TextBox contstrains scroll positions to max
This commit is contained in:
parent
83d5064803
commit
3e8523f37a
@ -249,16 +249,25 @@ func (element *TextBox) ScrollViewportBounds () (bounds image.Rectangle) {
|
|||||||
return image.Rect (
|
return image.Rect (
|
||||||
element.scroll,
|
element.scroll,
|
||||||
0,
|
0,
|
||||||
element.scroll + element.Bounds().Inset(theme.Padding()).Dx(),
|
element.scroll + element.scrollViewportWidth(),
|
||||||
0)
|
0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (element *TextBox) scrollViewportWidth () (width int) {
|
||||||
|
return element.Bounds().Inset(theme.Padding()).Dx()
|
||||||
|
}
|
||||||
|
|
||||||
// ScrollTo scrolls the viewport to the specified point relative to
|
// ScrollTo scrolls the viewport to the specified point relative to
|
||||||
// ScrollBounds.
|
// ScrollBounds.
|
||||||
func (element *TextBox) ScrollTo (position image.Point) {
|
func (element *TextBox) ScrollTo (position image.Point) {
|
||||||
|
// constrain to minimum
|
||||||
element.scroll = position.X
|
element.scroll = position.X
|
||||||
if element.scroll < 0 { element.scroll = 0 }
|
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 () {
|
if element.core.HasImage () {
|
||||||
element.draw()
|
element.draw()
|
||||||
|
@ -131,7 +131,7 @@ func (element *Artist) Resize (width, height int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (element *Artist) lines (weight int, bounds image.Rectangle) {
|
func (element *Artist) lines (weight int, bounds image.Rectangle) {
|
||||||
bounds = bounds.Inset(8)
|
bounds = bounds.Inset(4)
|
||||||
c := uhex(0xFFFFFFFF)
|
c := uhex(0xFFFFFFFF)
|
||||||
artist.Line(element, c, weight, bounds.Min, bounds.Max)
|
artist.Line(element, c, weight, bounds.Min, bounds.Max)
|
||||||
artist.Line (
|
artist.Line (
|
||||||
|
Reference in New Issue
Block a user