summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-13 00:28:57 +0800
committerruki <[email protected]>2018-01-12 20:53:47 +0800
commitbcb58d536cb131be4358d8893cfd1db77f72d942 (patch)
treedc283ebaf56f2f6f8555f0c030275dd17ed9c024
parent5d8d758fa2fb4a8e9691dae010b97725c6b736c0 (diff)
add box dialog
-rw-r--r--tests/ui/dialog.lua5
-rw-r--r--xmake/core/sandbox/modules/import/core/ui/boxdialog.lua26
-rw-r--r--xmake/core/ui/boxdialog.lua58
-rw-r--r--xmake/core/ui/rect.lua6
-rw-r--r--xmake/core/ui/window.lua18
5 files changed, 108 insertions, 5 deletions
diff --git a/tests/ui/dialog.lua b/tests/ui/dialog.lua
index 14552d1cb..dcdb0ff4a 100644
--- a/tests/ui/dialog.lua
+++ b/tests/ui/dialog.lua
@@ -28,6 +28,7 @@ import("core.ui.rect")
import("core.ui.view")
import("core.ui.label")
import("core.ui.event")
+import("core.ui.boxdialog")
import("core.ui.textdialog")
import("core.ui.application")
@@ -44,7 +45,7 @@ function demo:init()
self:background_set("blue")
-- init main dialog
- local dialog_main = textdialog:new("dialog.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main dialog")
+ local dialog_main = boxdialog:new("dialog.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main dialog")
dialog_main:text():text_set([[xmake is a cross-platform build utility based on lua.
The project focuses on making development and building easier and provides many features (.e.g package, install, plugin, macro, action, option, task ...), so that any developer can quickly pick it up and enjoy the productivity boost when developing and building project.]])
@@ -56,7 +57,7 @@ The project focuses on making development and building easier and provides many
-- init hello dialog
local dialog_hello = textdialog:new("dialog.hello", rect {0, 0, self:width() / 2, self:height() / 4}):background_set(dialog_main:frame():background())
- dialog_hello:frame():background_set("green")
+ dialog_hello:frame():background_set("cyan")
dialog_hello:text():text_set("hello xmake! (http://xmake.io)\nA cross-platform build utility based on Lua"):textattr_set("red")
dialog_hello:button_add("yes", "< Yes >", "cm_yes")
dialog_hello:button_add("no", "< No >", "cm_no")
diff --git a/xmake/core/sandbox/modules/import/core/ui/boxdialog.lua b/xmake/core/sandbox/modules/import/core/ui/boxdialog.lua
new file mode 100644
index 000000000..a229151e5
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/ui/boxdialog.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 boxdialog.lua
+--
+
+-- return module: boxdialog
+return require("ui/boxdialog")
diff --git a/xmake/core/ui/boxdialog.lua b/xmake/core/ui/boxdialog.lua
new file mode 100644
index 000000000..74b32b685
--- /dev/null
+++ b/xmake/core/ui/boxdialog.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 boxdialog.lua
+--
+
+-- load modules
+local log = require("ui/log")
+local rect = require("ui/rect")
+local curses = require("ui/curses")
+local window = require("ui/window")
+local textdialog = require("ui/textdialog")
+
+-- define module
+local boxdialog = boxdialog or textdialog()
+
+-- init dialog
+function boxdialog:init(name, bounds, title)
+
+ -- init window
+ textdialog.init(self, name, bounds, title)
+
+ -- insert box
+ self:panel():insert(self:box())
+
+ -- resize text bounds
+ self:text():bounds():resize(self:panel():width(), math.floor(self:panel():height() / 4))
+end
+
+-- get box
+function boxdialog:box()
+ if not self._BOX then
+ self._BOX = window:new("boxdialog.box", rect{0, math.floor(self:panel():height() / 4), self:panel():width(), self:panel():height() - 1})
+ self._BOX:border():cornerattr_set("black", "white")
+ end
+ return self._BOX
+end
+
+-- return module
+return boxdialog
diff --git a/xmake/core/ui/rect.lua b/xmake/core/ui/rect.lua
index c10d54377..4e91ff702 100644
--- a/xmake/core/ui/rect.lua
+++ b/xmake/core/ui/rect.lua
@@ -45,6 +45,12 @@ function rect:size()
return point { self.ex - self.sx, self.ey - self.sy }
end
+-- resize rect
+function rect:resize(w, h)
+ self.ex = self.sx + w
+ self.ey = self.sy + h
+end
+
-- move rect
function rect:move(dx, dy)
self.sx = self.sx + dx
diff --git a/xmake/core/ui/window.lua b/xmake/core/ui/window.lua
index 0a5b56783..d29d57e47 100644
--- a/xmake/core/ui/window.lua
+++ b/xmake/core/ui/window.lua
@@ -101,14 +101,20 @@ function window:border()
local border = view:new("window.border", self:frame():bounds())
function border:draw()
+ -- get corner attribute
+ local cornerattr = self:cornerattr()
+
-- the left-upper attribute
- local attr_ul = curses.color_pair("white", self:background())
- if self:background() == "white" then
+ local attr_ul = curses.color_pair(cornerattr[1], self:background())
+ if self:background() == cornerattr[1] then
attr_ul = {attr_ul, "standout"}
end
-- the right-lower attribute
- local attr_rl = curses.color_pair("black", self:background())
+ local attr_rl = curses.color_pair(cornerattr[2], self:background())
+ if self:background() == cornerattr[2] then
+ attr_rl = {attr_rl, "standout"}
+ end
-- the border characters
-- @note acs character will use 2 width on windows (pdcurses), so we use acsii characters instead of them.
@@ -134,6 +140,12 @@ function window:border()
self:canvas():move(self:width() - 1, 1):putchar(vline, self:height() - 1, true)
self:canvas():move(self:width() - 1, self:height() - 1):putchar(lrcorner)
end
+ function border:cornerattr()
+ return self._CORNERATTR or {"white", "black"}
+ end
+ function border:cornerattr_set(attr_ul, attr_rl)
+ self._CORNERATTR = {attr_ul or "white", attr_rl or attr_ul or "black"}
+ end
self._BORDER = border
end
return self._BORDER