add widgets.Window and fix paint_frame offset

develop
Myk Taylor 2022-12-14 12:04:29 -08:00
parent 12e62c7f9d
commit 4c6daf30d9
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
4 changed files with 24 additions and 7 deletions

@ -48,6 +48,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Lua ## Lua
- ``gui.View``: ``visible`` and ``active`` can now be functions that return a boolean - ``gui.View``: ``visible`` and ``active`` can now be functions that return a boolean
- ``widgets.Panel``: new attributes to control window dragging and resizing with mouse or keyboard - ``widgets.Panel``: new attributes to control window dragging and resizing with mouse or keyboard
- ``widgets.Window``: Panel subclass with attributes preset for top-level windows
## Internals ## Internals

@ -4247,6 +4247,12 @@ Has functions:
commit the new window size or :kbd:`Esc` to cancel. If resizing is canceled, commit the new window size or :kbd:`Esc` to cancel. If resizing is canceled,
then the window size from before the resize operation is restored. then the window size from before the resize operation is restored.
Window class
------------
Subclass of Panel; sets Panel attributes to useful defaults for a top-level
framed, draggable window.
ResizingPanel class ResizingPanel class
------------------- -------------------

@ -704,8 +704,9 @@ GREY_LINE_FRAME = {
signature_pen = to_pen{ fg = COLOR_DARKGREY, bg = COLOR_BLACK }, signature_pen = to_pen{ fg = COLOR_DARKGREY, bg = COLOR_BLACK },
} }
function paint_frame(x1,y1,x2,y2,style,title) function paint_frame(dc,rect,style,title)
local pen = style.frame_pen local pen = style.frame_pen
local x1,y1,x2,y2 = dc.x1+rect.x1, dc.y1+rect.y1, dc.x1+rect.x2, dc.y1+rect.y2
dscreen.paintTile(style.lt_frame_pen or pen, x1, y1) dscreen.paintTile(style.lt_frame_pen or pen, x1, y1)
dscreen.paintTile(style.rt_frame_pen or pen, x2, y1) dscreen.paintTile(style.rt_frame_pen or pen, x2, y1)
dscreen.paintTile(style.lb_frame_pen or pen, x1, y2) dscreen.paintTile(style.lb_frame_pen or pen, x1, y2)
@ -750,16 +751,13 @@ function FramedScreen:computeFrame(parent_rect)
end end
function FramedScreen:onRenderFrame(dc, rect) function FramedScreen:onRenderFrame(dc, rect)
local x1,y1,x2,y2 = rect.x1, rect.y1, rect.x2, rect.y2
if rect.wgap <= 0 and rect.hgap <= 0 then if rect.wgap <= 0 and rect.hgap <= 0 then
dc:clear() dc:clear()
else else
self:renderParent() self:renderParent()
dc:fill(rect, self.frame_background) dc:fill(rect, self.frame_background)
end end
paint_frame(dc,rect,self.frame_style,self.frame_title)
paint_frame(x1,y1,x2,y2,self.frame_style,self.frame_title)
end end
return _ENV return _ENV

@ -420,8 +420,7 @@ end
function Panel:onRenderFrame(dc, rect) function Panel:onRenderFrame(dc, rect)
Panel.super.onRenderFrame(self, dc, rect) Panel.super.onRenderFrame(self, dc, rect)
if not self.frame_style then return end if not self.frame_style then return end
local x1,y1,x2,y2 = rect.x1, rect.y1, rect.x2, rect.y2 gui.paint_frame(dc, rect, self.frame_style, self.frame_title)
gui.paint_frame(x1, y1, x2, y2, self.frame_style, self.frame_title)
if self.kbd_get_pos then if self.kbd_get_pos then
local pos = self.kbd_get_pos() local pos = self.kbd_get_pos()
local pen = dfhack.pen.parse{fg=COLOR_GREEN, bg=COLOR_BLACK} local pen = dfhack.pen.parse{fg=COLOR_GREEN, bg=COLOR_BLACK}
@ -433,6 +432,19 @@ function Panel:onRenderFrame(dc, rect)
end end
end end
------------
-- Window --
------------
Window = defclass(Window, Panel)
Window.ATTRS {
frame_style = gui.GREY_LINE_FRAME,
frame_background = gui.CLEAR_PEN,
frame_inset = 1,
draggable = true,
}
------------------- -------------------
-- ResizingPanel -- -- ResizingPanel --
------------------- -------------------