mirror of
https://github.com/sxyazi/yazi.git
synced 2026-05-13 08:16:40 +00:00
Co-authored-by: Lingxuan Ye <yelingxuan@xiaomi.com> Co-authored-by: sxyazi <sxyazi@gmail.com>
86 lines
1.8 KiB
Lua
86 lines
1.8 KiB
Lua
Root = {
|
|
_id = "root",
|
|
_dragging = nil,
|
|
}
|
|
|
|
function Root:new(area)
|
|
local me = setmetatable({ _area = area }, { __index = self })
|
|
me:layout()
|
|
me:build()
|
|
return me
|
|
end
|
|
|
|
function Root:layout()
|
|
self._chunks = ui.Layout()
|
|
:direction(ui.Layout.VERTICAL)
|
|
:constraints({
|
|
ui.Constraint.Length(1),
|
|
ui.Constraint.Length(Tabs.height()),
|
|
ui.Constraint.Fill(1),
|
|
ui.Constraint.Length(1),
|
|
})
|
|
:split(self._area)
|
|
end
|
|
|
|
function Root:build()
|
|
self._children = {
|
|
Header:new(self._chunks[1], cx.active),
|
|
Tabs:new(self._chunks[2]),
|
|
Tab:new(self._chunks[3], cx.active),
|
|
Status:new(self._chunks[4], cx.active),
|
|
Modal:new(self._area),
|
|
}
|
|
end
|
|
|
|
function Root:reflow()
|
|
local components = { self }
|
|
for _, child in ipairs(self._children) do
|
|
components = ya.list_merge(components, child:reflow())
|
|
end
|
|
return components
|
|
end
|
|
|
|
function Root:redraw()
|
|
local elements = self._base or {}
|
|
for _, child in ipairs(self._children) do
|
|
elements = ya.list_merge(elements, ui.redraw(child))
|
|
end
|
|
return elements
|
|
end
|
|
|
|
-- Mouse events
|
|
function Root:click(event, up)
|
|
local c = Root._dragging or ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
|
|
Root._dragging = not up and c or nil
|
|
|
|
if tostring(cx.layer) == "mgr" then
|
|
return c and c:click(event, up)
|
|
end
|
|
end
|
|
|
|
function Root:scroll(event, step)
|
|
if tostring(cx.layer) ~= "mgr" then
|
|
return
|
|
end
|
|
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)
|
|
if tostring(cx.layer) ~= "mgr" then
|
|
return
|
|
end
|
|
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
|
|
return c and c:touch(event, step)
|
|
end
|
|
|
|
function Root:move(event) end
|
|
|
|
function Root:drag(event)
|
|
if tostring(cx.layer) ~= "mgr" then
|
|
return
|
|
end
|
|
|
|
local c = Root._dragging
|
|
return c and c.drag and c:drag(event)
|
|
end
|