TextBox contstrains scroll positions to max

This commit is contained in:
Sasha Koshka 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()

View File

@ -131,7 +131,7 @@ func (element *Artist) Resize (width, height int) {
}
func (element *Artist) lines (weight int, bounds image.Rectangle) {
bounds = bounds.Inset(8)
bounds = bounds.Inset(4)
c := uhex(0xFFFFFFFF)
artist.Line(element, c, weight, bounds.Min, bounds.Max)
artist.Line (