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/program.lua | |
| parent | a5e736899e441c3c93e8bbece028ed16b98dbb1c (diff) | |
select and draw focused view
Diffstat (limited to 'xmake/core/ui/program.lua')
| -rw-r--r-- | xmake/core/ui/program.lua | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/xmake/core/ui/program.lua b/xmake/core/ui/program.lua index 0fe44049b..82ada0bcf 100644 --- a/xmake/core/ui/program.lua +++ b/xmake/core/ui/program.lua @@ -80,6 +80,10 @@ function program:init(name) -- init panel panel.init(self, name, rect {0, 0, curses.columns(), curses.lines()}) + + -- init state + self:state_set("focused", true) + self:state_set("selected", true) end -- exit program @@ -143,9 +147,22 @@ end -- on event function program:event_on(e) - if panel.event_on(self, e) then - return true + + -- get the top focused view + local focused_view = self + while focused_view:type() == "panel" and focused_view:current() do + focused_view = focused_view:current() end + + -- do event for focused views + while focused_view and focused_view ~= self do + if focused_view:event_on(e) then + return true + end + focused_view = focused_view:parent() + end + + -- quit program? if e.type == event.ev_keyboard and (e.key_name == "Esc" or e.key_name == "CtrlC") then self:quit() return true |
