diff options
| author | ruki <[email protected]> | 2017-12-22 22:35:14 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-22 09:31:26 +0800 |
| commit | 0f825ce5a225f7dfba8e46e44de82c50df0b2e35 (patch) | |
| tree | 2948fca0cc55a67a57ef10901a25a503828415f5 | |
| parent | 8594fdccd6cb87909a227f6ad0d794188bc11584 (diff) | |
improve cui refresh
| -rw-r--r-- | tests/ui/hello.lua | 7 | ||||
| -rw-r--r-- | xmake/core/ui/desktop.lua | 5 | ||||
| -rw-r--r-- | xmake/core/ui/group.lua | 8 | ||||
| -rw-r--r-- | xmake/core/ui/program.lua | 26 | ||||
| -rw-r--r-- | xmake/core/ui/view.lua | 12 |
5 files changed, 30 insertions, 28 deletions
diff --git a/tests/ui/hello.lua b/tests/ui/hello.lua index a069d015c..fb75384a8 100644 --- a/tests/ui/hello.lua +++ b/tests/ui/hello.lua @@ -46,6 +46,13 @@ function hello:event_on(e) view.event_on(self, e) if e.type == event.ev_keyboard then self:statusbar():info_set(e.key_name) + if e.key_name == "s" then + self:statusbar():show(not self:statusbar():state("visible")) + elseif e.key_name == "m" then + self:menubar():show(not self:menubar():state("visible")) + elseif e.key_name == "d" then + self:desktop():show(not self:desktop():state("visible")) + end end end diff --git a/xmake/core/ui/desktop.lua b/xmake/core/ui/desktop.lua index 9bf1e98ea..48bbcbaf6 100644 --- a/xmake/core/ui/desktop.lua +++ b/xmake/core/ui/desktop.lua @@ -22,11 +22,6 @@ -- @file desktop.lua -- ---[[ Console User Interface (cui) ]----------------------------------------- -Author: Tiago Dionizio (tiago.dionizio AT gmail.com) -$Id: desktop.lua 18 2007-06-21 20:43:52Z tngd $ ---------------------------------------------------------------------------]] - -- load modules local log = require("ui/log") local group = require("ui/group") diff --git a/xmake/core/ui/group.lua b/xmake/core/ui/group.lua index 80f7c22b7..73236627d 100644 --- a/xmake/core/ui/group.lua +++ b/xmake/core/ui/group.lua @@ -22,11 +22,6 @@ -- @file group.lua -- ---[[ Console User Interface (cui) ]----------------------------------------- -Author: Tiago Dionizio (tiago.dionizio AT gmail.com) -$Id: group.lua 18 2007-06-21 20:43:52Z tngd $ ---------------------------------------------------------------------------]] - -- load modules local log = require("ui/log") local view = require("ui/view") @@ -262,11 +257,13 @@ function group:draw() if v:state("visible") then v:draw() v:state_set("redraw", false) + v:_mark_refresh() end end -- clear mark self:state_set("redraw", false) + self:_mark_refresh() else -- only draw child views @@ -274,6 +271,7 @@ function group:draw() if v:state("visible") and v:state("redraw") then v:draw() v:state_set("redraw", false) + v:_mark_refresh() end end end diff --git a/xmake/core/ui/program.lua b/xmake/core/ui/program.lua index 8d30903c0..e934e8e54 100644 --- a/xmake/core/ui/program.lua +++ b/xmake/core/ui/program.lua @@ -123,23 +123,31 @@ end -- get the current event function program:event() + -- get event from the event queue first + local event_queue = self._EVENT_QUEUE + if event_queue then + local e = event_queue[1] + if e then + table.remove(event_queue, 1) + return e + end + end + -- get input key local key_code, key_name, key_meta = self:_input_key() if key_code then - if key_name == "Resize" or key_name == "CtrlL" then - self:change_bounds(Rect{0, 0, curses.columns(), curses.lines()}) - self:refresh() - elseif key_name == "Refresh" then - self:refresh() - else - return event.keyboard{key_code, key_name, key_meta} - end + return event.keyboard{key_code, key_name, key_meta} end end -- put an event to view function program:event_put(e) - -- TODO + + -- init event queue + self._EVENT_QUEUE = self._EVENT_QUEUE or {} + + -- put event to queue + table.insert(self._EVENT_QUEUE, e) end -- run program loop diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua index adfcbe209..d7d09ddc2 100644 --- a/xmake/core/ui/view.lua +++ b/xmake/core/ui/view.lua @@ -22,11 +22,6 @@ -- @file view.lua -- ---[[ Console User Interface (cui) ]----------------------------------------- -Author: Tiago Dionizio (tiago.dionizio AT gmail.com) -$Id: view.lua 18 2007-06-21 20:43:52Z tngd $ ---------------------------------------------------------------------------]] - -- load modules local log = require("ui/log") local rect = require("ui/rect") @@ -218,10 +213,7 @@ end -- invalidate view to redraw it function view:invalidate() - - -- need redraw and refresh it self:_mark_redraw() - self:_mark_refresh() end -- on event (abstract) @@ -311,7 +303,9 @@ end function view:_mark_refresh() -- need refresh it - self:state_set("refresh", true) + if self:state("visible") then + self:state_set("refresh", true) + end -- need refresh it's parent view if self:parent() then |
