summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-26 22:20:20 +0800
committerruki <[email protected]>2018-01-26 08:02:01 +0800
commit1589248c258456d5045d8e5bb9db69c9663f7181 (patch)
treefaafbb0ee60dba2afb3fbbf90e5081017d1838e7
parent019c81967d55a77950d0249d6d5674bbdb193796 (diff)
improve title bounds
-rw-r--r--xmake/core/ui/window.lua9
1 files changed, 9 insertions, 0 deletions
diff --git a/xmake/core/ui/window.lua b/xmake/core/ui/window.lua
index 2d10cd126..4f07c09d8 100644
--- a/xmake/core/ui/window.lua
+++ b/xmake/core/ui/window.lua
@@ -31,6 +31,7 @@ local panel = require("ui/panel")
local event = require("ui/event")
local border = require("ui/border")
local curses = require("ui/curses")
+local action = require("ui/action")
-- define module
local window = window or panel()
@@ -58,6 +59,14 @@ function window:init(name, bounds, title, shadow)
if title then
self._TITLE = label:new("window.title", rect{0, 0, #title, 1}, title)
self:title():textattr_set("blue bold")
+ self:title():action_set(action.ac_on_text_changed, function (v)
+ if v:text() then
+ local bounds = v:bounds()
+ v:bounds():resize(#v:text(), v:height())
+ bounds:move2(math.max(0, math.floor((self:frame():width() - v:width()) / 2)), bounds.sy)
+ v:invalidate(true)
+ end
+ end)
self:frame():insert(self:title(), {centerx = true})
end