Simplify the code
This commit is contained in:
@@ -2,38 +2,22 @@ local function setup()
|
|||||||
Manager.render = function(self, area)
|
Manager.render = function(self, area)
|
||||||
local chunks = self:layout(area)
|
local chunks = self:layout(area)
|
||||||
|
|
||||||
local dynamic_first_bar = function()
|
|
||||||
if chunks[2].w == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
return ui.Bar(chunks[1], ui.Bar.RIGHT)
|
|
||||||
end
|
|
||||||
|
|
||||||
local bar = function(c, x, y)
|
local bar = function(c, x, y)
|
||||||
x, y = math.max(0, x), math.max(0, y)
|
if x <= 0 or x == area.w - 1 then
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
return ui.Bar(
|
return ui.Bar(
|
||||||
ui.Rect { x = x, y = y, w = ya.clamp(0, area.w - x, 1), h = math.min(1, area.h) },
|
ui.Rect { x = x, y = math.max(0, y), w = ya.clamp(0, area.w - x, 1), h = math.min(1, area.h) },
|
||||||
x == 0 and ui.Bar.NONE or ui.Bar.TOP
|
ui.Bar.TOP
|
||||||
):symbol(c)
|
):symbol(c)
|
||||||
end
|
end
|
||||||
|
|
||||||
local dynamic_padding = function()
|
|
||||||
if chunks[1].w == 0 then
|
|
||||||
return ui.Padding(1, 0, 1, 1)
|
|
||||||
elseif chunks[3].w == 0 then
|
|
||||||
return ui.Padding(0, 1, 1, 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
return ui.Padding.y(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
return ya.flat {
|
return ya.flat {
|
||||||
-- Borders
|
-- Borders
|
||||||
ui.Border(area, ui.Border.ALL):type(ui.Border.ROUNDED),
|
ui.Border(area, ui.Border.ALL):type(ui.Border.ROUNDED),
|
||||||
dynamic_first_bar(),
|
ui.Bar(chunks[1]:padding(ui.Padding.y(1)), ui.Bar.RIGHT),
|
||||||
ui.Bar(chunks[3], ui.Bar.LEFT),
|
ui.Bar(chunks[3]:padding(ui.Padding.y(1)), ui.Bar.LEFT),
|
||||||
|
|
||||||
bar("┬", chunks[1].right - 1, chunks[1].y),
|
bar("┬", chunks[1].right - 1, chunks[1].y),
|
||||||
bar("┴", chunks[1].right - 1, chunks[1].bottom - 1),
|
bar("┴", chunks[1].right - 1, chunks[1].bottom - 1),
|
||||||
@@ -43,7 +27,7 @@ local function setup()
|
|||||||
-- Parent
|
-- Parent
|
||||||
Parent:render(chunks[1]:padding(ui.Padding.xy(1))),
|
Parent:render(chunks[1]:padding(ui.Padding.xy(1))),
|
||||||
-- Current
|
-- Current
|
||||||
Current:render(chunks[2]:padding(dynamic_padding())),
|
Current:render(chunks[2]:padding(ui.Padding.y(1))),
|
||||||
-- Preview
|
-- Preview
|
||||||
Preview:render(chunks[3]:padding(ui.Padding.xy(1))),
|
Preview:render(chunks[3]:padding(ui.Padding.xy(1))),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user