improve textdialog
This commit is contained in:
@@ -67,9 +67,14 @@ function textarea:text_set(text)
|
|||||||
return label.text_set(self, text)
|
return label.text_set(self, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- is scrollable?
|
||||||
|
function textarea:scrollable()
|
||||||
|
return self._LINECOUNT > self:height()
|
||||||
|
end
|
||||||
|
|
||||||
-- scroll
|
-- scroll
|
||||||
function textarea:scroll(lines)
|
function textarea:scroll(lines)
|
||||||
if self._LINECOUNT > self:height() then
|
if self:scrollable() then
|
||||||
self._STARTLINE = self._STARTLINE + lines
|
self._STARTLINE = self._STARTLINE + lines
|
||||||
if self._STARTLINE < 0 then
|
if self._STARTLINE < 0 then
|
||||||
self._STARTLINE = 0
|
self._STARTLINE = 0
|
||||||
@@ -85,7 +90,7 @@ end
|
|||||||
|
|
||||||
-- scroll to end
|
-- scroll to end
|
||||||
function textarea:scroll_to_end()
|
function textarea:scroll_to_end()
|
||||||
if self._LINECOUNT > self:height() then
|
if self:scrollable() then
|
||||||
local startline_end = self._LINECOUNT - self:height()
|
local startline_end = self._LINECOUNT - self:height()
|
||||||
self._STARTLINE = startline_end
|
self._STARTLINE = startline_end
|
||||||
self:action_on(action.ac_on_scrolled, self._STARTLINE / startline_end)
|
self:action_on(action.ac_on_scrolled, self._STARTLINE / startline_end)
|
||||||
|
@@ -59,9 +59,22 @@ function textdialog:init(name, bounds, title)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- show scrollbar?
|
||||||
|
self:text():action_set(action.ac_on_text_changed, function (v)
|
||||||
|
if self:option("scrollable") then
|
||||||
|
if v:scrollable() then
|
||||||
|
self:scrollbar():show(true)
|
||||||
|
else
|
||||||
|
self:scrollbar():show(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- on scroll for text and scrollbar
|
-- on scroll for text and scrollbar
|
||||||
self:text():action_set(action.ac_on_scrolled, function (v, progress)
|
self:text():action_set(action.ac_on_scrolled, function (v, progress)
|
||||||
self:scrollbar():progress_set(progress)
|
if self:option("scrollable") then
|
||||||
|
self:scrollbar():progress_set(progress)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -72,12 +85,9 @@ function textdialog:option_set(name, value)
|
|||||||
if value ~= oldvalue then
|
if value ~= oldvalue then
|
||||||
if value then
|
if value then
|
||||||
self:text():bounds():resize(self:panel():width() - 1, self:panel():height() - 1)
|
self:text():bounds():resize(self:panel():width() - 1, self:panel():height() - 1)
|
||||||
self:scrollbar():show(true)
|
|
||||||
else
|
else
|
||||||
self:text():bounds():resize(self:panel():width(), self:panel():height() - 1)
|
self:text():bounds():resize(self:panel():width(), self:panel():height() - 1)
|
||||||
self:scrollbar():show(false)
|
|
||||||
end
|
end
|
||||||
self:invalidate()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
dialog.option_set(self, name, value)
|
dialog.option_set(self, name, value)
|
||||||
|
@@ -76,6 +76,7 @@ function demo:dialog_help()
|
|||||||
local dialog_help = self._DIALOG_HELP
|
local dialog_help = self._DIALOG_HELP
|
||||||
if not dialog_help then
|
if not dialog_help then
|
||||||
dialog_help = textdialog:new("dialog.help", rect {1, 1, self:width() - 1, self:height() - 1}, "README")
|
dialog_help = textdialog:new("dialog.help", rect {1, 1, self:width() - 1, self:height() - 1}, "README")
|
||||||
|
dialog_help:option_set("scrollable", true)
|
||||||
local helptext = nil
|
local helptext = nil
|
||||||
local file = io.open("./LICENSE.md", 'r')
|
local file = io.open("./LICENSE.md", 'r')
|
||||||
if file then
|
if file then
|
||||||
@@ -86,7 +87,6 @@ function demo:dialog_help()
|
|||||||
dialog_help:text():text_set(helptext)
|
dialog_help:text():text_set(helptext)
|
||||||
end
|
end
|
||||||
dialog_help:button_add("exit", "< Exit >", function (v) self:remove(dialog_help) 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
|
self._DIALOG_HELP = dialog_help
|
||||||
end
|
end
|
||||||
return dialog_help
|
return dialog_help
|
||||||
|
Reference in New Issue
Block a user