diff options
| author | ruki <[email protected]> | 2018-01-13 00:37:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-01-12 21:45:36 +0800 |
| commit | 788f52e46e4333be8522f80cd033eba206fda3ff (patch) | |
| tree | ac4db1a6452e489f817ae3a37b280840e916b8c9 /xmake | |
| parent | bcb58d536cb131be4358d8893cfd1db77f72d942 (diff) | |
add resize state
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/ui/boxdialog.lua | 6 | ||||
| -rw-r--r-- | xmake/core/ui/panel.lua | 20 | ||||
| -rw-r--r-- | xmake/core/ui/program.lua | 3 | ||||
| -rw-r--r-- | xmake/core/ui/view.lua | 36 |
4 files changed, 56 insertions, 9 deletions
diff --git a/xmake/core/ui/boxdialog.lua b/xmake/core/ui/boxdialog.lua index 74b32b685..d46b2ed09 100644 --- a/xmake/core/ui/boxdialog.lua +++ b/xmake/core/ui/boxdialog.lua @@ -41,14 +41,14 @@ function boxdialog:init(name, bounds, title) -- insert box self:panel():insert(self:box()) - -- resize text bounds - self:text():bounds():resize(self:panel():width(), math.floor(self:panel():height() / 4)) + -- resize text + self:text():bounds().ey = 3 end -- get box function boxdialog:box() if not self._BOX then - self._BOX = window:new("boxdialog.box", rect{0, math.floor(self:panel():height() / 4), self:panel():width(), self:panel():height() - 1}) + self._BOX = window:new("boxdialog.box", rect{0, 3, self:panel():width(), self:panel():height() - 1}) self._BOX:border():cornerattr_set("black", "white") end return self._BOX diff --git a/xmake/core/ui/panel.lua b/xmake/core/ui/panel.lua index 6576c0b24..417f1d725 100644 --- a/xmake/core/ui/panel.lua +++ b/xmake/core/ui/panel.lua @@ -276,6 +276,26 @@ function panel:draw() end end +-- resize panel +function panel:resize() + + -- resize panel? + local resize = self:state("resize") + if resize then + view.resize(self) + end + + -- resize all child views + for v in self:views() do + if resize then + v:state_set("resize", true) + end + if v:state("visible") and (v:state("resize") or v:type() == "panel") then + v:resize() + end + end +end + -- refresh panel function panel:refresh() diff --git a/xmake/core/ui/program.lua b/xmake/core/ui/program.lua index 2075a466d..0fe44049b 100644 --- a/xmake/core/ui/program.lua +++ b/xmake/core/ui/program.lua @@ -201,6 +201,9 @@ function program:loop(argv) break end + -- resize views + self:resize() + -- draw views self:draw() diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua index 18b5898f7..70d4149ec 100644 --- a/xmake/core/ui/view.lua +++ b/xmake/core/ui/view.lua @@ -64,6 +64,7 @@ function view:init(name, bounds) state.focused = false -- true if parent is also focused state.redraw = true -- need redraw state.refresh = true -- need refresh + state.resize = true -- need resize self._STATE = state -- init options @@ -101,6 +102,11 @@ function view:name() return self._NAME end +-- get view bounds +function view:bounds() + return self._BOUNDS +end + -- set window bounds function view:bounds_set(bounds) @@ -136,11 +142,6 @@ function view:size() return self._SIZE end --- get view bounds -function view:bounds() - return self._BOUNDS -end - -- get the parent view function view:parent() return self._PARENT @@ -215,6 +216,16 @@ function view:refresh() end end +-- resize bounds of inner child views (abstract) +function view:resize() + + -- trace + log:print("%s: resize ..", self) + + -- clear mark + self:state_set("resize", false) +end + -- show view? function view:show(visible) if self:state("visible") ~= visible then @@ -224,7 +235,10 @@ function view:show(visible) end -- invalidate view to redraw it -function view:invalidate() +function view:invalidate(bounds) + if bounds then + self:_mark_resize() + end self:_mark_redraw() end @@ -343,6 +357,16 @@ function view:_limit(value, minval, maxval) return math.min(maxval, math.max(value, minval)) end +-- need resize view +function view:_mark_resize() + + -- trace + log:print("%s: mark as resize", self) + + -- need resize it + self:state_set("resize", true) +end + -- need redraw view function view:_mark_redraw() |
