From c29bf9dde01066325f2a8734a6fda6cd1bc40549 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 28 Dec 2017 22:34:34 +0800 Subject: rename group to panel --- .../core/sandbox/modules/import/core/ui/group.lua | 26 -- .../core/sandbox/modules/import/core/ui/panel.lua | 26 ++ xmake/core/ui/desktop.lua | 8 +- xmake/core/ui/group.lua | 337 --------------------- xmake/core/ui/menubar.lua | 8 +- xmake/core/ui/panel.lua | 337 +++++++++++++++++++++ xmake/core/ui/program.lua | 16 +- xmake/core/ui/statusbar.lua | 8 +- xmake/core/ui/view.lua | 2 +- 9 files changed, 384 insertions(+), 384 deletions(-) delete mode 100644 xmake/core/sandbox/modules/import/core/ui/group.lua create mode 100644 xmake/core/sandbox/modules/import/core/ui/panel.lua delete mode 100644 xmake/core/ui/group.lua create mode 100644 xmake/core/ui/panel.lua diff --git a/xmake/core/sandbox/modules/import/core/ui/group.lua b/xmake/core/sandbox/modules/import/core/ui/group.lua deleted file mode 100644 index 952a9c17b..000000000 --- a/xmake/core/sandbox/modules/import/core/ui/group.lua +++ /dev/null @@ -1,26 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file group.lua --- - --- return module: group -return require("ui/group") diff --git a/xmake/core/sandbox/modules/import/core/ui/panel.lua b/xmake/core/sandbox/modules/import/core/ui/panel.lua new file mode 100644 index 000000000..bf20d610a --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/panel.lua @@ -0,0 +1,26 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file panel.lua +-- + +-- return module: panel +return require("ui/panel") diff --git a/xmake/core/ui/desktop.lua b/xmake/core/ui/desktop.lua index 3682a230f..0715252b7 100644 --- a/xmake/core/ui/desktop.lua +++ b/xmake/core/ui/desktop.lua @@ -26,17 +26,17 @@ local log = require("ui/log") local rect = require("ui/rect") local view = require("ui/view") -local group = require("ui/group") +local panel = require("ui/panel") local curses = require("ui/curses") -- define module -local desktop = desktop or group() +local desktop = desktop or panel() -- init desktop function desktop:init(name, bounds) - -- init group - group.init(self, name, bounds) + -- init panel + panel.init(self, name, bounds) -- init background self:background_set("blue") diff --git a/xmake/core/ui/group.lua b/xmake/core/ui/group.lua deleted file mode 100644 index 5315b1b4e..000000000 --- a/xmake/core/ui/group.lua +++ /dev/null @@ -1,337 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file group.lua --- - --- load modules -local log = require("ui/log") -local view = require("ui/view") -local rect = require("ui/rect") -local event = require("ui/event") -local point = require("ui/point") -local curses = require("ui/curses") -local dlist = require("base/dlist") - --- define module -local group = group or view() - --- init group -function group:init(name, bounds) - - -- init view - view.init(self, name, bounds) - - -- mark as group - self:type_set("group") - - -- mark as selectable - self:option_set("selectable", true) - - -- init child views - self._VIEWS = dlist() -end - --- exit group -function group:exit() - - -- exit view - view.exit(self) -end - --- get all child views -function group:views() - return self._VIEWS:items() -end - --- get views count -function group:count() - return self._VIEWS:size() -end - --- is empty? -function group:empty() - return self._VIEWS:empty() -end - --- get the first view -function group:first() - return self._VIEWS:first() -end - --- get the next view -function group:next(v) - return self._VIEWS:next(v) -end - --- get the previous view -function group:prev(v) - return self._VIEWS:prev(v) -end - --- get the current selected child view -function group:current() - return self._CURRENT -end - --- insert view -function group:insert(v, opt) - - -- check - assert(not v:parent() or v:parent() == self) - - -- this view has been inserted into this group? remove it first - if v:parent() == self then - self:remove(v) - end - - -- center this view if centerx or centery are set - local bounds = v:bounds() - local org = point {bounds.sx, bounds.sy} - if opt and opt.centerx then - org.x = math.floor((self:width() - v:width()) / 2) - end - 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) - v:bounds_set(bounds) - - -- insert this view - self._VIEWS:push(v) - - -- set it's parent view - v:parent_set(self) - - -- set application - v:application_set(self:application()) - - -- select this view - if v:option("selectable") then - self:select(v) - end -end - --- remove view -function group:remove(v) - - -- check - assert(v:parent() == self) - - -- lock - self:lock() - - -- hide this view first - v:show(false) - - -- remove view - self._VIEWS:remove(v) - - -- select next view - if self:current() == v then - self._CURRENT = nil - self:select_next() - end - - -- unlock - self:unlock() -end - --- select the child view -function group:select(v) - - -- check - assert(v == nil or (v:parent() == self and v:option("selectable"))) - - -- get the current selected view - local current = self:current() - if v == current then - return - end - - -- undo the previous selected view - if current then - - -- undo the current view first - if self:state("focused") then - current:state_set("focused", false) - end - current:state_set("selected", false) - end - - -- update the current selected view - self._CURRENT = v - - -- update the new selected view - if v then - - -- modify view order and mark this view as top - if v:option("top_select") then - self._VIEWS:remove(v) - self._VIEWS:push(v) - end - - -- select and focus this view - v:state_set('selected', true) - if self:state("focused") then - v:state_set('focused', true) - end - end -end - --- select the next view -function group:select_next(start) - - -- is empty? - if self:empty() then - return - end - - -- get current view - local current = start or self:current() or self:first() - - -- 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 - 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 - --- on event -function group:event_on(e) - - -- is empty views? - if self:empty() then - return - end - - -- send event to all child views - for v in self:views() do - if v:event_need(e) then - v:event_on(e) - end - end -end - --- draw group -function group:draw() - - -- redraw group? - local redraw = self:state("redraw") - - -- draw group background first - if redraw then - view.draw(self) - end - - -- draw all child views - for v in self:views() do - if redraw then - v:state_set("redraw", true) - end - if v:state("visible") and (v:state("redraw") or v:type() == "group") then - v:draw() - end - end -end - --- refresh group -function group:refresh() - - -- need not refresh? do not refresh it - if not self:state("refresh") then - return - end - - -- refresh all child views - for v in self:views() do - if v:state("refresh") then - v:refresh() - v:state_set("refresh", false) - end - end - - -- refresh it - view.refresh(self) - - -- clear mark - self:state_set("refresh", false) -end - --- dump all views -function group:dump() - log:print("%s", self:_tostring(1)) -end - --- tostring(group, level) -function group:_tostring(level) - local str = "" - if self.views then - str = str .. string.format("<%s %s>", self:name(), tostring(self:bounds())) - if not self:empty() then - str = str .. "\n" - end - for v in self:views() do - for l = 1, level do - str = str .. " " - end - str = str .. group._tostring(v, level + 1) .. "\n" - end - else - str = tostring(self) - end - return str -end - --- tostring(group) -function group:__tostring() - return string.format("", self:name(), tostring(self:bounds())) -end - - --- return module -return group diff --git a/xmake/core/ui/menubar.lua b/xmake/core/ui/menubar.lua index 6fdcad24f..ad3f2b4ae 100644 --- a/xmake/core/ui/menubar.lua +++ b/xmake/core/ui/menubar.lua @@ -26,17 +26,17 @@ local log = require("ui/log") local rect = require("ui/rect") local label = require("ui/label") -local group = require("ui/group") +local panel = require("ui/panel") local curses = require("ui/curses") -- define module -local menubar = menubar or group() +local menubar = menubar or panel() -- init menubar function menubar:init(name, bounds) - -- init group - group.init(self, name, bounds) + -- init panel + panel.init(self, name, bounds) -- init title self._TITLE = label:new("menubar.title", rect{0, 0, self:width(), self:height()}) diff --git a/xmake/core/ui/panel.lua b/xmake/core/ui/panel.lua new file mode 100644 index 000000000..a48612b28 --- /dev/null +++ b/xmake/core/ui/panel.lua @@ -0,0 +1,337 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file panel.lua +-- + +-- load modules +local log = require("ui/log") +local view = require("ui/view") +local rect = require("ui/rect") +local event = require("ui/event") +local point = require("ui/point") +local curses = require("ui/curses") +local dlist = require("base/dlist") + +-- define module +local panel = panel or view() + +-- init panel +function panel:init(name, bounds) + + -- init view + view.init(self, name, bounds) + + -- mark as panel + self:type_set("panel") + + -- mark as selectable + self:option_set("selectable", true) + + -- init child views + self._VIEWS = dlist() +end + +-- exit panel +function panel:exit() + + -- exit view + view.exit(self) +end + +-- get all child views +function panel:views() + return self._VIEWS:items() +end + +-- get views count +function panel:count() + return self._VIEWS:size() +end + +-- is empty? +function panel:empty() + return self._VIEWS:empty() +end + +-- get the first view +function panel:first() + return self._VIEWS:first() +end + +-- get the next view +function panel:next(v) + return self._VIEWS:next(v) +end + +-- get the previous view +function panel:prev(v) + return self._VIEWS:prev(v) +end + +-- get the current selected child view +function panel:current() + return self._CURRENT +end + +-- insert view +function panel:insert(v, opt) + + -- check + assert(not v:parent() or v:parent() == self) + + -- this view has been inserted into this panel? remove it first + if v:parent() == self then + self:remove(v) + end + + -- center this view if centerx or centery are set + local bounds = v:bounds() + local org = point {bounds.sx, bounds.sy} + if opt and opt.centerx then + org.x = math.floor((self:width() - v:width()) / 2) + end + 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) + v:bounds_set(bounds) + + -- insert this view + self._VIEWS:push(v) + + -- set it's parent view + v:parent_set(self) + + -- set application + v:application_set(self:application()) + + -- select this view + if v:option("selectable") then + self:select(v) + end +end + +-- remove view +function panel:remove(v) + + -- check + assert(v:parent() == self) + + -- lock + self:lock() + + -- hide this view first + v:show(false) + + -- remove view + self._VIEWS:remove(v) + + -- select next view + if self:current() == v then + self._CURRENT = nil + self:select_next() + end + + -- unlock + self:unlock() +end + +-- select the child view +function panel:select(v) + + -- check + assert(v == nil or (v:parent() == self and v:option("selectable"))) + + -- get the current selected view + local current = self:current() + if v == current then + return + end + + -- undo the previous selected view + if current then + + -- undo the current view first + if self:state("focused") then + current:state_set("focused", false) + end + current:state_set("selected", false) + end + + -- update the current selected view + self._CURRENT = v + + -- update the new selected view + if v then + + -- modify view order and mark this view as top + if v:option("top_select") then + self._VIEWS:remove(v) + self._VIEWS:push(v) + end + + -- select and focus this view + v:state_set('selected', true) + if self:state("focused") then + v:state_set('focused', true) + end + end +end + +-- select the next view +function panel:select_next(start) + + -- is empty? + if self:empty() then + return + end + + -- get current view + local current = start or self:current() or self:first() + + -- 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 + next = self:next(next) + end +end + +-- select the previous view +function panel: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 + +-- on event +function panel:event_on(e) + + -- is empty views? + if self:empty() then + return + end + + -- send event to all child views + for v in self:views() do + if v:event_need(e) then + v:event_on(e) + end + end +end + +-- draw panel +function panel:draw() + + -- redraw panel? + local redraw = self:state("redraw") + + -- draw panel background first + if redraw then + view.draw(self) + end + + -- draw all child views + for v in self:views() do + if redraw then + v:state_set("redraw", true) + end + if v:state("visible") and (v:state("redraw") or v:type() == "panel") then + v:draw() + end + end +end + +-- refresh panel +function panel:refresh() + + -- need not refresh? do not refresh it + if not self:state("refresh") then + return + end + + -- refresh all child views + for v in self:views() do + if v:state("refresh") then + v:refresh() + v:state_set("refresh", false) + end + end + + -- refresh it + view.refresh(self) + + -- clear mark + self:state_set("refresh", false) +end + +-- dump all views +function panel:dump() + log:print("%s", self:_tostring(1)) +end + +-- tostring(panel, level) +function panel:_tostring(level) + local str = "" + if self.views then + str = str .. string.format("<%s %s>", self:name(), tostring(self:bounds())) + if not self:empty() then + str = str .. "\n" + end + for v in self:views() do + for l = 1, level do + str = str .. " " + end + str = str .. panel._tostring(v, level + 1) .. "\n" + end + else + str = tostring(self) + end + return str +end + +-- tostring(panel) +function panel:__tostring() + return string.format("", self:name(), tostring(self:bounds())) +end + + +-- return module +return panel diff --git a/xmake/core/ui/program.lua b/xmake/core/ui/program.lua index 014168ef3..0d1bed84f 100644 --- a/xmake/core/ui/program.lua +++ b/xmake/core/ui/program.lua @@ -31,12 +31,12 @@ $Id: program.lua 18 2007-06-21 20:43:52Z tngd $ local log = require("ui/log") local rect = require("ui/rect") local point = require("ui/point") -local group = require("ui/group") +local panel = require("ui/panel") local event = require("ui/event") local curses = require("ui/curses") -- define module -local program = program or group() +local program = program or panel() -- init program function program:init(name) @@ -78,15 +78,15 @@ function program:init(name) -- get 8-bits character for getch() main_window:meta(true) - -- init group - group.init(self, name, rect {0, 0, curses.columns(), curses.lines()}) + -- init panel + panel.init(self, name, rect {0, 0, curses.columns(), curses.lines()}) end -- exit program function program:exit() - -- exit group - group.exit(self) + -- exit panel + panel.exit(self) -- (attempt to) make sure the screen will be cleared -- if not restored by the curses driver @@ -212,7 +212,7 @@ function program:refresh() end -- refresh views - group.refresh(self) + panel.refresh(self) -- trace log:print("%s: refresh ..", self) @@ -369,7 +369,7 @@ function program:_refresh_cursor() -- get the top focused view local focused_view = self - while focused_view:type() == "group" and focused_view:current() do + while focused_view:type() == "panel" and focused_view:current() do focused_view = focused_view:current() end diff --git a/xmake/core/ui/statusbar.lua b/xmake/core/ui/statusbar.lua index c0e0814dc..ba4206958 100644 --- a/xmake/core/ui/statusbar.lua +++ b/xmake/core/ui/statusbar.lua @@ -25,19 +25,19 @@ -- load modules local log = require("ui/log") local rect = require("ui/rect") -local group = require("ui/group") +local panel = require("ui/panel") local label = require("ui/label") local event = require("ui/event") local curses = require("ui/curses") -- define module -local statusbar = statusbar or group() +local statusbar = statusbar or panel() -- init statusbar function statusbar:init(name, bounds) - -- init group - group.init(self, name, bounds) + -- init panel + panel.init(self, name, bounds) -- init info self._INFO = label:new("statusbar.info", rect{0, 0, self:width(), self:height()}) diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua index 5b8449641..3312a3f50 100644 --- a/xmake/core/ui/view.lua +++ b/xmake/core/ui/view.lua @@ -60,7 +60,7 @@ function view:init(name, bounds) state.visible = true -- view visibility state.cursor_visible = false -- cursor visibility state.block_cursor = false -- block cursor - state.selected = false -- current selected window inside group + state.selected = false -- current selected window inside panel state.focused = false -- true if parent is also focused state.redraw = true -- need redraw state.refresh = true -- need refresh -- cgit v1.3.1