summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-13 00:37:36 +0800
committerruki <[email protected]>2018-01-12 21:45:36 +0800
commit788f52e46e4333be8522f80cd033eba206fda3ff (patch)
treeac4db1a6452e489f817ae3a37b280840e916b8c9
parentbcb58d536cb131be4358d8893cfd1db77f72d942 (diff)
add resize state
-rw-r--r--tests/ui/dialog.lua6
-rw-r--r--xmake/core/ui/boxdialog.lua6
-rw-r--r--xmake/core/ui/panel.lua20
-rw-r--r--xmake/core/ui/program.lua3
-rw-r--r--xmake/core/ui/view.lua36
5 files changed, 58 insertions, 13 deletions
diff --git a/tests/ui/dialog.lua b/tests/ui/dialog.lua
index dcdb0ff4a..443a1ef4e 100644
--- a/tests/ui/dialog.lua
+++ b/tests/ui/dialog.lua
@@ -46,9 +46,7 @@ function demo:init()
-- init main dialog
local dialog_main = boxdialog:new("dialog.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main dialog")
- dialog_main:text():text_set([[xmake is a cross-platform build utility based on lua.
-
-The project focuses on making development and building easier and provides many features (.e.g package, install, plugin, macro, action, option, task ...), so that any developer can quickly pick it up and enjoy the productivity boost when developing and building project.]])
+ dialog_main:text():text_set("The project focuses on making development and building easier and provides many features (.e.g package, install, plugin, macro, action, option, task ...), so that any developer can quickly pick it up and enjoy the productivity boost when developing and building project.")
dialog_main:button_add("ok", "< OK >", "cm_ok")
dialog_main:button_add("cancel", "< Cancel >", "cm_cancel")
dialog_main:button_add("help", "< Help >", "cm_help")
@@ -56,7 +54,7 @@ The project focuses on making development and building easier and provides many
self:insert(dialog_main)
-- init hello dialog
- local dialog_hello = textdialog:new("dialog.hello", rect {0, 0, self:width() / 2, self:height() / 4}):background_set(dialog_main:frame():background())
+ local dialog_hello = textdialog:new("dialog.hello", rect {0, 0, 50, 8}):background_set(dialog_main:frame():background())
dialog_hello:frame():background_set("cyan")
dialog_hello:text():text_set("hello xmake! (http://xmake.io)\nA cross-platform build utility based on Lua"):textattr_set("red")
dialog_hello:button_add("yes", "< Yes >", "cm_yes")
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()