diff options
| author | ruki <[email protected]> | 2017-12-19 22:38:24 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-19 09:50:27 +0800 |
| commit | 5924ef4adbe4b084c465bc9604254be60d147074 (patch) | |
| tree | 93c00311a46d3ac7034b775ba4fa6b69212bff9f | |
| parent | b061bd17789d582771c77778e17a4f5576e1a01f (diff) | |
remove some redraw ops
| -rw-r--r-- | tests/ui/hello.lua | 15 | ||||
| -rw-r--r-- | xmake/core/ui/application.lua | 4 | ||||
| -rw-r--r-- | xmake/core/ui/group.lua | 11 | ||||
| -rw-r--r-- | xmake/core/ui/menubar.lua | 16 | ||||
| -rw-r--r-- | xmake/core/ui/statusbar.lua | 13 | ||||
| -rw-r--r-- | xmake/core/ui/view.lua | 15 |
6 files changed, 47 insertions, 27 deletions
diff --git a/tests/ui/hello.lua b/tests/ui/hello.lua index 847d75ded..21bcd1b96 100644 --- a/tests/ui/hello.lua +++ b/tests/ui/hello.lua @@ -25,7 +25,20 @@ -- imports import("core.ui.application") +-- the hello application +local hello = application() + +-- init hello +function hello:init() + + -- init name + application.init(self, "hello") + + -- init title + self:menubar():title_set("xmake") +end + -- main entry function main(...) - application.run("hello", ...) + hello:run(...) end diff --git a/xmake/core/ui/application.lua b/xmake/core/ui/application.lua index 8caf4a01e..9401728be 100644 --- a/xmake/core/ui/application.lua +++ b/xmake/core/ui/application.lua @@ -106,14 +106,14 @@ function application:do_event(e) end -- run application -function application.run(name, ...) +function application:run(...) -- init runner local argv = {...} local runner = function () -- new an application - local app = application:new(name) + local app = self:new() if app then app:loop(argv) app:exit() diff --git a/xmake/core/ui/group.lua b/xmake/core/ui/group.lua index b9846c731..a088ef7af 100644 --- a/xmake/core/ui/group.lua +++ b/xmake/core/ui/group.lua @@ -28,6 +28,7 @@ $Id: group.lua 18 2007-06-21 20:43:52Z tngd $ --------------------------------------------------------------------------]] -- load modules +local log = require("ui/log") local view = require("ui/view") local rect = require("ui/rect") local event = require("ui/event") @@ -133,8 +134,7 @@ function group:insert(v) self:select(v) end - -- draw and show this view - v:draw() + -- show this view v:show(true) -- unlock @@ -252,6 +252,9 @@ function group:execute() -- show this group self:show(true) + -- refresh first + self:refresh() + -- do message loop local e = nil local sleep = true @@ -300,7 +303,11 @@ function group:redraw(on_parent) -- redraw all child views for v in self:views() do if v:state("visible") then + + -- cause groups to redraw v:redraw(false) + + -- draw this child view self:_draw_child(v) end end diff --git a/xmake/core/ui/menubar.lua b/xmake/core/ui/menubar.lua index 1148909aa..1c770d64c 100644 --- a/xmake/core/ui/menubar.lua +++ b/xmake/core/ui/menubar.lua @@ -41,8 +41,8 @@ function menubar:init(name, bounds) -- init view view.init(self, name, bounds) - -- init color - self:attr_set("color", curses.color_pair("red", "white")) + -- init title + self._TITLE = "" end -- exit menubar @@ -54,7 +54,7 @@ end function menubar:draw() local c = self:canvas() c:attr(self:attr("color")):move(0, 0):write(string.rep(' ', self:width() * self:height())) - c:move(1, 0):write('Menu Bar') + c:move(1, 0):write(self:title()) end -- do event @@ -62,5 +62,15 @@ function menubar:do_event(e) view.do_event(self, e) end +-- get title +function menubar:title() + return self._TITLE +end + +-- set title +function menubar:title_set(title) + self._TITLE = title or "" +end + -- return module return menubar diff --git a/xmake/core/ui/statusbar.lua b/xmake/core/ui/statusbar.lua index fbdc46ff8..564ac4a15 100644 --- a/xmake/core/ui/statusbar.lua +++ b/xmake/core/ui/statusbar.lua @@ -36,13 +36,7 @@ local statusbar = statusbar or view() -- init statusbar function statusbar:init(name, bounds) - - -- init view view.init(self, name, bounds) - - -- init attributes - self:attr_set("key", curses.color_pair("red", "white")) - self:attr_set("text", curses.color_pair("black", "white")) end -- exit statusbar @@ -57,12 +51,11 @@ function statusbar:draw() local c = self:canvas() c:move(0, 0) - -- draw status + -- draw statusbar local x = 0 - local kattr = self:attr("key") - local tattr = self:attr("text") + local color = self:attr("color") if x < self:width() then - c:attr(tattr):write(string.rep(' ', self:width() - x)) + c:attr(color):write(string.rep(' ', self:width() - x)) end end diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua index fb64ff406..6efb3c525 100644 --- a/xmake/core/ui/view.lua +++ b/xmake/core/ui/view.lua @@ -81,8 +81,9 @@ function view:init(name, bounds) self._OPTIONS = options -- init attributes - local attrs = object() - self._ATTRS = attrs + local attrs = object() + attrs.color = curses.color_pair("blue", "white") + self._ATTRS = attrs -- init name self._NAME = name @@ -181,6 +182,7 @@ end -- draw view function view:draw() +log:print("view draw: %s", self:name()) self:canvas():clear() end @@ -256,11 +258,6 @@ function view:state_set(name, enable) -- change state self._STATE[name] = enable - - -- update visible? - if name == "visible" then - self:redraw(true) - end end -- get option @@ -287,8 +284,8 @@ function view:attr(name) end -- set attribute -function view:attr_set(name, attr) - self._ATTRS[name] = attr +function view:attr_set(name, value) + self._ATTRS[name] = value end -- update screen |
