diff options
| author | ruki <[email protected]> | 2017-12-14 00:33:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-13 21:18:51 +0800 |
| commit | 2694f86469cdd776ba2caba9bcd7ec261457aa2c (patch) | |
| tree | cda848781d502ca90804432575d88871be1a8b55 /xmake/core/ui/view.lua | |
| parent | fccce25811e0a02bca4ac81a9ecadea85b2f855f (diff) | |
add core.base.dlist
Diffstat (limited to 'xmake/core/ui/view.lua')
| -rw-r--r-- | xmake/core/ui/view.lua | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua index e8e38a9f3..4008ce547 100644 --- a/xmake/core/ui/view.lua +++ b/xmake/core/ui/view.lua @@ -29,6 +29,7 @@ $Id: view.lua 18 2007-06-21 20:43:52Z tngd $ -- load modules local object = require("ui/object") +local canvas = require("ui/canvas") local curses = require("ui/curses") -- define module @@ -53,7 +54,18 @@ function view:init(bounds) -- check assert(type(bounds) == 'table') - -- init bounds + -- init state + local state = object() + state.visible = false -- view visibility + state.cursor_visible = false -- cursor visibility + state.block_cursor = false -- block cursor + state.selected = false -- current selected window inside group + state.focused = false -- true if parent is also focused + state.disabled = false -- view disabled + state.modal = false -- is modal view? + self._STATE = state + + -- init bounds and window self:bounds_set(bounds) end @@ -92,6 +104,82 @@ function view:bounds() return self._bounds() end +-- get the parent view +function view:parent() + return self._PARENT +end + +-- get the view canvas +function view:canvas() + if not self._CANVAS then + self._CANVAS = canvas:new(self, self._window) + end + return self._CANVAS +end + +-- on draw window +function view:on_draw() + self:canvas():clear() +end + +-- refresh view in parent window +function view:refresh() + self:on_draw() + self:redraw(true) +end + +-- redraw view +function view:redraw(on_parent) + + -- redraw this child view on parent view (group) + if on_parent and self:parent() then + self:lock() + local v = self + while v:parent() do + v:parent():draw_child(v) + v = v:parent() + end + self:unlock() + end +end + +-- lock view +function view:lock() +end + +-- unlock view +function view:unlock() +end + +-- show view? +function view:show(visible) + if self:state("visible") ~= visible then + self:state_set("visible", visible) + end +end + +-- get state +function view:state(name) + return self._STATE[name] +end + +-- set state +function view:state_set(name, enable) + + -- state is not changed? + enable = enable or false + if self:state(name) == enable then + return + end + + -- change state + self._STATE[name] = enable + + -- update visible? + if name == "visible" then + self:redraw(true) + end +end -- return module return view |
