diff --git a/docs/changelog.txt b/docs/changelog.txt index 4ef5302db..2c000262b 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -48,6 +48,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Lua - ``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.Window``: Panel subclass with attributes preset for top-level windows ## Internals diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 45644ac13..d3e7b3d32 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -4247,6 +4247,12 @@ Has functions: 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. +Window class +------------ + +Subclass of Panel; sets Panel attributes to useful defaults for a top-level +framed, draggable window. + ResizingPanel class ------------------- diff --git a/library/lua/gui.lua b/library/lua/gui.lua index fb274ebec..02d06bf5f 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -704,8 +704,9 @@ GREY_LINE_FRAME = { 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 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.rt_frame_pen or pen, x2, y1) dscreen.paintTile(style.lb_frame_pen or pen, x1, y2) @@ -750,16 +751,13 @@ function FramedScreen:computeFrame(parent_rect) end 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 dc:clear() else self:renderParent() dc:fill(rect, self.frame_background) end - - paint_frame(x1,y1,x2,y2,self.frame_style,self.frame_title) + paint_frame(dc,rect,self.frame_style,self.frame_title) end return _ENV diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index f10588065..9b456808c 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -420,8 +420,7 @@ end function Panel:onRenderFrame(dc, rect) Panel.super.onRenderFrame(self, dc, rect) if not self.frame_style then return end - local x1,y1,x2,y2 = rect.x1, rect.y1, rect.x2, rect.y2 - gui.paint_frame(x1, y1, x2, y2, self.frame_style, self.frame_title) + gui.paint_frame(dc, rect, self.frame_style, self.frame_title) if self.kbd_get_pos then local pos = self.kbd_get_pos() local pen = dfhack.pen.parse{fg=COLOR_GREEN, bg=COLOR_BLACK} @@ -433,6 +432,19 @@ function Panel:onRenderFrame(dc, rect) 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 -- -------------------