diff --git a/yazi-plugin/preset/components/modal.lua b/yazi-plugin/preset/components/modal.lua new file mode 100644 index 00000000..0041c831 --- /dev/null +++ b/yazi-plugin/preset/components/modal.lua @@ -0,0 +1,42 @@ +Modal = { + _id = "modal", + + _inc = 1000, + _children = {}, +} + +function Modal:new(area) return setmetatable({ _area = area }, { __index = self }) end + +function Modal:reflow() + local components = {} + for _, child in ipairs(self._children) do + components = ya.list_merge(components, child[1]:new(self._area):reflow()) + end + return components +end + +function Modal:redraw() + local elements = {} + for _, child in ipairs(self._children) do + elements = ya.list_merge(elements, ya.redraw_with(child[1]:new(self._area))) + end + return elements +end + +-- Children +function Modal:children_add(tbl, order) + self._inc = self._inc + 1 + self._children[#self._children + 1] = { tbl, id = self._inc, order = order } + + table.sort(self._children, function(a, b) return a.order < b.order end) + return self._inc +end + +function Modal:children_remove(id) + for i, child in ipairs(self._children) do + if child.id == id then + table.remove(self._children, i) + break + end + end +end diff --git a/yazi-plugin/preset/components/rail.lua b/yazi-plugin/preset/components/rail.lua index 8f6011ef..06d4e2fa 100644 --- a/yazi-plugin/preset/components/rail.lua +++ b/yazi-plugin/preset/components/rail.lua @@ -1,6 +1,5 @@ Rail = { _id = "rail", - _area = ui.Rect.default, } function Rail:new(chunks, tab) @@ -20,7 +19,7 @@ function Rail:build() } end -function Rail:reflow() return { self } end +function Rail:reflow() return {} end function Rail:redraw() local elements = self._base or {} diff --git a/yazi-plugin/preset/components/root.lua b/yazi-plugin/preset/components/root.lua index 6922c47b..8f2079b1 100644 --- a/yazi-plugin/preset/components/root.lua +++ b/yazi-plugin/preset/components/root.lua @@ -26,6 +26,7 @@ function Root:build() Header:new(self._chunks[1], cx.active), Tab:new(self._chunks[2], cx.active), Status:new(self._chunks[3], cx.active), + Modal:new(self._area), } end @@ -47,17 +48,17 @@ end -- Mouse events function Root:click(event, up) - local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self._children) + local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow()) return c and c:click(event, up) end function Root:scroll(event, step) - local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self._children) + local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow()) return c and c:scroll(event, step) end function Root:touch(event, step) - local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self._children) + local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow()) return c and c:touch(event, step) end diff --git a/yazi-plugin/preset/components/tab.lua b/yazi-plugin/preset/components/tab.lua index a4bcd010..de684ffb 100644 --- a/yazi-plugin/preset/components/tab.lua +++ b/yazi-plugin/preset/components/tab.lua @@ -46,17 +46,8 @@ function Tab:redraw() end -- Mouse events -function Tab:click(event, up) - local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self._children) - return c and c:click(event, up) -end +function Tab:click(event, up) end -function Tab:scroll(event, step) - local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self._children) - return c and c:scroll(event, step) -end +function Tab:scroll(event, step) end -function Tab:touch(event, step) - local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self._children) - return c and c:touch(event, step) -end +function Tab:touch(event, step) end diff --git a/yazi-plugin/src/lua.rs b/yazi-plugin/src/lua.rs index 484d0978..f0cf7f15 100644 --- a/yazi-plugin/src/lua.rs +++ b/yazi-plugin/src/lua.rs @@ -43,6 +43,7 @@ fn stage_1(lua: &'static 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/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()?; lua.load(preset!("components/progress")).set_name("progress.lua").exec()?;