diff options
| author | ruki <[email protected]> | 2018-01-23 22:30:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-01-23 09:03:01 +0800 |
| commit | f7c0c7b89a45bf02a3ca3ffee8251d7a09654e41 (patch) | |
| tree | a0992229d26f8f523db4e6c35de9b2f39c0b44bb | |
| parent | 2db3a5f053faebb08c3e65e5b097d0de4064ac1e (diff) | |
modify action args
| -rw-r--r-- | tests/ui/dialog.lua | 16 | ||||
| -rw-r--r-- | xmake/core/ui/action.lua | 4 | ||||
| -rw-r--r-- | xmake/core/ui/boxdialog.lua | 6 | ||||
| -rw-r--r-- | xmake/core/ui/button.lua | 2 | ||||
| -rw-r--r-- | xmake/core/ui/event.lua | 3 | ||||
| -rw-r--r-- | xmake/core/ui/inputdialog.lua | 6 | ||||
| -rw-r--r-- | xmake/core/ui/label.lua | 11 |
7 files changed, 26 insertions, 22 deletions
diff --git a/tests/ui/dialog.lua b/tests/ui/dialog.lua index b42da5875..a6c87238d 100644 --- a/tests/ui/dialog.lua +++ b/tests/ui/dialog.lua @@ -48,14 +48,14 @@ function demo:init() -- init help dialog local dialog_help = textdialog:new("dialog.help", rect {1, 1, self:width() - 1, self:height() - 1}, "README") dialog_help:text():text_set(io.readfile(path.join(os.scriptdir(), "dialog.lua"))) - dialog_help:button_add("exit", "< Exit >", function (v, e) self:remove(dialog_help) end) + dialog_help:button_add("exit", "< Exit >", function (v) self:remove(dialog_help) end) -- 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("tips", "< Tips >", function (v, e) self:view("dialog.tips"):show(true, {focused = true}) end) - dialog_main:button_add("input", "< Input >", function (v, e) self:view("dialog.input"):show(true, {focused = true}) end) - dialog_main:button_add("help", "< Help >", function (v, e) self:insert(dialog_help) end) + dialog_main:button_add("tips", "< Tips >", function (v) self:view("dialog.tips"):show(true, {focused = true}) end) + dialog_main:button_add("input", "< Input >", function (v) self:view("dialog.input"):show(true, {focused = true}) end) + dialog_main:button_add("help", "< Help >", function (v) self:insert(dialog_help) end) dialog_main:button_add("quit", "< Quit >", "cm_quit") self:insert(dialog_main) @@ -63,8 +63,8 @@ function demo:init() local dialog_input = inputdialog:new("dialog.input", rect {0, 0, 50, 8}):background_set(dialog_main:frame():background()) dialog_input:frame():background_set("cyan") dialog_input:text():text_set("please input text:"):textattr_set("red") - dialog_input:button_add("no", "< No >", function (v, e) dialog_input:show(false) end) - dialog_input:button_add("yes", "< Yes >", function (v, e) + dialog_input:button_add("no", "< No >", function (v) dialog_input:show(false) end) + dialog_input:button_add("yes", "< Yes >", function (v) dialog_main:text():text_set(dialog_input:textedit():text()) dialog_input:show(false) end) @@ -75,8 +75,8 @@ function demo:init() local dialog_tips = textdialog:new("dialog.tips", rect {0, 0, 50, 8}):background_set(dialog_main:frame():background()) dialog_tips:frame():background_set("cyan") dialog_tips:text():text_set("hello xmake! (http://xmake.io)\nA cross-platform build utility based on Lua"):textattr_set("red") - dialog_tips:button_add("yes", "< Yes >", function (v, e) dialog_tips:show(false) end) - dialog_tips:button_add("no", "< No >", function (v, e) dialog_tips:show(false) end) + dialog_tips:button_add("yes", "< Yes >", function (v) dialog_tips:show(false) end) + dialog_tips:button_add("no", "< No >", function (v) dialog_tips:show(false) end) self:insert(dialog_tips, {centerx = true, centery = true}) end diff --git a/xmake/core/ui/action.lua b/xmake/core/ui/action.lua index 11f320ec2..2fcbbdf97 100644 --- a/xmake/core/ui/action.lua +++ b/xmake/core/ui/action.lua @@ -42,8 +42,10 @@ end -- register action enums action:register("ac_max", - "ac_on_text_changed", + "ac_on_text_changed", "ac_on_enter", + "ac_on_load", + "ac_on_save", "ac_on_exit") -- return module diff --git a/xmake/core/ui/boxdialog.lua b/xmake/core/ui/boxdialog.lua index 0ed780e9e..74d5b629d 100644 --- a/xmake/core/ui/boxdialog.lua +++ b/xmake/core/ui/boxdialog.lua @@ -49,9 +49,9 @@ function boxdialog:init(name, bounds, title) self:text():option_set("progress", false) -- text changed - self:text():action_set(action.ac_on_text_changed, function (v, e) - if e.text then - local lines = #self:text():splitext(e.text) + self:text():action_set(action.ac_on_text_changed, function (v) + if v:text() then + local lines = #self:text():splitext(v:text()) if lines > 0 and lines < self:height() then self:box():bounds().sy = lines self:text():bounds().ey = lines diff --git a/xmake/core/ui/button.lua b/xmake/core/ui/button.lua index 9c6e398f9..763dae995 100644 --- a/xmake/core/ui/button.lua +++ b/xmake/core/ui/button.lua @@ -94,7 +94,7 @@ function button:event_on(e) self:application():send(on_action) elseif type(on_action) == "function" then -- do action script - on_action(self, e) + on_action(self) end end return true diff --git a/xmake/core/ui/event.lua b/xmake/core/ui/event.lua index d43927705..1e9060f30 100644 --- a/xmake/core/ui/event.lua +++ b/xmake/core/ui/event.lua @@ -83,9 +83,6 @@ event.keyboard = object {_init = { "key_code", "key_name", "key_meta" }, type = -- define command event event.command = object {_init = { "command", "extra" }, type = event.ev_command} --- define text event -event.text = object {_init = { "text" }, type = event.ev_text} - -- define idle event event.idle = object {_init = {}, type = event.ev_idle} diff --git a/xmake/core/ui/inputdialog.lua b/xmake/core/ui/inputdialog.lua index 5a2a271ff..511a9c810 100644 --- a/xmake/core/ui/inputdialog.lua +++ b/xmake/core/ui/inputdialog.lua @@ -52,9 +52,9 @@ function inputdialog:init(name, bounds, title) self:text():option_set("progress", false) -- text changed - self:text():action_set(action.ac_on_text_changed, function (v, e) - if e.text then - local lines = #self:text():splitext(e.text) + self:text():action_set(action.ac_on_text_changed, function (v) + if v:text() then + local lines = #self:text():splitext(v:text()) if lines > 0 and lines < self:height() then self:text():bounds().ey = lines self:textedit():bounds().sy = lines diff --git a/xmake/core/ui/label.lua b/xmake/core/ui/label.lua index f39358368..0fcce66d5 100644 --- a/xmake/core/ui/label.lua +++ b/xmake/core/ui/label.lua @@ -68,14 +68,19 @@ end -- set text function label:text_set(text) + + -- set text text = text or "" - if self._TEXT ~= text then + local changed = self._TEXT ~= text + self._TEXT = text + + -- do action + if changed then local on_action = self:action(action.ac_on_text_changed) if on_action then - on_action(self, event.text {text}) + on_action(self) end end - self._TEXT = text self:invalidate() return self end |
