Fix TextBox scroll behavior

This commit is contained in:
Sasha Koshka 2024-05-13 19:39:36 -04:00
parent 96fa7b5623
commit b9092eae87
1 changed files with 12 additions and 11 deletions

View File

@ -222,7 +222,7 @@ func (this *textBox) drawDot (can canvas.Canvas) {
func (this *textBox) textOffset () image.Point { func (this *textBox) textOffset () image.Point {
return this.InnerBounds().Min. return this.InnerBounds().Min.
Sub(this.scroll). Add(this.scroll).
Sub(this.drawer.LayoutBoundsSpace().Min) Sub(this.drawer.LayoutBoundsSpace().Min)
} }
@ -294,6 +294,7 @@ func (this *textBox) doLayout () {
this.contentBounds = this.normalizedLayoutBoundsSpace() this.contentBounds = this.normalizedLayoutBoundsSpace()
this.constrainScroll() this.constrainScroll()
this.contentBounds = this.contentBounds.Add(this.scroll) this.contentBounds = this.contentBounds.Add(this.scroll)
// println(this.InnerBounds().String(), this.contentBounds.String())
if previousContentBounds != this.contentBounds { if previousContentBounds != this.contentBounds {
this.on.contentBoundsChange.Broadcast() this.on.contentBoundsChange.Broadcast()
@ -308,19 +309,19 @@ func (this *textBox) constrainScroll () {
// X // X
if width <= innerBounds.Dx() { if width <= innerBounds.Dx() {
this.scroll.X = 0 this.scroll.X = 0
} else if this.scroll.X < 0 { } else if this.scroll.X > 0 {
this.scroll.X = 0 this.scroll.X = 0
} else if this.scroll.X > width - innerBounds.Dx() { } else if this.scroll.X < innerBounds.Dx() - width {
this.scroll.X = width - innerBounds.Dx() this.scroll.X = innerBounds.Dx() - width
} }
// Y // Y
if height <= innerBounds.Dy() { if height <= innerBounds.Dy() {
this.scroll.Y = 0 this.scroll.Y = 0
} else if this.scroll.Y < 0 { } else if this.scroll.Y > 0 {
this.scroll.Y = 0 this.scroll.Y = 0
} else if this.scroll.Y > height - innerBounds.Dy() { } else if this.scroll.Y < innerBounds.Dy() - height {
this.scroll.Y = height - innerBounds.Dy() this.scroll.Y = innerBounds.Dy() - height
} }
} }
@ -333,16 +334,16 @@ func (this *textBox) scrollToDot () {
// X // X
if dot.X < innerBounds.Min.X + em { if dot.X < innerBounds.Min.X + em {
scroll.X -= innerBounds.Min.X - dot.X + em scroll.X += innerBounds.Min.X - dot.X + em
} else if dot.X > innerBounds.Max.X - em { } else if dot.X > innerBounds.Max.X - em {
scroll.X += dot.X - innerBounds.Max.X + em scroll.X -= dot.X - innerBounds.Max.X + em
} }
// Y // Y
if dot.Y < innerBounds.Min.Y + lineHeight { if dot.Y < innerBounds.Min.Y + lineHeight {
scroll.Y -= innerBounds.Min.Y - dot.Y + lineHeight scroll.Y += innerBounds.Min.Y - dot.Y + lineHeight
} else if dot.Y > innerBounds.Max.Y - lineHeight { } else if dot.Y > innerBounds.Max.Y - lineHeight {
scroll.Y += dot.Y - innerBounds.Max.Y + lineHeight scroll.Y -= dot.Y - innerBounds.Max.Y + lineHeight
} }
this.ScrollTo(scroll) this.ScrollTo(scroll)