Scrollbar and ScrollContainer use ScrollTo correctly

This commit is contained in:
Sasha Koshka 2024-05-13 19:45:18 -04:00
parent 224ca25000
commit 87e81c00d3
2 changed files with 9 additions and 9 deletions

View File

@ -98,9 +98,9 @@ func (this *Scrollbar) SetValue (value float64) {
position := trackLength * value
point := this.layout.linked.ContentBounds().Min
if this.layout.vertical {
point.Y = int(position)
point.Y = -int(position)
} else {
point.X = int(position)
point.X = -int(position)
}
this.layout.linked.ScrollTo(point)
@ -173,15 +173,15 @@ func (this *Scrollbar) handleMouseDown (button input.Button) {
}
case input.ButtonMiddle:
if above {
this.scrollBy(-this.pageSize())
} else {
this.scrollBy(this.pageSize())
} else {
this.scrollBy(-this.pageSize())
}
case input.ButtonRight:
if above {
this.scrollBy(-this.stepSize())
} else {
this.scrollBy(this.stepSize())
} else {
this.scrollBy(-this.stepSize())
}
}
}
@ -200,7 +200,7 @@ func (this *Scrollbar) handleScroll (x, y float64) {
if this.layout.linked == nil { return }
this.layout.linked.ScrollTo (
this.layout.linked.ContentBounds().Min.
Add(image.Pt(int(x), int(y))))
Sub(image.Pt(int(x), int(y))))
}
func (this *Scrollbar) drag () {
@ -327,7 +327,7 @@ func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
} else {
handleOffset = image.Pt(int(handlePosition), 0)
}
handle = handle.Add(handleOffset).Add(gutter.Min)
handle = handle.Sub(handleOffset).Add(gutter.Min)
// place handle
boxes[0].SetBounds(handle)

View File

@ -108,7 +108,7 @@ func (this *ScrollContainer) handleScroll (x, y float64) {
if this.layout.root == nil { return }
this.layout.root.ScrollTo (
this.layout.root.ContentBounds().Min.
Add(image.Pt(int(x), int(y))))
Sub(image.Pt(int(x), int(y))))
}
type scrollContainerLayout struct {