mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-24 16:21:04 +00:00
114 lines
2.7 KiB
Lua
114 lines
2.7 KiB
Lua
Root = {
|
|
_id = "root",
|
|
_dragging = nil,
|
|
_dropping = 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 = {
|
|
Backdrop:new(self._area),
|
|
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 = 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 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 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 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
|
|
|
|
function Root:drop(event)
|
|
local d = Root._dropping
|
|
local c = event.x and ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow()) or d
|
|
if d and d.drop and d._id ~= c._id then
|
|
d:drop { type = "leave" }
|
|
end
|
|
|
|
Root._dropping = c
|
|
if tostring(cx.layer) == "mgr" then
|
|
return c and c.drop and c:drop(event)
|
|
end
|
|
end
|
|
|
|
function Root:clipboard(event)
|
|
if event and event.type == "mimetypes" and event.pw then
|
|
-- No harm in asking for unavailable types
|
|
local mimetypes = "text/plain text/uri-list"
|
|
rt.tty:queue("ReadClipboard", { mimes = mimetypes, pw = event.pw, name = "Paste Event", primary = event.primary })
|
|
rt.tty:flush()
|
|
elseif event and event.type == "data" then
|
|
if event.data["text/uri-list"] ~= nil then
|
|
require("clipboard").copy_uri_list(event.data["text/uri-list"])
|
|
end
|
|
end
|
|
end
|