From f19ae16c9d64f2678bef68af5719eededbc2e279 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 14 Jan 2023 01:00:38 -0800 Subject: [PATCH] give more control over the resizing dimensions of ResizingPanels --- docs/dev/Lua API.rst | 7 +++++++ library/lua/gui/widgets.lua | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 33b48c0a7..728551ff6 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -4416,6 +4416,13 @@ Subclass of Panel; automatically adjusts its own frame height and width to the minimum required to show its subviews. Pairs nicely with a parent Panel that has ``autoarrange_subviews`` enabled. +It has the following attributes: + +:auto_height: Sets self.frame.h from the positions and height of its subviews + (default is ``true``). +:auto_width: Sets self.frame.w from the positions and width of its subviews + (default is ``false``). + Pages class ----------- diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 9293e737c..1488eda90 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -530,6 +530,11 @@ Window.ATTRS { ResizingPanel = defclass(ResizingPanel, Panel) +ResizingPanel.ATTRS{ + auto_height = true, + auto_width = false, +} + -- adjust our frame dimensions according to positions and sizes of our subviews function ResizingPanel:postUpdateLayout(frame_body) local w, h = 0, 0 @@ -550,6 +555,8 @@ function ResizingPanel:postUpdateLayout(frame_body) end if not self.frame then self.frame = {} end local oldw, oldh = self.frame.w, self.frame.h + if not self.auto_height then h = oldh end + if not self.auto_width then w = oldw end self.frame.w, self.frame.h = w, h if not self._updateLayoutGuard and (oldw ~= w or oldh ~= h) then self._updateLayoutGuard = true -- protect against infinite loops