@@ -1472,8 +1472,8 @@ function Widgets.textBox:setTexts(t)
1472
1472
end
1473
1473
function Widgets .textBox :push (t )
1474
1474
ins (self ._texts ,t )
1475
- if self ._scrollPos == (# self ._texts - 1 - self . _capacity )* self .lineHeight then -- minus 1 for the new message
1476
- self ._scrollPos = min (self ._scrollPos + self .lineHeight ,( # self ._texts - self . _capacity ) * self .lineHeight )
1475
+ if self ._scrollPos == (# self ._texts - 1 )* self .lineHeight - self . h then -- minus 1 for the new message
1476
+ self ._scrollPos = min (self ._scrollPos + self .lineHeight ,# self ._texts * self .lineHeight - self . h )
1477
1477
end
1478
1478
end
1479
1479
function Widgets .textBox :clear ()
@@ -1503,10 +1503,10 @@ function Widgets.textBox:press(x,y)
1503
1503
end
1504
1504
end
1505
1505
function Widgets .textBox :drag (_ ,_ ,_ ,dy )
1506
- self ._scrollPos = max (0 ,min (self ._scrollPos - dy ,( # self ._texts - self . _capacity ) * self .lineHeight ))
1506
+ self ._scrollPos = max (0 ,min (self ._scrollPos - dy ,# self ._texts * self .lineHeight - self . h ))
1507
1507
end
1508
1508
function Widgets .textBox :scroll (dx ,dy )
1509
- self ._scrollPos = max (0 ,min (self ._scrollPos - (dx + dy )* self .lineHeight ,( # self ._texts - self . _capacity ) * self .lineHeight ))
1509
+ self ._scrollPos = max (0 ,min (self ._scrollPos - (dx + dy )* self .lineHeight ,# self ._texts * self .lineHeight - self . h ))
1510
1510
end
1511
1511
function Widgets .textBox :arrowKey (k )
1512
1512
self :scroll (0 ,k == ' up' and - 1 or k == ' down' and 1 or 0 )
@@ -1521,8 +1521,9 @@ function Widgets.textBox:update(dt)
1521
1521
end
1522
1522
function Widgets .textBox :draw ()
1523
1523
local x ,y ,w ,h = self ._x ,self ._y ,self .w ,self .h
1524
- local texts = self ._texts
1524
+ local list = self ._texts
1525
1525
local lineH = self .lineHeight
1526
+ local H =# list * lineH
1526
1527
local scroll = self ._scrollPos1
1527
1528
1528
1529
-- Background
@@ -1541,12 +1542,12 @@ function Widgets.textBox:draw()
1541
1542
1542
1543
-- Slider
1543
1544
gc_setColor (COLOR .L )
1544
- if # texts > self ._capacity then
1545
- local len = h * h / ( # texts * lineH )
1545
+ if # list > self ._capacity then
1546
+ local len = h * h / H
1546
1547
if self .scrollBarPos == ' left' then
1547
- gc_rectangle (' fill' ,- 15 ,(h - len )* scroll / (( # texts - self . _capacity ) * lineH ),10 ,len ,self .cornerR )
1548
+ gc_rectangle (' fill' ,- 15 ,(h - len )* scroll / (H - h ),10 ,len ,self .cornerR )
1548
1549
elseif self .scrollBarPos == ' right' then
1549
- gc_rectangle (' fill' ,w + 5 ,(h - len )* scroll / (( # texts - self . _capacity ) * lineH ),10 ,len ,self .cornerR )
1550
+ gc_rectangle (' fill' ,w + 5 ,(h - len )* scroll / (H - h ),10 ,len ,self .cornerR )
1550
1551
end
1551
1552
end
1552
1553
@@ -1571,8 +1572,8 @@ function Widgets.textBox:draw()
1571
1572
local pos = floor (scroll / lineH )
1572
1573
for i = 1 ,self ._capacity + 1 do
1573
1574
i = pos + i
1574
- if texts [i ] then
1575
- gc_printf (texts [i ],10 ,self .yOffset ,w - 16 )
1575
+ if list [i ] then
1576
+ gc_printf (list [i ],10 ,self .yOffset ,w - 16 )
1576
1577
end
1577
1578
gc_translate (0 ,lineH )
1578
1579
end
0 commit comments