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.child.Resize (
element.childWidth, element.childWidth,
element.childHeight) element.childHeight)
element.draw() element.core.DamageAll()
} }
} }
} }
@ -339,10 +339,11 @@ func (element *ScrollContainer) updateMinimumSize () {
func (element *ScrollContainer) childScrollBoundsChangeCallback () { func (element *ScrollContainer) childScrollBoundsChangeCallback () {
element.horizontal.enabled, element.horizontal.enabled,
element.vertical.enabled = element.child.ScrollAxes() element.vertical.enabled = element.child.ScrollAxes()
if element.core.HasImage() { if element.core.HasImage() {
element.recalculate() element.recalculate()
element.drawHorizontalBar() element.drawHorizontalBar()
element.drawVerticalBar() 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.core.AllocateCanvas(width, height)
element.scrollToCursor() element.scrollToCursor()
element.draw() element.draw()
if element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
}
} }
func (element *TextBox) HandleMouseDown (x, y int, button tomo.Button) { func (element *TextBox) HandleMouseDown (x, y int, button tomo.Button) {
@ -69,6 +72,7 @@ func (element *TextBox) HandleKeyDown (
return return
} }
scrollMemory := element.scroll
altered := true altered := true
textChanged := false textChanged := false
switch { switch {
@ -120,6 +124,11 @@ func (element *TextBox) HandleKeyDown (
element.scrollToCursor() element.scrollToCursor()
} }
if (textChanged || scrollMemory != element.scroll) &&
element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
}
if altered && element.core.HasImage () { if altered && element.core.HasImage () {
element.draw() element.draw()
element.core.DamageAll() element.core.DamageAll()
@ -307,9 +316,6 @@ func (element *TextBox) scrollToCursor () {
element.scroll -= minX - cursorPosition.X element.scroll -= minX - cursorPosition.X
if element.scroll < 0 { element.scroll = 0 } if element.scroll < 0 { element.scroll = 0 }
} }
if element.onScrollBoundsChange != nil {
element.onScrollBoundsChange()
}
} }
func (element *TextBox) draw () { func (element *TextBox) draw () {