From f37f8f9a1588348b042b1df69a805dc614f0fbbc Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 28 Dec 2017 00:30:37 +0800 Subject: improve group select --- xmake/core/ui/button.lua | 12 ++++++++++++ xmake/core/ui/group.lua | 47 +++++++++++++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/xmake/core/ui/button.lua b/xmake/core/ui/button.lua index 22413a83c..92f5f8894 100644 --- a/xmake/core/ui/button.lua +++ b/xmake/core/ui/button.lua @@ -43,5 +43,17 @@ function button:init(name, bounds, text) self:cursor_show(true) end +-- set state +function button:state_set(name, enable) + + -- set label state + label.state_set(self, name, enable) + + -- the focused text and background attribute + if name == "focused" then + -- TODO + end +end + -- return module return button diff --git a/xmake/core/ui/group.lua b/xmake/core/ui/group.lua index 61ce7f8d7..5315b1b4e 100644 --- a/xmake/core/ui/group.lua +++ b/xmake/core/ui/group.lua @@ -198,7 +198,7 @@ function group:select(v) end -- select the next view -function group:select_next(forward, start) +function group:select_next(start) -- is empty? if self:empty() then @@ -208,25 +208,36 @@ function group:select_next(forward, start) -- get current view local current = start or self:current() or self:first() - -- forward? - if forward then - local next = self:next(current) - while next ~= current do - if next:option("selectable") and next:state("visible") then - self:select(next) - break - end - next = self:next(next) + -- select the next view + local next = self:next(current) + while next ~= current do + if next:option("selectable") and next:state("visible") then + self:select(next) + break end - else - local prev = self:prev(current) - while prev ~= current do - if prev:option("selectable") and prev:state("visible") then - self:select(prev) - break - end - prev = self:prev(prev) + next = self:next(next) + end +end + +-- select the previous view +function group:select_prev(start) + + -- is empty? + if self:empty() then + return + end + + -- get current view + local current = start or self:current() or self:first() + + -- select the previous view + local prev = self:prev(current) + while prev ~= current do + if prev:option("selectable") and prev:state("visible") then + self:select(prev) + break end + prev = self:prev(prev) end end -- cgit v1.3.1