summaryrefslogtreecommitdiff
path: root/xmake/core/ui/button.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-23 22:19:11 +0800
committerruki <[email protected]>2018-01-23 07:55:11 +0800
commit2db3a5f053faebb08c3e65e5b097d0de4064ac1e (patch)
tree460a7b2fb2d10f510a3bc712f2bd60f89e626abf /xmake/core/ui/button.lua
parentac234fd5eb079d9e21485ac7d4b06c2c30d2db2a (diff)
add action enums to ui
Diffstat (limited to 'xmake/core/ui/button.lua')
-rw-r--r--xmake/core/ui/button.lua23
1 files changed, 13 insertions, 10 deletions
diff --git a/xmake/core/ui/button.lua b/xmake/core/ui/button.lua
index 6d6d19996..9c6e398f9 100644
--- a/xmake/core/ui/button.lua
+++ b/xmake/core/ui/button.lua
@@ -27,13 +27,14 @@ local log = require("ui/log")
local view = require("ui/view")
local event = require("ui/event")
local label = require("ui/label")
+local action = require("ui/action")
local curses = require("ui/curses")
-- define module
local button = button or label()
-- init button
-function button:init(name, bounds, text, action)
+function button:init(name, bounds, text, on_action)
-- init label
label.init(self, name, bounds, text)
@@ -45,7 +46,7 @@ function button:init(name, bounds, text, action)
self:cursor_show(true)
-- init action
- self:action_set("keyboard.Enter", action)
+ self:action_set(action.ac_on_enter, on_action)
end
-- draw button
@@ -85,14 +86,16 @@ function button:event_on(e)
-- enter this button?
if e.type == event.ev_keyboard then
- local action = self:action("keyboard." .. e.key_name)
- if action then
- if type(action) == "string" then
- -- send command
- self:application():send(action)
- elseif type(action) == "function" then
- -- do action script
- action(self, e)
+ if e.key_name == "Enter" then
+ local on_action = self:action(action.ac_on_enter)
+ if on_action then
+ if type(on_action) == "string" then
+ -- send command
+ self:application():send(on_action)
+ elseif type(on_action) == "function" then
+ -- do action script
+ on_action(self, e)
+ end
end
return true
end