summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-12 00:43:05 +0800
committerruki <[email protected]>2018-01-11 22:18:35 +0800
commit2faa7ee11ebce0e797aa71554d7eac80f0a679d2 (patch)
tree8730a53a8744517344bdb4afd0c91ff7b1c09276
parentb8276d35af753721b99e893d92485c99e2de111f (diff)
improve button
-rw-r--r--xmake/core/ui/button.lua30
1 files changed, 23 insertions, 7 deletions
diff --git a/xmake/core/ui/button.lua b/xmake/core/ui/button.lua
index b78c0bc11..abdf63d44 100644
--- a/xmake/core/ui/button.lua
+++ b/xmake/core/ui/button.lua
@@ -24,6 +24,7 @@
-- load modules
local log = require("ui/log")
+local view = require("ui/view")
local label = require("ui/label")
local curses = require("ui/curses")
@@ -43,16 +44,31 @@ function button:init(name, bounds, text, command)
self:cursor_show(true)
end
--- set state
-function button:state_set(name, enable)
+-- draw button
+function button:draw()
- -- set label state
- label.state_set(self, name, enable)
+ -- draw background
+ view.draw(self)
- -- the focused text and background attribute
- if name == "focused" then
- -- TODO
+ -- strip text string
+ local str = self:text()
+ if str and #str > 0 then
+ str = string.sub(str, 1, self:width())
end
+ if not str or #str == 0 then
+ return
+ end
+
+ -- get the text attribute value
+ local textattr = self:textattr_val()
+
+ -- selected?
+ if self:state("selected") then
+ textattr = {textattr, "reverse"}
+ end
+
+ -- draw text
+ self:canvas():attr(textattr):move(0, 0):puts(str)
end
-- return module