summaryrefslogtreecommitdiff
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
parentc4bdc1b82cc058e29eb3dc9ad335fdc6333e465e (diff)
add textedit
-rw-r--r--tests/ui/dialog.lua33
-rw-r--r--xmake/core/sandbox/modules/import/core/ui/border.lua26
-rw-r--r--xmake/core/sandbox/modules/import/core/ui/inputdialog.lua26
-rw-r--r--xmake/core/sandbox/modules/import/core/ui/textedit.lua26
-rw-r--r--xmake/core/ui/border.lua104
-rw-r--r--xmake/core/ui/inputdialog.lua60
-rw-r--r--xmake/core/ui/textarea.lua5
-rw-r--r--xmake/core/ui/textedit.lua80
-rw-r--r--xmake/core/ui/window.lua54
9 files changed, 352 insertions, 62 deletions
diff --git a/tests/ui/dialog.lua b/tests/ui/dialog.lua
index f662625dc..9e4d601c1 100644
--- a/tests/ui/dialog.lua
+++ b/tests/ui/dialog.lua
@@ -30,6 +30,7 @@ import("core.ui.label")
import("core.ui.event")
import("core.ui.boxdialog")
import("core.ui.textdialog")
+import("core.ui.inputdialog")
import("core.ui.application")
-- the demo application
@@ -52,19 +53,33 @@ function demo:init()
-- init 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("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.")
- dialog_main:button_add("ok", "< OK >", function (v, e) self:view("dialog.hello"):show(true, {focused = true}) end)
- dialog_main:button_add("cancel", "< Cancel >", "cm_cancel")
+ dialog_main:button_add("tips", "< Tips >", function (v, e) self:view("dialog.tips"):show(true, {focused = true}) end)
+ dialog_main:button_add("input", "< Input >", function (v, e) self:view("dialog.input"):show(true, {focused = true}) end)
dialog_main:button_add("help", "< Help >", function (v, e) self:insert(dialog_help) end)
dialog_main:button_add("quit", "< Quit >", "cm_quit")
self:insert(dialog_main)
- -- init hello dialog
- local dialog_hello = textdialog:new("dialog.hello", rect {0, 0, 50, 8}):background_set(dialog_main:frame():background())
- 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 >", function (v, e) dialog_hello:show(false) end)
- dialog_hello:button_add("no", "< No >", function (v, e) dialog_hello:show(false) end)
- self:insert(dialog_hello, {centerx = true, centery = true})
+ -- init tips dialog
+ local dialog_tips = textdialog:new("dialog.tips", rect {0, 0, 50, 8}):background_set(dialog_main:frame():background())
+ dialog_tips:frame():background_set("cyan")
+ dialog_tips:text():text_set("hello xmake! (http://xmake.io)\nA cross-platform build utility based on Lua"):textattr_set("red")
+ dialog_tips:button_add("yes", "< Yes >", function (v, e) dialog_tips:show(false) end)
+ dialog_tips:button_add("no", "< No >", function (v, e) dialog_tips:show(false) end)
+ self:insert(dialog_tips, {centerx = true, centery = true})
+
+ -- init input dialog
+ local dialog_input = inputdialog:new("dialog.input", rect {0, 0, 50, 8}):background_set(dialog_main:frame():background())
+ dialog_input:frame():background_set("cyan")
+ dialog_input:text():text_set("please input text:"):textattr_set("red")
+ dialog_input:button_add("no", "< No >", function (v, e) dialog_input:show(false) end)
+ dialog_input:button_add("yes", "< Yes >", function (v, e)
+ dialog_main:text():text_set(dialog_input:textedit():text())
+ dialog_input:show(false)
+ end)
+ self:insert(dialog_input, {centerx = true, centery = true})
+
+ -- TODO
+-- dialog_input:show(false)
end
-- main entry
diff --git a/xmake/core/sandbox/modules/import/core/ui/border.lua b/xmake/core/sandbox/modules/import/core/ui/border.lua
new file mode 100644
index 000000000..46e4fd824
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/ui/border.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 border.lua
+--
+
+-- return module: border
+return require("ui/border")
diff --git a/xmake/core/sandbox/modules/import/core/ui/inputdialog.lua b/xmake/core/sandbox/modules/import/core/ui/inputdialog.lua
new file mode 100644
index 000000000..9a888c324
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/ui/inputdialog.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 inputdialog.lua
+--
+
+-- return module: inputdialog
+return require("ui/inputdialog")
diff --git a/xmake/core/sandbox/modules/import/core/ui/textedit.lua b/xmake/core/sandbox/modules/import/core/ui/textedit.lua
new file mode 100644
index 000000000..a9ebd3885
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/ui/textedit.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 textedit.lua
+--
+
+-- return module: textedit
+return require("ui/textedit")
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
diff --git a/xmake/core/ui/inputdialog.lua b/xmake/core/ui/inputdialog.lua
new file mode 100644
index 000000000..349dc131c
--- /dev/null
+++ b/xmake/core/ui/inputdialog.lua
@@ -0,0 +1,60 @@
+--!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 inputdialog.lua
+--
+
+-- load modules
+local log = require("ui/log")
+local rect = require("ui/rect")
+local view = require("ui/view")
+local curses = require("ui/curses")
+local window = require("ui/window")
+local textedit = require("ui/textedit")
+local textdialog = require("ui/textdialog")
+
+-- define module
+local inputdialog = inputdialog or textdialog()
+
+-- init dialog
+function inputdialog:init(name, bounds, title)
+
+ -- init window
+ textdialog.init(self, name, bounds, title)
+
+ -- insert textedit
+ self:panel():insert(self:textedit())
+
+ -- resize text
+ self:text():bounds().ey = 1
+ self:text():invalidate(true)
+end
+
+-- get textedit
+function inputdialog:textedit()
+ if not self._TEXTEDIT then
+ self._TEXTEDIT = textedit:new("inputdialog.textedit", rect{0, 1, self:panel():width(), self:panel():height() - 1})
+ end
+ return self._TEXTEDIT
+end
+
+-- return module
+return inputdialog
diff --git a/xmake/core/ui/textarea.lua b/xmake/core/ui/textarea.lua
index fe9f6c083..4ef3bd878 100644
--- a/xmake/core/ui/textarea.lua
+++ b/xmake/core/ui/textarea.lua
@@ -83,14 +83,17 @@ function textarea:event_on(e)
if self._STARTLINE < 0 then
self._STARTLINE = 0
end
+ self:invalidate()
+ return true
elseif e.key_name == "Down" then
self._STARTLINE = self._STARTLINE + 5
if self._LINECOUNT - self._STARTLINE < self:height() then
self._STARTLINE = self._LINECOUNT - self:height()
end
+ self:invalidate()
+ return true
end
end
- self:invalidate()
end
-- return module
diff --git a/xmake/core/ui/textedit.lua b/xmake/core/ui/textedit.lua
new file mode 100644
index 000000000..f00c8e888
--- /dev/null
+++ b/xmake/core/ui/textedit.lua
@@ -0,0 +1,80 @@
+--!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 textedit.lua
+--
+
+-- load modules
+local log = require("ui/log")
+local view = require("ui/view")
+local label = require("ui/label")
+local event = require("ui/event")
+local border = require("ui/border")
+local curses = require("ui/curses")
+
+-- define module
+local textedit = textedit or label()
+
+-- init textedit
+function textedit:init(name, bounds, text)
+
+ -- init label
+ label.init(self, name, bounds, text)
+
+ -- show cursor
+ self:cursor_show(true)
+
+ -- mark as selectable
+ self:option_set("selectable", true)
+end
+
+-- draw textedit
+function textedit:draw(transparent)
+
+ -- draw label
+ label.draw(self, transparent)
+
+ -- TODO
+ -- move cursor
+ local x, y = self:canvas():pos()
+ self:cursor_move(x, y)
+end
+
+-- on event
+function textedit:event_on(e)
+
+ -- update text
+ if e.type == event.ev_keyboard then
+ if e.key_code > 0x1f and e.key_code < 0x7f then
+ self:text_set(self:text() .. e.key_name)
+ elseif e.key_name == "Enter" then
+ self:text_set(self:text() .. '\n')
+ elseif e.key_name == "Backspace" then
+ local text = self:text()
+ if #text > 0 then
+ self:text_set(text:sub(1, #text - 1))
+ end
+ end
+ end
+end
+
+-- return module
+return textedit
diff --git a/xmake/core/ui/window.lua b/xmake/core/ui/window.lua
index eb66eeeb3..7040c6e26 100644
--- a/xmake/core/ui/window.lua
+++ b/xmake/core/ui/window.lua
@@ -28,6 +28,7 @@ local rect = require("ui/rect")
local view = require("ui/view")
local label = require("ui/label")
local panel = require("ui/panel")
+local border = require("ui/border")
local curses = require("ui/curses")
-- define module
@@ -100,58 +101,7 @@ end
-- get border
function window:border()
if not self._BORDER then
- local border = view:new("window.border", self:frame():bounds())
- 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 windows (pdcurses), so we use acsii characters instead of them.
- local iswin = os.host() == "windows"
- 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
- 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
+ self._BORDER = border:new("window.border", self:frame():bounds())
end
return self._BORDER
end