diff options
| author | ruki <[email protected]> | 2018-01-02 00:43:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-01-01 22:21:14 +0800 |
| commit | 827f07629755347bed82cb51bc1735b2984e284c (patch) | |
| tree | 7a69d659d67281211df0da854d60c3d53e253b71 | |
| parent | 1bf42f883ad6c68ebc48c2b574233fb0fb27aecf (diff) | |
add window
| -rw-r--r-- | tests/ui/desktop.lua (renamed from tests/ui/hello.lua) | 21 | ||||
| -rw-r--r-- | tests/ui/window.lua | 53 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/window.lua | 26 | ||||
| -rw-r--r-- | xmake/core/ui/application.lua | 10 | ||||
| -rw-r--r-- | xmake/core/ui/menubar.lua | 3 | ||||
| -rw-r--r-- | xmake/core/ui/panel.lua | 13 | ||||
| -rw-r--r-- | xmake/core/ui/window.lua | 58 |
7 files changed, 153 insertions, 31 deletions
diff --git a/tests/ui/hello.lua b/tests/ui/desktop.lua index 223ab8094..48539a14f 100644 --- a/tests/ui/hello.lua +++ b/tests/ui/desktop.lua @@ -19,7 +19,7 @@ -- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- -- @author ruki --- @file hello.lua +-- @file desktop.lua -- -- imports @@ -31,14 +31,19 @@ import("core.ui.event") import("core.ui.button") import("core.ui.application") --- the hello application -local hello = application() +-- the demo application +local demo = application() --- init hello -function hello:init() +-- init demo +function demo:init() -- init name - application.init(self, "hello") + application.init(self, "demo") + + -- show desktop, menubar and statusbar + self:insert(self:desktop()) + self:insert(self:menubar()) + self:insert(self:statusbar()) -- init title self:menubar():title():text_set("Menu Bar (Hello)") @@ -54,7 +59,7 @@ function hello:init() end -- on event -function hello:event_on(e) +function demo:event_on(e) if view.event_on(self, e) then return true end @@ -74,5 +79,5 @@ end -- main entry function main(...) - hello:run(...) + demo:run(...) end diff --git a/tests/ui/window.lua b/tests/ui/window.lua new file mode 100644 index 000000000..9eabd5cd6 --- /dev/null +++ b/tests/ui/window.lua @@ -0,0 +1,53 @@ +--!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 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file window.lua +-- + +-- imports +import("core.ui.log") +import("core.ui.rect") +import("core.ui.view") +import("core.ui.label") +import("core.ui.event") +import("core.ui.window") +import("core.ui.application") + +-- the demo application +local demo = application() + +-- init demo +function demo:init() + + -- init name + application.init(self, "demo") + + -- init background + self:background_set("blue") + + -- init main window + self:insert(window:new("window.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main window")) +end + +-- main entry +function main(...) + demo:run(...) +end diff --git a/xmake/core/sandbox/modules/import/core/ui/window.lua b/xmake/core/sandbox/modules/import/core/ui/window.lua new file mode 100644 index 000000000..b04042b81 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/window.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 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file window.lua +-- + +-- return module: window +return require("ui/window") diff --git a/xmake/core/ui/application.lua b/xmake/core/ui/application.lua index 0354ecb07..aca6a2297 100644 --- a/xmake/core/ui/application.lua +++ b/xmake/core/ui/application.lua @@ -22,11 +22,6 @@ -- @file application.lua -- ---[[ Console User Interface (cui) ]----------------------------------------- -Author: Tiago Dionizio (tiago.dionizio AT gmail.com) -$Id: application.lua 18 2007-06-21 20:43:52Z tngd $ ---------------------------------------------------------------------------]] - -- load modules local os = require("base/os") local log = require("ui/log") @@ -57,11 +52,6 @@ function application:init(name) -- save application self:application_set(self) - -- add menubar, statusbar and desktop - self:insert(self:statusbar()) - self:insert(self:menubar()) - self:insert(self:desktop()) - -- trace log:print("<application: %s>: init ok", name) end diff --git a/xmake/core/ui/menubar.lua b/xmake/core/ui/menubar.lua index d880703ef..0ac28c414 100644 --- a/xmake/core/ui/menubar.lua +++ b/xmake/core/ui/menubar.lua @@ -39,9 +39,8 @@ function menubar:init(name, bounds) panel.init(self, name, bounds) -- init title - self._TITLE = label:new("menubar.title", rect{0, 0, self:width(), self:height()}) + self._TITLE = label:new("menubar.title", rect{0, 0, self:width(), self:height()}, "Menu Bar") self:insert(self:title()) - self:title():text_set("Menu Bar") self:title():textattr_set("red") -- init background diff --git a/xmake/core/ui/panel.lua b/xmake/core/ui/panel.lua index a13c29889..d9a6f8c4c 100644 --- a/xmake/core/ui/panel.lua +++ b/xmake/core/ui/panel.lua @@ -129,12 +129,6 @@ 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) @@ -143,9 +137,6 @@ function panel:remove(v) self._CURRENT = nil self:select_next() end - - -- unlock - self:unlock() end -- select the child view @@ -203,7 +194,7 @@ function panel:select_next(start) -- select the next view local next = self:next(current) - while next ~= current do + while next and next ~= current do if next:option("selectable") and next:state("visible") then self:select(next) break @@ -225,7 +216,7 @@ function panel:select_prev(start) -- select the previous view local prev = self:prev(current) - while prev ~= current do + while prev and prev ~= current do if prev:option("selectable") and prev:state("visible") then self:select(prev) break diff --git a/xmake/core/ui/window.lua b/xmake/core/ui/window.lua new file mode 100644 index 000000000..b782a1f38 --- /dev/null +++ b/xmake/core/ui/window.lua @@ -0,0 +1,58 @@ +--!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 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file window.lua +-- + +-- load modules +local log = require("ui/log") +local rect = require("ui/rect") +local label = require("ui/label") +local panel = require("ui/panel") +local curses = require("ui/curses") + +-- define module +local window = window or panel() + +-- init window +function window:init(name, bounds, title) + + -- init panel + panel.init(self, name, bounds) + + -- init background + self:background_set("white") + + -- init title + if title then + self._TITLE = label:new("window.title", rect{0, 0, #title, 1}, title) + self:insert(self:title(), {centerx = true}) + self:title():textattr_set("blue bold") + end +end + +-- get title +function window:title() + return self._TITLE +end + +-- return module +return window |
