resize window

This commit is contained in:
ruki
2020-05-05 23:36:00 +08:00
parent af5bfc8c50
commit 1dc02e058d
6 changed files with 52 additions and 6 deletions

View File

@@ -70,5 +70,11 @@ function boxdialog:box()
return self._BOX return self._BOX
end 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 module
return boxdialog return boxdialog

View File

@@ -110,5 +110,11 @@ function dialog:on_event(e)
return window.on_event(self, e) return window.on_event(self, e)
end 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 module
return dialog return dialog

View File

@@ -64,5 +64,11 @@ function textdialog:on_event(e)
end end
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 module
return textdialog return textdialog

View File

@@ -169,7 +169,7 @@ end
function view:draw(transparent) function view:draw(transparent)
-- trace -- trace
log:print("%s: draw ..", self) log:print("%s: draw (transparent: %s) ..", self, tostring(transparent))
-- draw background -- draw background
if not transparent then if not transparent then

View File

@@ -43,6 +43,7 @@ function window:init(name, bounds, title, shadow)
-- insert shadow -- insert shadow
if shadow then if shadow then
self._SHADOW = view:new("window.shadow", rect{2, 1, self:width(), self:height()}):background_set("black")
self:insert(self:shadow()) self:insert(self:shadow())
self:frame():bounds():movee(-2, -1) self:frame():bounds():movee(-2, -1)
self:frame():invalidate(true) self:frame():invalidate(true)
@@ -98,9 +99,6 @@ end
-- get shadow -- get shadow
function window: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 return self._SHADOW
end end
@@ -123,5 +121,21 @@ function window:on_event(e)
end end
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 module
return window return window

View File

@@ -42,8 +42,22 @@ function demo:init()
-- init background -- init background
self:background_set("blue") self:background_set("blue")
-- init main window -- init body window
self:insert(window:new("window.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main window", true)) 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 end
-- run demo -- run demo