@@ -1472,8 +1472,8 @@ function Widgets.textBox:setTexts(t)
14721472end
14731473function Widgets .textBox :push (t )
14741474 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 )
14771477 end
14781478end
14791479function Widgets .textBox :clear ()
@@ -1503,10 +1503,10 @@ function Widgets.textBox:press(x,y)
15031503 end
15041504end
15051505function 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 ))
15071507end
15081508function 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 ))
15101510end
15111511function Widgets .textBox :arrowKey (k )
15121512 self :scroll (0 ,k == ' up' and - 1 or k == ' down' and 1 or 0 )
@@ -1521,8 +1521,9 @@ function Widgets.textBox:update(dt)
15211521end
15221522function Widgets .textBox :draw ()
15231523 local x ,y ,w ,h = self ._x ,self ._y ,self .w ,self .h
1524- local texts = self ._texts
1524+ local list = self ._texts
15251525 local lineH = self .lineHeight
1526+ local H =# list * lineH
15261527 local scroll = self ._scrollPos1
15271528
15281529 -- Background
@@ -1541,12 +1542,12 @@ function Widgets.textBox:draw()
15411542
15421543 -- Slider
15431544 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
15461547 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 )
15481549 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 )
15501551 end
15511552 end
15521553
@@ -1571,8 +1572,8 @@ function Widgets.textBox:draw()
15711572 local pos = floor (scroll / lineH )
15721573 for i = 1 ,self ._capacity + 1 do
15731574 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 )
15761577 end
15771578 gc_translate (0 ,lineH )
15781579 end
0 commit comments