diff options
| author | ruki <[email protected]> | 2017-12-23 00:46:33 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-22 22:39:18 +0800 |
| commit | 8e249fefd8265911fe4fe8ef72e489cbc8e326eb (patch) | |
| tree | 39c8fa6e7b2bdb74a5bd98d77900849fab739061 /xmake/core/ui/label.lua | |
| parent | 9e2b084be73bc0b966c2c43f73403703d64b7228 (diff) | |
import some ui modules
Diffstat (limited to 'xmake/core/ui/label.lua')
| -rw-r--r-- | xmake/core/ui/label.lua | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/xmake/core/ui/label.lua b/xmake/core/ui/label.lua new file mode 100644 index 000000000..57a287cb5 --- /dev/null +++ b/xmake/core/ui/label.lua @@ -0,0 +1,75 @@ +--!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 label.lua +-- + +-- load modules +local log = require("ui/log") +local view = require("ui/view") +local curses = require("ui/curses") + +-- define module +local label = label or view() + +-- init label +function label:init(name, bounds, text) + + -- init view + view.init(self, name, bounds) + + -- init text + self._TEXT = text or "" + + -- init color + self:attr_set("color", curses.color_pair("red", "white")) +end + +-- exit label +function label:exit() + view.exit(self) +end + +-- draw view +function label:draw() + + -- trace + log:print("%s: draw ..", self) + + -- draw it + local c = self:canvas() + local s = string.sub(self:text(), 1, self:width()) .. string.rep(' ', self:width() - #self:text()) + c:attr(self:attr("color")):move(0, 0):write(s, self:attr("color")) +end + +-- get text +function label:text() + return self._TEXT +end + +-- set text +function label:text_set(text) + self._TEXT = text or "" + self:invalidate() +end + +-- return module +return label |
