summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-20 00:45:29 +0800
committerruki <[email protected]>2018-01-19 22:32:58 +0800
commitba7696ff7174d8d07e6aec4138b9cce5f0952ca4 (patch)
treeef52c41eca271695dad3c802efc8be8c0bdf8b8a
parent35ca390ac845a86c78e34059946207f8f980ed5e (diff)
add text changed
-rw-r--r--xmake/core/ui/boxdialog.lua14
-rw-r--r--xmake/core/ui/event.lua7
-rw-r--r--xmake/core/ui/inputdialog.lua14
-rw-r--r--xmake/core/ui/label.lua10
4 files changed, 42 insertions, 3 deletions
diff --git a/xmake/core/ui/boxdialog.lua b/xmake/core/ui/boxdialog.lua
index 92ec704e5..65112e65d 100644
--- a/xmake/core/ui/boxdialog.lua
+++ b/xmake/core/ui/boxdialog.lua
@@ -45,6 +45,20 @@ function boxdialog:init(name, bounds, title)
self:text():bounds().ey = 3
self:text():invalidate(true)
self:text():option_set("selectable", false)
+ self:text():option_set("progress", false)
+
+ -- text changed
+ self:text():action_set("text.changed", function (v, e)
+ if e.text then
+ local lines = #e.text:split('\n', true)
+ if lines > 0 and lines < self:height() then
+ self:box():bounds().sy = lines
+ self:text():bounds().ey = lines
+ self:box():invalidate(true)
+ self:text():invalidate(true)
+ end
+ end
+ end)
-- select buttons by default
self:panel():select(self:buttons())
diff --git a/xmake/core/ui/event.lua b/xmake/core/ui/event.lua
index 411cf9e40..6c7dd7fb0 100644
--- a/xmake/core/ui/event.lua
+++ b/xmake/core/ui/event.lua
@@ -66,8 +66,8 @@ function event:dump()
end
end
--- register event types, event.ev_keyboard = 1, event.ev_mouse = 2, ... , event.ev_idle = 4, event.ev_max = 4
-event:register("ev_max", "ev_keyboard", "ev_mouse", "ev_command", "ev_idle")
+-- register event types, event.ev_keyboard = 1, event.ev_mouse = 2, ... , event.ev_idle = 5, event.ev_max = 5
+event:register("ev_max", "ev_keyboard", "ev_mouse", "ev_command", "ev_text", "ev_idle")
-- register command event types (ev_command)
event:register("cm_max", "cm_quit", "cm_ok", "cm_cancel", "cm_yes", "cm_no", "cm_help")
@@ -83,6 +83,9 @@ event.keyboard = object {_init = { "key_code", "key_name", "key_meta" }, type =
-- define command event
event.command = object {_init = { "command", "extra" }, type = event.ev_command}
+-- define text event
+event.text = object {_init = { "text" }, type = event.ev_text}
+
-- define idle event
event.idle = object {_init = {}, type = event.ev_idle}
diff --git a/xmake/core/ui/inputdialog.lua b/xmake/core/ui/inputdialog.lua
index b91070cb1..dc908bc29 100644
--- a/xmake/core/ui/inputdialog.lua
+++ b/xmake/core/ui/inputdialog.lua
@@ -48,6 +48,20 @@ function inputdialog:init(name, bounds, title)
self:text():bounds().ey = 1
self:text():invalidate(true)
self:text():option_set("selectable", false)
+ self:text():option_set("progress", false)
+
+ -- text changed
+ self:text():action_set("text.changed", function (v, e)
+ if e.text then
+ local lines = #e.text:split('\n', true)
+ if lines > 0 and lines < self:height() then
+ self:text():bounds().ey = lines
+ self:textedit():bounds().sy = lines
+ self:text():invalidate(true)
+ self:textedit():invalidate(true)
+ end
+ end
+ end)
end
-- get textedit
diff --git a/xmake/core/ui/label.lua b/xmake/core/ui/label.lua
index 2615414c1..d2f571c6c 100644
--- a/xmake/core/ui/label.lua
+++ b/xmake/core/ui/label.lua
@@ -25,6 +25,7 @@
-- load modules
local log = require("ui/log")
local view = require("ui/view")
+local event = require("ui/event")
local curses = require("ui/curses")
-- define module
@@ -66,7 +67,14 @@ end
-- set text
function label:text_set(text)
- self._TEXT = text or ""
+ text = text or ""
+ if self._TEXT ~= text then
+ local action = self:action("text.changed")
+ if action then
+ action(self, event.text {text})
+ end
+ end
+ self._TEXT = text
self:invalidate()
return self
end