summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-12-26 00:34:40 +0800
committerruki <[email protected]>2017-12-25 21:28:00 +0800
commit6d5b0370398a581f14569ea7b63d31217d4252fc (patch)
tree026294ac4bf021bafe96c818c4b7e82b52d327e3
parent994f26116837e8502af2ea8ce81ce7aa2f3d9f94 (diff)
add background for ui view
-rw-r--r--xmake/core/sandbox/modules/import/core/ui/button.lua26
-rw-r--r--xmake/core/ui/button.lua75
-rw-r--r--xmake/core/ui/curses.lua1
-rw-r--r--xmake/core/ui/desktop.lua35
-rw-r--r--xmake/core/ui/label.lua13
-rw-r--r--xmake/core/ui/menubar.lua19
-rw-r--r--xmake/core/ui/statusbar.lua25
-rw-r--r--xmake/core/ui/view.lua17
8 files changed, 141 insertions, 70 deletions
diff --git a/xmake/core/sandbox/modules/import/core/ui/button.lua b/xmake/core/sandbox/modules/import/core/ui/button.lua
new file mode 100644
index 000000000..bc199ce45
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/ui/button.lua
@@ -0,0 +1,26 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file button.lua
+--
+
+-- return module: button
+return require("ui/button")
diff --git a/xmake/core/ui/button.lua b/xmake/core/ui/button.lua
new file mode 100644
index 000000000..95a4b3fcb
--- /dev/null
+++ b/xmake/core/ui/button.lua
@@ -0,0 +1,75 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file button.lua
+--
+
+-- load modules
+local log = require("ui/log")
+local view = require("ui/view")
+local curses = require("ui/curses")
+
+-- define module
+local button = button or view()
+
+-- init button
+function button:init(name, bounds, text)
+
+ -- init view
+ view.init(self, name, bounds)
+
+ -- init text
+ self._TEXT = text or ""
+
+ -- init color
+ self:attr_set("color", curses.color_pair("white", "blue"))
+end
+
+-- exit button
+function button:exit()
+ view.exit(self)
+end
+
+-- draw view
+function button:draw()
+
+ -- trace
+ log:print("%s: draw ..", self)
+
+ -- draw it
+ local c = self:canvas()
+ local s = string.sub(self:text(), 1, self:width()) .. string.rep(' ', self:width() - #self:text())
+ c:attr(self:attr("color")):move(0, 0):write(s, self:attr("color"))
+end
+
+-- get text
+function button:text()
+ return self._TEXT
+end
+
+-- set text
+function button:text_set(text)
+ self._TEXT = text or ""
+ self:invalidate()
+end
+
+-- return module
+return button
diff --git a/xmake/core/ui/curses.lua b/xmake/core/ui/curses.lua
index 124797ec6..37b25fae8 100644
--- a/xmake/core/ui/curses.lua
+++ b/xmake/core/ui/curses.lua
@@ -167,7 +167,6 @@ function curses.color_pair(fg, bg)
os.raise("failed to initialize color pair (%d, %s, %s)", curses._NCOLORS, fg, bg)
end
- -- TODO rename
-- get the color attr
local attr = curses._color_pair(curses._NCOLORS)
diff --git a/xmake/core/ui/desktop.lua b/xmake/core/ui/desktop.lua
index 0b0f3e550..1de91c6a8 100644
--- a/xmake/core/ui/desktop.lua
+++ b/xmake/core/ui/desktop.lua
@@ -38,8 +38,8 @@ function desktop:init(name, bounds)
-- init group
group.init(self, name, bounds)
- -- add background
- self:insert(self:background())
+ -- init background
+ self:background_set(curses.color_pair("white", "blue"))
end
-- exit desktop
@@ -47,35 +47,12 @@ function desktop:exit()
group.exit(self)
end
--- get desktop background
-function desktop:background()
-
- -- init background
- if not self._BACKGROUND then
-
- -- create background view
- local background = view:new("desktop.background", rect {0, 0, self:width(), self:height()})
- self._BACKGROUND = background
-
- -- init background color
- background:attr_set("color", curses.color_pair("white", "blue"))
+-- draw desktop
+function desktop:draw()
- -- draw background
- function background:draw()
-
- -- trace
- log:print("%s: draw ..", self)
-
- -- draw it
- local c = self:canvas()
- c:attr(self:attr("color")):move(0, 0):write(string.rep(' ', self:width() * self:height()))
- end
- end
-
- -- get background
- return self._BACKGROUND
+ -- draw background
+ view.draw(self)
end
-
-- return module
return desktop
diff --git a/xmake/core/ui/label.lua b/xmake/core/ui/label.lua
index 505b674da..0d25cc156 100644
--- a/xmake/core/ui/label.lua
+++ b/xmake/core/ui/label.lua
@@ -37,10 +37,10 @@ function label:init(name, bounds, text)
view.init(self, name, bounds)
-- init text
- self._TEXT = text or ""
+ self:text_set(text)
- -- init color
- self:attr_set("color", curses.color_pair("white", "blue"))
+ -- init background
+ self:background_set(curses.color_pair("white", "blue"))
end
-- exit label
@@ -51,13 +51,12 @@ end
-- draw view
function label:draw()
- -- trace
- log:print("%s: draw ..", self)
+ -- draw background
+ view.draw(self)
-- draw it
- local c = self:canvas()
local s = string.sub(self:text(), 1, self:width()) .. string.rep(' ', self:width() - #self:text())
- c:attr(self:attr("color")):move(0, 0):write(s, self:attr("color"))
+ self:canvas():move(0, 0):write(s)
end
-- get text
diff --git a/xmake/core/ui/menubar.lua b/xmake/core/ui/menubar.lua
index df55f1610..356a70f9e 100644
--- a/xmake/core/ui/menubar.lua
+++ b/xmake/core/ui/menubar.lua
@@ -22,11 +22,6 @@
-- @file menubar.lua
--
---[[ Console User Interface (cui) ]-----------------------------------------
-Author: Tiago Dionizio (tiago.dionizio AT gmail.com)
-$Id: menubar.lua 18 2007-06-21 20:43:52Z tngd $
---------------------------------------------------------------------------]]
-
-- load modules
local log = require("ui/log")
local view = require("ui/view")
@@ -42,10 +37,10 @@ function menubar:init(name, bounds)
view.init(self, name, bounds)
-- init title
- self._TITLE = "Menu Bar"
+ self:title_set("Menu Bar")
- -- init color
- self:attr_set("color", curses.color_pair("red", "white"))
+ -- init background
+ self:background_set(curses.color_pair("red", "white"))
end
-- exit menubar
@@ -56,13 +51,11 @@ end
-- draw view
function menubar:draw()
- -- trace
- log:print("%s: draw ..", self)
+ -- draw background
+ view.draw(self)
-- draw it
- local c = self:canvas()
- c:attr(self:attr("color")):move(0, 0):write(string.rep(' ', self:width() * self:height()))
- c:move(1, 0):write(self:title())
+ self:canvas():move(1, 0):write(self:title())
end
-- en event
diff --git a/xmake/core/ui/statusbar.lua b/xmake/core/ui/statusbar.lua
index 634bdbfc3..18688e86f 100644
--- a/xmake/core/ui/statusbar.lua
+++ b/xmake/core/ui/statusbar.lua
@@ -22,11 +22,6 @@
-- @file statusbar.lua
--
---[[ Console User Interface (cui) ]-----------------------------------------
-Author: Tiago Dionizio (tiago.dionizio AT gmail.com)
-$Id: statusbar.lua 18 2007-06-21 20:43:52Z tngd $
---------------------------------------------------------------------------]]
-
-- load modules
local log = require("ui/log")
local view = require("ui/view")
@@ -44,6 +39,9 @@ function statusbar:init(name, bounds, commands)
-- init info
self:info_set("")
+
+ -- init background
+ self:background_set(curses.color_pair("blue", "white"))
end
-- exit statusbar
@@ -54,22 +52,11 @@ end
-- draw view
function statusbar:draw()
- -- trace
- log:print("%s: draw ..", self)
-
- -- get canvas
- local c = self:canvas()
- c:move(0, 0)
-
- -- draw statusbar
- local x = 0
- local color = self:attr("color")
- if x < self:width() then
- c:attr(color):write(string.rep(' ', self:width() - x))
- end
+ -- draw background
+ view.draw(self)
-- draw status info
- c:move(1, 0):write(self:info())
+ self:canvas():move(1, 0):write(self:info())
end
-- on event
diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua
index 26ab2b246..e119d0c24 100644
--- a/xmake/core/ui/view.lua
+++ b/xmake/core/ui/view.lua
@@ -68,7 +68,6 @@ function view:init(name, bounds)
-- init attributes
local attrs = object()
- attrs.color = curses.color_pair("blue", "white")
self._ATTRS = attrs
-- init needed events type
@@ -178,6 +177,12 @@ function view:draw()
-- clear view
self:canvas():clear()
+
+ -- draw background
+ local background = self:background()
+ if background then
+ self:canvas():attr(background):move(0, 0):write(string.rep(' ', self:width() * self:height()))
+ end
end
-- refresh view
@@ -285,6 +290,16 @@ function view:attr_set(name, value)
self:invalidate()
end
+-- get background
+function view:background()
+ return self:attr("background")
+end
+
+-- set background
+function view:background_set(color)
+ self:attr_set("background", color)
+end
+
-- need redraw view
function view:_mark_redraw()