diff --git a/src/ltui/boxdialog.lua b/src/ltui/boxdialog.lua index 470e886..5952b4d 100644 --- a/src/ltui/boxdialog.lua +++ b/src/ltui/boxdialog.lua @@ -70,5 +70,11 @@ function boxdialog:box() return self._BOX end +-- on resize +function boxdialog:on_resize() + textdialog.on_resize(self) + self:box():bounds_set(rect{0, 3, self:panel():width(), self:panel():height() - 1}) +end + -- return module return boxdialog diff --git a/src/ltui/dialog.lua b/src/ltui/dialog.lua index 0e772f2..2604d97 100644 --- a/src/ltui/dialog.lua +++ b/src/ltui/dialog.lua @@ -110,5 +110,11 @@ function dialog:on_event(e) return window.on_event(self, e) end +-- on resize +function dialog:on_resize() + window.on_resize(self) + self:buttons():bounds_set(rect:new(0, self:panel():height() - 1, self:panel():width(), 1)) +end + -- return module return dialog diff --git a/src/ltui/textdialog.lua b/src/ltui/textdialog.lua index 9c1f88c..48bb335 100644 --- a/src/ltui/textdialog.lua +++ b/src/ltui/textdialog.lua @@ -64,5 +64,11 @@ function textdialog:on_event(e) end end +-- on resize +function textdialog:on_resize() + dialog.on_resize(self) + self:text():bounds_set(rect:new(0, 0, self:panel():width(), self:panel():height() - 1)) +end + -- return module return textdialog diff --git a/src/ltui/view.lua b/src/ltui/view.lua index eac4a41..e9cf943 100644 --- a/src/ltui/view.lua +++ b/src/ltui/view.lua @@ -169,7 +169,7 @@ end function view:draw(transparent) -- trace - log:print("%s: draw ..", self) + log:print("%s: draw (transparent: %s) ..", self, tostring(transparent)) -- draw background if not transparent then diff --git a/src/ltui/window.lua b/src/ltui/window.lua index 8e953bb..f7dcb44 100644 --- a/src/ltui/window.lua +++ b/src/ltui/window.lua @@ -43,6 +43,7 @@ function window:init(name, bounds, title, shadow) -- insert shadow if shadow then + self._SHADOW = view:new("window.shadow", rect{2, 1, self:width(), self:height()}):background_set("black") self:insert(self:shadow()) self:frame():bounds():movee(-2, -1) self:frame():invalidate(true) @@ -98,9 +99,6 @@ end -- get shadow function window:shadow() - if not self._SHADOW then - self._SHADOW = view:new("window.shadow", rect{2, 1, self:width(), self:height()}):background_set("black") - end return self._SHADOW end @@ -123,5 +121,21 @@ function window:on_event(e) end end +-- on resize +function window:on_resize() + self:frame():bounds_set(rect{0, 0, self:width(), self:height()}) + if self:shadow() then + self:shadow():bounds_set(rect{2, 1, self:width(), self:height()}) + self:frame():bounds():movee(-2, -1) + end + self:border():bounds_set(self:frame():bounds()) + if self:title() then + self:frame():center(self:title(), {centerx = true}) + end + self:panel():bounds_set(self:frame():bounds()) + self:panel():bounds():grow(-1, -1) + panel.on_resize(self) +end + -- return module return window diff --git a/tests/window.lua b/tests/window.lua index c4e98e9..f650c15 100644 --- a/tests/window.lua +++ b/tests/window.lua @@ -42,8 +42,22 @@ function demo:init() -- init background self:background_set("blue") - -- init main window - self:insert(window:new("window.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main window", true)) + -- init body window + self:insert(self:body_window()) +end + +-- get body window +function demo:body_window() + if not self._BODY_WINDOW then + self._BODY_WINDOW = window:new("window.body", rect {1, 1, self:width() - 1, self:height() - 1}, "main window", true) + end + return self._BODY_WINDOW +end + +-- on resize +function demo:on_resize() + self:body_window():bounds_set(rect {1, 1, self:width() - 1, self:height() - 1}) + application.on_resize(self) end -- run demo