diff --git a/yazi-binding/src/elements/rect.rs b/yazi-binding/src/elements/rect.rs index f1d2e64d..6c21d678 100644 --- a/yazi-binding/src/elements/rect.rs +++ b/yazi-binding/src/elements/rect.rs @@ -48,6 +48,15 @@ impl Rect { r.height = r.height.saturating_sub(pad.top + pad.bottom); Self(r) } + + fn patch(self, t: Table) -> mlua::Result { + Ok(Self(ratatui::layout::Rect { + x: t.raw_get::>("x")?.unwrap_or(self.x), + y: t.raw_get::>("y")?.unwrap_or(self.y), + width: t.raw_get::>("w")?.unwrap_or(self.width), + height: t.raw_get::>("h")?.unwrap_or(self.height), + })) + } } impl UserData for Rect { @@ -71,5 +80,7 @@ impl UserData for Rect { fn add_methods>(methods: &mut M) { methods.add_method("pad", |_, me, pad: Pad| Ok(me.pad(pad))); methods.add_method("contains", |_, me, Self(rect)| Ok(me.contains(rect.into()))); + + methods.add_meta_method(MetaMethod::Call, |_, me, t: Table| me.patch(t)); } } diff --git a/yazi-plugin/preset/components/marker.lua b/yazi-plugin/preset/components/marker.lua index 19ccd8d7..74e3fba0 100644 --- a/yazi-plugin/preset/components/marker.lua +++ b/yazi-plugin/preset/components/marker.lua @@ -24,7 +24,7 @@ function Marker:redraw() local y = math.min(self._area.y + last[1], self._area.y + self._area.h) - 1 local rect = ui.Rect { - x = math.max(0, self._area.x - 1), + x = self._area.x, y = y, w = 1, h = math.min(1 + last[2] - last[1], self._area.y + self._area.h - y), diff --git a/yazi-plugin/preset/components/markers.lua b/yazi-plugin/preset/components/markers.lua new file mode 100644 index 00000000..6c4bdad1 --- /dev/null +++ b/yazi-plugin/preset/components/markers.lua @@ -0,0 +1,33 @@ +Markers = { + _id = "markers", +} + +function Markers:new(chunks, tab) + local me = setmetatable({ _chunks = chunks, _tab = tab }, { __index = self }) + me:build() + return me +end + +function Markers:build() + self._children = { + Marker:new(self._chunks[1], self._tab.parent), + Marker:new(self._chunks[2], self._tab.current), + } +end + +function Markers:reflow() return {} end + +function Markers:redraw() + local elements = {} + for _, child in ipairs(self._children) do + elements = ya.list_merge(elements, ui.redraw(child)) + end + return elements +end + +-- Mouse events +function Markers:click(event, up) end + +function Markers:scroll(event, step) end + +function Markers:touch(event, step) end diff --git a/yazi-plugin/preset/components/rail.lua b/yazi-plugin/preset/components/rail.lua index 137b9b08..40d938d8 100644 --- a/yazi-plugin/preset/components/rail.lua +++ b/yazi-plugin/preset/components/rail.lua @@ -19,15 +19,19 @@ end -- Mouse events function Rail:click(event, up) end +function Rail:scroll(event, step) end + +function Rail:touch(event, step) end + function Rail:drag(event) - local c, parent, current, preview = self._chunks, 0, 0, 0 + local c, x, parent, current, preview = self._chunks, 0, 0, 0, 0 if self._id == "rail-left" then - local x = math.min(event.x, c[2].right - 2) + x = math.min(event.x, c[2].right - 2) parent = math.max(1, x - c[1].x) current = math.max(1, c[1].w + c[2].w - parent) preview = math.max(1, c[3].w) else - local x = math.max(event.x, c[2].x + 2) + x = math.max(event.x, c[2].x + 2) preview = math.max(1, c[3].right - x) current = math.max(1, c[2].w + c[3].w - preview) parent = math.max(1, c[1].w) @@ -39,7 +43,3 @@ function Rail:drag(event) ui.render() end end - -function Rail:scroll(event, step) end - -function Rail:touch(event, step) end diff --git a/yazi-plugin/preset/components/rails.lua b/yazi-plugin/preset/components/rails.lua index da351271..5487cb1b 100644 --- a/yazi-plugin/preset/components/rails.lua +++ b/yazi-plugin/preset/components/rails.lua @@ -11,15 +11,11 @@ end function Rails:build() local c, children = self._chunks, {} if c[1].w > 0 then - children[#children + 1] = - Rail:new("rail-left", ui.Rect { x = c[2].x, y = c[2].y, w = math.min(1, c[2].w), h = c[2].h }, c) + children[#children + 1] = Rail:new("rail-left", c[2] { w = math.min(1, c[2].w) }, c) end if c[3].w > 0 then - children[#children + 1] = Rail:new( - "rail-right", - ui.Rect { x = math.max(0, c[2].right - 1), y = c[2].y, w = math.min(1, c[2].w), h = c[2].h }, - c - ) + children[#children + 1] = + Rail:new("rail-right", c[2] { x = math.max(0, c[2].right - 1), w = math.min(1, c[2].w) }, c) end self._children = children end diff --git a/yazi-plugin/preset/components/tab.lua b/yazi-plugin/preset/components/tab.lua index bea19d3b..357abaab 100644 --- a/yazi-plugin/preset/components/tab.lua +++ b/yazi-plugin/preset/components/tab.lua @@ -29,6 +29,7 @@ function Tab:build() Current:new(c[2]:pad(ui.Pad.x(1)), self._tab), Preview:new(c[3]:pad(ui.Pad(0, 1, 0, p)), self._tab), Rails:new(c, self._tab), + Markers:new(c, self._tab), } end diff --git a/yazi-plugin/preset/components/tasks.lua b/yazi-plugin/preset/components/tasks.lua index f13b9129..8b8ddefc 100644 --- a/yazi-plugin/preset/components/tasks.lua +++ b/yazi-plugin/preset/components/tasks.lua @@ -29,12 +29,7 @@ function Tasks:redraw() break end - elements[#elements + 1] = ui.Line({ self:icon(snap), snap.title }):area(ui.Rect { - x = self._area.x, - y = y, - w = self._area.w, - h = 1, - }) + elements[#elements + 1] = ui.Line({ self:icon(snap), snap.title }):area(self._area { y = y, h = 1 }) if i == cx.tasks.cursor + 1 then elements[#elements] = elements[#elements]:style(th.tasks.hovered) @@ -107,14 +102,14 @@ function Tasks:progress_redraw(snap, y) return { ui.Gauge() - :area(ui.Rect { x = self._chunks[1].x, y = y, w = self._chunks[1].w, h = 1 }) + :area(self._chunks[1] { y = y, h = 1 }) :percent(snap.percent) :label(ui.Span(label):style(th.status.progress_label)) :gauge_style(style), ui.Line(string.format("%d/%d", snap.prog.success_files, snap.prog.total_files)) :fg("gray") - :area(ui.Rect { x = self._chunks[2].x, y = y, w = self._chunks[2].w, h = 1 }) + :area(self._chunks[2] { y = y, h = 1 }) :align(ui.Align.RIGHT), } else @@ -127,7 +122,7 @@ function Tasks:progress_redraw(snap, y) text = "Failed, press Enter to view log…" end return { - ui.Line(text):fg("gray"):area(ui.Rect { x = self._chunks[1].x, y = y, w = self._chunks[1].w, h = 1 }), + ui.Line(text):fg("gray"):area(self._chunks[1] { y = y, h = 1 }), } end end diff --git a/yazi-plugin/preset/plugins/folder.lua b/yazi-plugin/preset/plugins/folder.lua index 43d75ab2..cbf65d18 100644 --- a/yazi-plugin/preset/plugins/folder.lua +++ b/yazi-plugin/preset/plugins/folder.lua @@ -30,10 +30,11 @@ function M:peek(job) left[#left]:truncate { max = max, ellipsis = entity:ellipsis(max) } end + local marker_area = job.area { x = math.max(0, job.area.x - 1) } ya.preview_widget(job, { ui.List(left):area(job.area), ui.Text(right):area(job.area):align(ui.Align.RIGHT), - table.unpack(Marker:new(job.area, folder):redraw()), + table.unpack(Marker:new(marker_area, folder):redraw()), }) end diff --git a/yazi-plugin/src/standard.rs b/yazi-plugin/src/standard.rs index 11c890a7..d2a9a0c4 100644 --- a/yazi-plugin/src/standard.rs +++ b/yazi-plugin/src/standard.rs @@ -47,6 +47,7 @@ fn stage_1(lua: &Lua) -> Result<()> { lua.load(preset!("components/linemode")).set_name("linemode.lua").exec()?; lua.load(preset!("components/marker")).set_name("marker.lua").exec()?; + lua.load(preset!("components/markers")).set_name("markers.lua").exec()?; lua.load(preset!("components/modal")).set_name("modal.lua").exec()?; lua.load(preset!("components/parent")).set_name("parent.lua").exec()?; lua.load(preset!("components/preview")).set_name("preview.lua").exec()?; diff --git a/yazi-runner/src/loader/loader.rs b/yazi-runner/src/loader/loader.rs index e5eb025b..c8c38d6c 100644 --- a/yazi-runner/src/loader/loader.rs +++ b/yazi-runner/src/loader/loader.rs @@ -60,6 +60,7 @@ impl Default for Loader { ("header".to_owned(), [][..].into()), ("linemode".to_owned(), [][..].into()), ("marker".to_owned(), [][..].into()), + ("markers".to_owned(), [][..].into()), ("modal".to_owned(), [][..].into()), ("parent".to_owned(), [][..].into()), ("preview".to_owned(), [][..].into()),