diff options
| author | ruki <[email protected]> | 2017-12-25 22:25:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-25 08:35:44 +0800 |
| commit | 994f26116837e8502af2ea8ce81ce7aa2f3d9f94 (patch) | |
| tree | 4d1fc547db18fcd480589530e52b5441622873ee | |
| parent | 34df1cdc819a181872aa987c3ea9f2ba0810127c (diff) | |
improve group.insert
| -rw-r--r-- | tests/ui/hello.lua | 4 | ||||
| -rw-r--r-- | xmake/core/ui/group.lua | 6 | ||||
| -rw-r--r-- | xmake/core/ui/view.lua | 2 |
3 files changed, 4 insertions, 8 deletions
diff --git a/tests/ui/hello.lua b/tests/ui/hello.lua index b24b70e70..f52d71230 100644 --- a/tests/ui/hello.lua +++ b/tests/ui/hello.lua @@ -43,9 +43,7 @@ function hello:init() self:menubar():title_set("Menu Bar (Hello)") -- add title label - local title = "hello xmake!" - local pos = (self:width() - #title) / 2 - self:desktop():insert(label:new("title", rect {pos, 0, pos + #title, 1}, title)) + self:desktop():insert(label:new("title", rect {0, 0, 12, 1}, "hello xmake!"), {centerx = true}) end -- on event diff --git a/xmake/core/ui/group.lua b/xmake/core/ui/group.lua index 73236627d..fada01444 100644 --- a/xmake/core/ui/group.lua +++ b/xmake/core/ui/group.lua @@ -90,7 +90,7 @@ function group:current() end -- insert view -function group:insert(v) +function group:insert(v, opt) -- check assert(not v:parent() or v:parent() == self) @@ -103,10 +103,10 @@ function group:insert(v) -- center this view if centerx or centery are set local bounds = v:bounds() local org = point {bounds.sx, bounds.sy} - if v:option("centerx") then + if opt and opt.centerx then org.x = math.floor((self:width() - v:width()) / 2) end - if v:option("centery") then + if opt and opt.centery then org.y = math.floor((self:height() - v:height()) / 2) end bounds:move(org.x - bounds.sx, org.y - bounds.sy) diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua index d7d09ddc2..26ab2b246 100644 --- a/xmake/core/ui/view.lua +++ b/xmake/core/ui/view.lua @@ -64,8 +64,6 @@ function view:init(name, bounds) local options = object() options.selectable = false -- true if window can be selected options.top_select = false -- if true, selecting window will bring it to front - options.centerx = false -- center horizontaly when inserting in parent - options.centery = false -- center verticaly when inserting in parent self._OPTIONS = options -- init attributes |
