From adb9c5ea1293003fd69b009be585ef05075730cf Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 28 Nov 2022 15:12:22 -0800 Subject: [PATCH] fix frame size calculation when frame_inset is set also fix error when clicking on HotkeyLabels where no on_activate callback has been set --- docs/changelog.txt | 4 +++- library/lua/gui/widgets.lua | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 75bec1368..82b129dd2 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -34,7 +34,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: # Future ## New Plugins -- `overlay`: plugin is transformed from a single line of text that runs `gui/launcher` on click to a fully-featured overlay injection framework. See `overlay-dev-guide` for details. +- `overlay`: plugin is transformed from a single line of text that runs `gui/launcher` on click to a fully-featured overlay injection framework. It now houses a popup menu for active keybindings, all the widgets provided by `dwarfmonitor` (e.g. the current date and number of happy/unhappy dwarves), the overlay that highlights suspended buildings when you pause, and others. See `overlay-dev-guide` for details. ## Fixes - `automaterial`: fix the cursor jumping up a z level when clicking quickly after box select @@ -113,6 +113,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - ``dfhack.constructions.findAtTile()``: exposed preexisting function to Lua. - ``dfhack.constructions.insert()``: exposed new function to Lua. - ``widgets.Panel``: new ``frame_style`` and ``frame_title`` attributes for drawing frames around groups of widgets +- ``widgets.ResizingPanel``: now accounts for frame inset when calculating frame size +- ``widgets.HotkeyLabel``: now ignores mouse clicks when ``on_activate`` is not defined - ``widgets.EditField`` now allows other widgets to process characters that the ``on_char`` callback rejects. - ``gui.Screen.show()`` now returns ``self`` as a convenience - ``gui.View.getMousePos()`` now takes an optional ``ViewRect`` parameter in case the caller wants to get the mouse pos relative to a rect that is not the frame_body (such as the frame_rect) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index e8093345f..67aa8d00d 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -144,6 +144,9 @@ function ResizingPanel:postUpdateLayout(frame_body) (s.frame and s.frame.h or frame_body.height)) end end + local l,t,r,b = gui.parse_inset(self.frame_inset) + w = w + l + r + h = h + t + b if self.frame_style then w = w + 2 h = h + 2 @@ -827,7 +830,8 @@ function Label:scroll(nlines) end end local n = self.start_line_num + nlines - n = math.min(n, self:getTextHeight() - self.frame_body.height + 1) + local text_height = math.max(1, self:getTextHeight()) + n = math.min(n, text_height - self.frame_body.height + 1) n = math.max(n, 1) nlines = n - self.start_line_num self.start_line_num = n @@ -928,7 +932,7 @@ end function HotkeyLabel:onInput(keys) if HotkeyLabel.super.onInput(self, keys) then return true - elseif keys._MOUSE_L_DOWN and self:getMousePos() then + elseif keys._MOUSE_L_DOWN and self:getMousePos() and self.on_activate then self.on_activate() return true end