improve textdialog
This commit is contained in:
@@ -40,7 +40,6 @@ function boxdialog:init(name, bounds, title)
|
||||
self:text():bounds().ey = self._TEXT_EY
|
||||
self:text():invalidate(true)
|
||||
self:text():option_set("selectable", false)
|
||||
self:text():option_set("scrollable", false)
|
||||
|
||||
-- insert box
|
||||
self:panel():insert(self:box())
|
||||
|
@@ -45,7 +45,6 @@ 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("scrollable", false)
|
||||
|
||||
-- text changed
|
||||
self:text():action_set(action.ac_on_text_changed, function (v)
|
||||
|
@@ -122,6 +122,7 @@ function mconfdialog:helpdialog()
|
||||
if not self._HELPDIALOG then
|
||||
local helpdialog = textdialog:new("mconfdialog.help", self:bounds(), "help")
|
||||
helpdialog:button_add("exit", "< Exit >", function (v) helpdialog:quit() end)
|
||||
helpdialog:option_set("scrollable", true)
|
||||
self._HELPDIALOG = helpdialog
|
||||
end
|
||||
return self._HELPDIALOG
|
||||
@@ -132,6 +133,7 @@ function mconfdialog:resultdialog()
|
||||
if not self._RESULTDIALOG then
|
||||
local resultdialog = textdialog:new("mconfdialog.result", self:bounds(), "result")
|
||||
resultdialog:button_add("exit", "< Exit >", function (v) resultdialog:quit() end)
|
||||
resultdialog:option_set("scrollable", true)
|
||||
self._RESULTDIALOG = resultdialog
|
||||
end
|
||||
return self._RESULTDIALOG
|
||||
|
@@ -35,7 +35,7 @@ function scrollbar:init(name, bounds, vertical)
|
||||
view.init(self, name, bounds)
|
||||
|
||||
-- init bar attribute
|
||||
self:charattr_set("black")
|
||||
self:charattr_set("black on black")
|
||||
|
||||
-- init bar vertical
|
||||
self:vertical_set(vertical)
|
||||
@@ -165,14 +165,18 @@ function scrollbar:on_draw(transparent)
|
||||
if self:vertical() then
|
||||
local sb = math.floor(self:height() * pb)
|
||||
local se = math.ceil(self:height() * pe)
|
||||
if se > sb and se - sb < self:height() then
|
||||
self:canvas():attr(charattr):move(0, sb):putchar(char, se - sb, true)
|
||||
if se > sb and se - sb <= self:height() then
|
||||
for x = 0, self:width() - 1 do
|
||||
self:canvas():attr(charattr):move(x, sb):putchar(char, se - sb, true)
|
||||
end
|
||||
end
|
||||
else
|
||||
local sb = math.floor(self:width() * pb)
|
||||
local se = math.ceil(self:width() * pe)
|
||||
if se > sb and se - sb < self:width() then
|
||||
self:canvas():attr(charattr):move(sb, 0):putchar(char, se - sb)
|
||||
if se > sb and se - sb <= self:width() then
|
||||
for y = 0, self:height() - 1 do
|
||||
self:canvas():attr(charattr):move(sb, y):putchar(char, se - sb)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -25,7 +25,6 @@ local label = require("ltui/label")
|
||||
local event = require("ltui/event")
|
||||
local curses = require("ltui/curses")
|
||||
local action = require("ltui/action")
|
||||
local scrollbar = require("ltui/scrollbar")
|
||||
|
||||
-- define module
|
||||
local textarea = textarea or label()
|
||||
@@ -39,9 +38,6 @@ function textarea:init(name, bounds, text)
|
||||
-- mark as selectable
|
||||
self:option_set("selectable", true)
|
||||
|
||||
-- mark as scrollable
|
||||
self:option_set("scrollable", true)
|
||||
|
||||
-- init start line
|
||||
self._STARTLINE = 0
|
||||
self._LINECOUNT = 0
|
||||
@@ -61,17 +57,6 @@ function textarea:on_draw(transparent)
|
||||
if strs and #strs > 0 and textattr then
|
||||
self:canvas():attr(textattr):move(0, 0):putstrs(strs, self._STARTLINE + 1)
|
||||
end
|
||||
|
||||
-- draw scrollable
|
||||
if self:option("scrollable") then
|
||||
local tb = self._STARTLINE
|
||||
local fator = self:height() / self._LINECOUNT
|
||||
local sb = math.min(math.floor(tb * fator), self:height() - 1)
|
||||
local se = math.min(sb + math.ceil(self:height() * fator), self:height())
|
||||
if se > sb and se - sb < self:height() then
|
||||
self:canvas():attr("black"):move(self:width() - 1, sb):putchar(' ', se - sb, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- set text
|
||||
|
@@ -19,13 +19,14 @@
|
||||
--
|
||||
|
||||
-- load modules
|
||||
local log = require("ltui/base/log")
|
||||
local rect = require("ltui/rect")
|
||||
local event = require("ltui/event")
|
||||
local dialog = require("ltui/dialog")
|
||||
local curses = require("ltui/curses")
|
||||
local textarea = require("ltui/textarea")
|
||||
local action = require("ltui/action")
|
||||
local log = require("ltui/base/log")
|
||||
local rect = require("ltui/rect")
|
||||
local event = require("ltui/event")
|
||||
local dialog = require("ltui/dialog")
|
||||
local curses = require("ltui/curses")
|
||||
local textarea = require("ltui/textarea")
|
||||
local scrollbar = require("ltui/scrollbar")
|
||||
local action = require("ltui/action")
|
||||
|
||||
-- define module
|
||||
local textdialog = textdialog or dialog()
|
||||
@@ -36,9 +37,15 @@ function textdialog:init(name, bounds, title)
|
||||
-- init window
|
||||
dialog.init(self, name, bounds, title)
|
||||
|
||||
-- mark as scrollable, disabled by default
|
||||
self:option_set("scrollable", false)
|
||||
|
||||
-- insert text
|
||||
self:panel():insert(self:text())
|
||||
|
||||
-- insert scrollbar
|
||||
self:panel():insert(self:scrollbar())
|
||||
|
||||
-- select buttons by default
|
||||
self:panel():select(self:buttons())
|
||||
|
||||
@@ -48,6 +55,24 @@ function textdialog:init(name, bounds, title)
|
||||
end)
|
||||
end
|
||||
|
||||
-- enable or disable scrollbar
|
||||
function textdialog:option_set(name, value)
|
||||
if name == "scrollable" then
|
||||
local oldvalue = self:option(name)
|
||||
if value ~= oldvalue then
|
||||
if value then
|
||||
self:text():bounds():resize(self:panel():width() - 1, self:panel():height() - 1)
|
||||
self:scrollbar():show(true)
|
||||
else
|
||||
self:text():bounds():resize(self:panel():width(), self:panel():height() - 1)
|
||||
self:scrollbar():show(false)
|
||||
end
|
||||
self:invalidate()
|
||||
end
|
||||
end
|
||||
dialog.option_set(self, name, value)
|
||||
end
|
||||
|
||||
-- get text
|
||||
function textdialog:text()
|
||||
if not self._TEXT then
|
||||
@@ -56,6 +81,15 @@ function textdialog:text()
|
||||
return self._TEXT
|
||||
end
|
||||
|
||||
-- get scrollbar
|
||||
function textdialog:scrollbar()
|
||||
if not self._SCROLLBAR then
|
||||
self._SCROLLBAR = scrollbar:new("textdialog.scrollbar", rect:new(self:panel():width() - 1, 0, 1, self:panel():height() - 1))
|
||||
self._SCROLLBAR:show(false)
|
||||
end
|
||||
return self._SCROLLBAR
|
||||
end
|
||||
|
||||
-- on event
|
||||
function textdialog:on_event(e)
|
||||
|
||||
|
@@ -47,9 +47,6 @@ function textedit:init(name, bounds, text)
|
||||
self:option_set("mouseable", true)
|
||||
self:action_set(action.ac_on_clicked, function () return true end)
|
||||
|
||||
-- disable scrollbar
|
||||
self:option_set("scrollable", false)
|
||||
|
||||
-- enable multiple line
|
||||
self:option_set("multiline", true)
|
||||
end
|
||||
|
@@ -86,6 +86,7 @@ function demo:dialog_help()
|
||||
dialog_help:text():text_set(helptext)
|
||||
end
|
||||
dialog_help:button_add("exit", "< Exit >", function (v) self:remove(dialog_help) end)
|
||||
dialog_help:option_set("scrollable", true)
|
||||
self._DIALOG_HELP = dialog_help
|
||||
end
|
||||
return dialog_help
|
||||
|
Reference in New Issue
Block a user