draw scroll progress

This commit is contained in:
ruki
2020-05-09 22:36:24 +08:00
parent bfcc4c9fc0
commit 4f1a96fcec
2 changed files with 7 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
package = "ltui"
version = "1.9-2"
version = "1.9-3"
source = {
url = "git://github.com/tboox/ltui",
tag = "v1.9"

View File

@@ -62,9 +62,12 @@ function textarea:on_draw(transparent)
-- draw progress
if self:option("progress") then
local progress = math.floor((self._STARTLINE + math.min(self:height(), self._LINECOUNT)) * 100 / self._LINECOUNT)
if (self._STARTLINE > 0 or progress < 100) and self:width() > 20 then
self:canvas():move(self:width() - 10, self:height() - 1):putstr(string.format("(%d%%)", progress))
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