improve scrollbar
This commit is contained in:
@@ -149,30 +149,30 @@ function scrollbar:on_draw(transparent)
|
|||||||
-- draw background
|
-- draw background
|
||||||
view.on_draw(self, transparent)
|
view.on_draw(self, transparent)
|
||||||
|
|
||||||
-- compute bar range
|
-- draw bar
|
||||||
local char = self:char()
|
local char = self:char()
|
||||||
local charattr = self:charattr_val()
|
local charattr = self:charattr_val()
|
||||||
local progress = self:progress()
|
|
||||||
local stepwidth = self:stepwidth()
|
|
||||||
local pb = progress
|
|
||||||
local pe = progress + stepwidth
|
|
||||||
if pe > 1 then
|
|
||||||
pb = 1 - stepwidth
|
|
||||||
pe = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
-- draw bar
|
|
||||||
if self:vertical() then
|
if self:vertical() then
|
||||||
local sb = math.floor(self:height() * pb)
|
local sn = math.ceil(self:height() * self:stepwidth())
|
||||||
local se = math.ceil(self:height() * pe)
|
local sb = math.floor(self:height() * self:progress())
|
||||||
|
local se = sb + sn
|
||||||
|
if se > self:height() then
|
||||||
|
sb = self:height() - sn
|
||||||
|
se = self:height()
|
||||||
|
end
|
||||||
if se > sb and se - sb <= self:height() then
|
if se > sb and se - sb <= self:height() then
|
||||||
for x = 0, self:width() - 1 do
|
for x = 0, self:width() - 1 do
|
||||||
self:canvas():attr(charattr):move(x, sb):putchar(char, se - sb, true)
|
self:canvas():attr(charattr):move(x, sb):putchar(char, se - sb, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local sb = math.floor(self:width() * pb)
|
local sn = math.ceil(self:width() * self:stepwidth())
|
||||||
local se = math.ceil(self:width() * pe)
|
local sb = math.floor(self:width() * self:progress())
|
||||||
|
local se = sb + sn
|
||||||
|
if se > self:width() then
|
||||||
|
sb = self:width() - sn
|
||||||
|
se = self:width()
|
||||||
|
end
|
||||||
if se > sb and se - sb <= self:width() then
|
if se > sb and se - sb <= self:width() then
|
||||||
for y = 0, self:height() - 1 do
|
for y = 0, self:height() - 1 do
|
||||||
self:canvas():attr(charattr):move(sb, y):putchar(char, se - sb)
|
self:canvas():attr(charattr):move(sb, y):putchar(char, se - sb)
|
||||||
|
@@ -74,9 +74,11 @@ function textarea:scroll(lines)
|
|||||||
if self._STARTLINE < 0 then
|
if self._STARTLINE < 0 then
|
||||||
self._STARTLINE = 0
|
self._STARTLINE = 0
|
||||||
end
|
end
|
||||||
if self._STARTLINE > self._LINECOUNT - self:height() then
|
local startline_end = self._LINECOUNT - self:height()
|
||||||
self._STARTLINE = self._LINECOUNT - self:height()
|
if self._STARTLINE > startline_end then
|
||||||
|
self._STARTLINE = startline_end
|
||||||
end
|
end
|
||||||
|
self:action_on(action.ac_on_scrolled, self._STARTLINE / startline_end)
|
||||||
self:invalidate()
|
self:invalidate()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -84,7 +86,9 @@ 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._LINECOUNT > self:height() then
|
||||||
self._STARTLINE = self._LINECOUNT - self:height()
|
local startline_end = self._LINECOUNT - self:height()
|
||||||
|
self._STARTLINE = startline_end
|
||||||
|
self:action_on(action.ac_on_scrolled, self._STARTLINE / startline_end)
|
||||||
self:invalidate()
|
self:invalidate()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -58,6 +58,11 @@ function textdialog:init(name, bounds, title)
|
|||||||
self:text():bounds_set(rect:new(0, 0, v:width(), v:height() - 1))
|
self:text():bounds_set(rect:new(0, 0, v:width(), v:height() - 1))
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- on scroll for text and scrollbar
|
||||||
|
self:text():action_set(action.ac_on_scrolled, function (v, progress)
|
||||||
|
self:scrollbar():progress_set(progress)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- enable or disable scrollbar
|
-- enable or disable scrollbar
|
||||||
|
Reference in New Issue
Block a user