TextBox contstrains scroll positions to max

This commit is contained in:
2023-01-20 23:40:59 -05:00
parent 83d5064803
commit 3e8523f37a
2 changed files with 12 additions and 3 deletions

View File

@@ -249,16 +249,25 @@ func (element *TextBox) ScrollViewportBounds () (bounds image.Rectangle) {
return image.Rect (
element.scroll,
0,
element.scroll + element.Bounds().Inset(theme.Padding()).Dx(),
element.scroll + element.scrollViewportWidth(),
0)
}
func (element *TextBox) scrollViewportWidth () (width int) {
return element.Bounds().Inset(theme.Padding()).Dx()
}
// ScrollTo scrolls the viewport to the specified point relative to
// ScrollBounds.
func (element *TextBox) ScrollTo (position image.Point) {
// constrain to minimum
element.scroll = position.X
if element.scroll < 0 { element.scroll = 0 }
// TODO: constrain to max
// constrain to maximum
contentBounds := element.ScrollContentBounds()
maxPosition := contentBounds.Max.X - element.scrollViewportWidth()
if element.scroll > maxPosition { element.scroll = maxPosition }
if element.core.HasImage () {
element.draw()