summaryrefslogtreecommitdiff
path: root/xmake/core/ui/border.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-18 23:14:40 +0800
committerruki <[email protected]>2018-01-18 13:28:01 +0800
commit7d42cff795e9600a837fc0e595baa4d76ac0838e (patch)
tree2204f7beacf64ecdb488daea5dfa831ccad3303a /xmake/core/ui/border.lua
parentc4bdc1b82cc058e29eb3dc9ad335fdc6333e465e (diff)
add textedit
Diffstat (limited to 'xmake/core/ui/border.lua')
-rw-r--r--xmake/core/ui/border.lua104
1 files changed, 104 insertions, 0 deletions
diff --git a/xmake/core/ui/border.lua b/xmake/core/ui/border.lua
new file mode 100644
index 000000000..6ed001db4
--- /dev/null
+++ b/xmake/core/ui/border.lua
@@ -0,0 +1,104 @@
+--!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 border.lua
+--
+
+-- load modules
+local log = require("ui/log")
+local rect = require("ui/rect")
+local view = require("ui/view")
+local label = require("ui/label")
+local curses = require("ui/curses")
+
+-- define module
+local border = border or view()
+
+-- init border
+function border:init(name, bounds)
+
+ -- init view
+ view.init(self, name, bounds)
+
+ -- check bounds
+ assert(self:width() > 2 and self:height() > 2, string.format("%s: too small!", self))
+end
+
+-- draw border
+function border:draw(transparent)
+
+ -- draw background (transparent)
+ view.draw(self, true)
+
+ -- get corner attribute
+ local cornerattr = self:cornerattr()
+
+ -- the left-upper attribute
+ 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(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 borders (pdcurses), so we use acsii characters instead of them.
+ local iswin = os.host() == "borders"
+ local hline = iswin and '-' or "hline"
+ local vline = iswin and '|' or "vline"
+ local ulcorner = iswin and ' ' or "ulcorner"
+ local llcorner = iswin and ' ' or "llcorner"
+ local urcorner = iswin and ' ' or "urcorner"
+ local lrcorner = iswin and ' ' or "lrcorner"
+
+ -- draw left and top border
+ self:canvas():attr(attr_ul)
+ self:canvas():move(0, 0):putchar(hline, self:width())
+ self:canvas():move(0, 0):putchar(ulcorner)
+ self:canvas():move(0, 1):putchar(vline, self:height() - 1, true)
+ self:canvas():move(0, self:height() - 1):putchar(llcorner)
+
+ -- draw bottom and right border
+ self:canvas():attr(attr_rl)
+ self:canvas():move(1, self:height() - 1):putchar(hline, self:width() - 1)
+ self:canvas():move(self:width() - 1, 0):putchar(urcorner)
+ 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
+
+-- get border corner attribute
+function border:cornerattr()
+ return self._CORNERATTR or {"white", "black"}
+end
+
+-- set border corner attribute
+function border:cornerattr_set(attr_ul, attr_rl)
+ self._CORNERATTR = {attr_ul or "white", attr_rl or attr_ul or "black"}
+ self:invalidate()
+end
+
+
+-- return module
+return border