summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-17 22:33:14 +0800
committerruki <[email protected]>2018-01-17 09:19:24 +0800
commitd729a22336476e0b8de653d83d0f0bfe7d7b172e (patch)
tree86dca44f59172054b5556989443f688e9c2074d6
parent4bc80943272b031e41a7047f795d85a04682cbd6 (diff)
fix view:show bug
-rw-r--r--tests/ui/dialog.lua6
-rw-r--r--xmake/core/ui/panel.lua15
-rw-r--r--xmake/core/ui/view.lua13
3 files changed, 27 insertions, 7 deletions
diff --git a/tests/ui/dialog.lua b/tests/ui/dialog.lua
index 6d9c85d0a..af9cd0f61 100644
--- a/tests/ui/dialog.lua
+++ b/tests/ui/dialog.lua
@@ -47,7 +47,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("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("ok", "< OK >", function (v, e) self:view("dialog.hello"):show(true, {focused = true}) end)
dialog_main:button_add("cancel", "< Cancel >", "cm_cancel")
dialog_main:button_add("help", "< Help >", "cm_help")
dialog_main:button_add("quit", "< Quit >", "cm_quit")
@@ -57,8 +57,8 @@ function demo:init()
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 >", function (v, e) self:remove(dialog_hello) end)
- dialog_hello:button_add("no", "< No >", function (v, e) self:remove(dialog_hello) end)
+ dialog_hello:button_add("yes", "< Yes >", function (v, e) dialog_hello:show(false) end)
+ dialog_hello:button_add("no", "< No >", function (v, e) dialog_hello:show(false) end)
self:insert(dialog_hello, {centerx = true, centery = true})
end
diff --git a/xmake/core/ui/panel.lua b/xmake/core/ui/panel.lua
index 3c795a0c0..43c71315e 100644
--- a/xmake/core/ui/panel.lua
+++ b/xmake/core/ui/panel.lua
@@ -147,8 +147,7 @@ function panel:remove(v)
-- select next view
if self:current() == v then
- self._CURRENT = nil
- self:select_next()
+ self:select_next(nil, true)
end
-- invalidate it
@@ -195,13 +194,18 @@ function panel:select(v)
end
-- select the next view
-function panel:select_next(start)
+function panel:select_next(start, reset)
-- is empty?
if self:empty() then
return
end
+ -- reset?
+ if reset then
+ self._CURRENT = nil
+ end
+
-- get current view
local current = start or self:current()
@@ -223,6 +227,11 @@ function panel:select_prev(start)
return
end
+ -- reset?
+ if reset then
+ self._CURRENT = nil
+ end
+
-- get current view
local current = start or self:current()
diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua
index de301e795..00c27132a 100644
--- a/xmake/core/ui/view.lua
+++ b/xmake/core/ui/view.lua
@@ -232,8 +232,19 @@ function view:resize()
end
-- show view?
-function view:show(visible)
+--
+-- .e.g
+-- v:show(false)
+-- v:show(true, {focused = true})
+--
+function view:show(visible, opt)
if self:state("visible") ~= visible then
+ local parent = self:parent()
+ if parent and parent:current() == self and not visible then
+ parent:select_next(nil, true)
+ elseif parent and visible and opt and opt.focused then
+ parent:select(self)
+ end
self:state_set("visible", visible)
self:invalidate()
end