diff options
| author | ruki <[email protected]> | 2018-01-16 00:25:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-01-15 20:34:26 +0800 |
| commit | a36785d37fa91a238a3c5358f0dadb2f8de473d3 (patch) | |
| tree | 767b3102892042cf7aac784bdf699732680dee6e /xmake/core/ui/button.lua | |
| parent | a5e736899e441c3c93e8bbece028ed16b98dbb1c (diff) | |
select and draw focused view
Diffstat (limited to 'xmake/core/ui/button.lua')
| -rw-r--r-- | xmake/core/ui/button.lua | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/xmake/core/ui/button.lua b/xmake/core/ui/button.lua index 3d788b560..482dcef9a 100644 --- a/xmake/core/ui/button.lua +++ b/xmake/core/ui/button.lua @@ -45,7 +45,7 @@ function button:init(name, bounds, text, action) self:cursor_show(true) -- init action - self:action_set("on_enter", action) + self:action_set("keyboard.Enter", action) end -- draw button @@ -85,21 +85,27 @@ function button:event_on(e) -- enter this button? if e.type == event.ev_keyboard then - if e.key_name == "Enter" then - local on_enter = self:action("on_enter") - if on_enter then - if type(on_enter) == "string" then - -- send command - self:application():send(on_enter) - elseif type(on_enter) == "function" then - -- do enter script - on_enter(self) - end + 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) end return true end end end +-- set state +function button:state_set(name, enable) + if name == "focused" and self:state(name) ~= enable then + self:invalidate() + end + return view.state_set(self, name, enable) +end + -- return module return button |
