use proper widgets for the minimize button

develop
Myk Taylor 2023-03-15 13:40:34 -07:00
parent a4365f47f5
commit 73e65f2d94
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 16 additions and 14 deletions

@ -262,9 +262,6 @@ function PlannerOverlay:init()
self.selected = 1 self.selected = 1
self.minimized = false self.minimized = false
local function is_minimized() return self.minimized end
local function not_is_minimized() return not self.minimized end
local main_panel = widgets.Panel{ local main_panel = widgets.Panel{
view_id='main', view_id='main',
frame={t=0, l=0, r=0, h=14}, frame={t=0, l=0, r=0, h=14},
@ -273,6 +270,17 @@ function PlannerOverlay:init()
visible=function() return not self.minimized end, visible=function() return not self.minimized end,
} }
local minimized_panel = widgets.Label{
frame={t=0, r=1, w=1, h=1},
text={
{
text=function() return string.char(self.minimized and 31 or 30) end,
pen=COLOR_RED,
},
},
on_click=function() self.minimized = not self.minimized end,
}
local function make_is_selected_fn(idx) local function make_is_selected_fn(idx)
return function() return self.selected == idx end return function() return self.selected == idx end
end end
@ -476,6 +484,7 @@ function PlannerOverlay:init()
self:addviews{ self:addviews{
main_panel, main_panel,
minimized_panel,
error_panel, error_panel,
} }
end end
@ -582,7 +591,7 @@ function PlannerOverlay:onInput(keys)
return true return true
end end
if PlannerOverlay.super.onInput(self, keys) then if PlannerOverlay.super.onInput(self, keys) then
return true return not self.minimized
end end
if keys._MOUSE_L_DOWN then if keys._MOUSE_L_DOWN then
if is_over_options_panel() then return false end if is_over_options_panel() then return false end
@ -590,14 +599,10 @@ function PlannerOverlay:onInput(keys)
detect_rect.height = self.subviews.main.frame_rect.height + detect_rect.height = self.subviews.main.frame_rect.height +
self.subviews.errors.frame_rect.height self.subviews.errors.frame_rect.height
detect_rect.y2 = detect_rect.y1 + detect_rect.height - 1 detect_rect.y2 = detect_rect.y1 + detect_rect.height - 1
local x, y = self.subviews.main:getMousePos(gui.ViewRect{rect=detect_rect}) if self.subviews.main:getMousePos(gui.ViewRect{rect=detect_rect})
if x or self.subviews.errors:getMousePos() then or self.subviews.errors:getMousePos() then
if x and x == detect_rect.width-2 and y == 0 then
self.minimized = not self.minimized
return true return true
end end
return not self.minimized
end
if self.minimized then return false end if self.minimized then return false end
if not is_construction() and #uibs.errors > 0 then return true end if not is_construction() and #uibs.errors > 0 then return true end
if dfhack.gui.getMousePos() then if dfhack.gui.getMousePos() then
@ -658,9 +663,6 @@ function PlannerOverlay:render(dc)
if not is_plannable() then return end if not is_plannable() then return end
self.subviews.errors:updateLayout() self.subviews.errors:updateLayout()
PlannerOverlay.super.render(self, dc) PlannerOverlay.super.render(self, dc)
-- render "minimize" button
dc:seek(self.frame_rect.x2-1, self.frame_rect.y1)
dc:char(string.char(self.minimized and 31 or 30), COLOR_RED)
end end
local ONE_BY_ONE = xy2pos(1, 1) local ONE_BY_ONE = xy2pos(1, 1)