diff options
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/boxdialog.lua | 26 | ||||
| -rw-r--r-- | xmake/core/ui/boxdialog.lua | 58 | ||||
| -rw-r--r-- | xmake/core/ui/rect.lua | 6 | ||||
| -rw-r--r-- | xmake/core/ui/window.lua | 18 |
4 files changed, 105 insertions, 3 deletions
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 |
