Scroll bars recalculate and draw properly

This commit is contained in:
Sasha Koshka 2023-01-20 15:52:46 -05:00
parent faf38b96c2
commit b85285f326
2 changed files with 12 additions and 5 deletions

View File

@ -88,7 +88,7 @@ func (element *ScrollContainer) Adopt (child tomo.Scrollable) {
element.child.Resize (
element.childWidth,
element.childHeight)
element.draw()
element.core.DamageAll()
}
}
}
@ -339,10 +339,11 @@ func (element *ScrollContainer) updateMinimumSize () {
func (element *ScrollContainer) childScrollBoundsChangeCallback () {
element.horizontal.enabled,
element.vertical.enabled = element.child.ScrollAxes()
if element.core.HasImage() {
element.recalculate()
element.drawHorizontalBar()
element.drawVerticalBar()
element.core.DamageRegion(element.horizontal.gutter)
element.core.DamageRegion(element.vertical.gutter)
}
}

View File

@ -49,6 +49,9 @@ func (element *TextBox) Resize (width, height int) {
element.core.AllocateCanvas(width, height)
element.scrollToCursor()
element.draw()
if element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
}
}
func (element *TextBox) HandleMouseDown (x, y int, button tomo.Button) {
@ -69,6 +72,7 @@ func (element *TextBox) HandleKeyDown (
return
}
scrollMemory := element.scroll
altered := true
textChanged := false
switch {
@ -119,6 +123,11 @@ func (element *TextBox) HandleKeyDown (
if altered {
element.scrollToCursor()
}
if (textChanged || scrollMemory != element.scroll) &&
element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
}
if altered && element.core.HasImage () {
element.draw()
@ -307,9 +316,6 @@ func (element *TextBox) scrollToCursor () {
element.scroll -= minX - cursorPosition.X
if element.scroll < 0 { element.scroll = 0 }
}
if element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
}
}
func (element *TextBox) draw () {