summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-12-27 22:30:21 +0800
committerruki <[email protected]>2017-12-27 09:02:06 +0800
commit5a9bc97b532309a1d13175e5ce4e82a2f430d58e (patch)
treed201b1b561cb7dc70fcbd3eed2029a077ecc2367
parentc2af438912e29dec6f1e8962633f339a6ab2cab7 (diff)
add two button to hello
-rw-r--r--tests/ui/hello.lua7
-rw-r--r--xmake/core/ui/button.lua42
2 files changed, 11 insertions, 38 deletions
diff --git a/tests/ui/hello.lua b/tests/ui/hello.lua
index 776cee75a..490bf46de 100644
--- a/tests/ui/hello.lua
+++ b/tests/ui/hello.lua
@@ -28,6 +28,7 @@ import("core.ui.rect")
import("core.ui.view")
import("core.ui.label")
import("core.ui.event")
+import("core.ui.button")
import("core.ui.application")
-- the hello application
@@ -44,6 +45,12 @@ function hello:init()
-- add title label
self:desktop():insert(label:new("title", rect {0, 0, 12, 1}, "hello xmake!"), {centerx = true})
+
+ -- add yes button
+ self:desktop():insert(button:new("yes", rect {0, 1, 7, 2}, "< Yes >"), {centerx = true})
+
+ -- add no button
+ self:desktop():insert(button:new("no", rect {0, 2, 6, 3}, "< No >"), {centerx = true})
end
-- on event
diff --git a/xmake/core/ui/button.lua b/xmake/core/ui/button.lua
index 95a4b3fcb..fe9a719c7 100644
--- a/xmake/core/ui/button.lua
+++ b/xmake/core/ui/button.lua
@@ -24,51 +24,17 @@
-- load modules
local log = require("ui/log")
-local view = require("ui/view")
+local label = require("ui/label")
local curses = require("ui/curses")
-- define module
-local button = button or view()
+local button = button or label()
-- 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()
+ -- init label
+ label.init(self, name, bounds, text)
end
-- return module