Add TextView, improved Scrollbar

This commit is contained in:
2023-09-15 16:11:59 -04:00
parent e45e391f6d
commit 02551987a4
4 changed files with 63 additions and 5 deletions

View File

@@ -173,15 +173,15 @@ func (this *Scrollbar) handleMouseDown (button input.Button) {
}
case input.ButtonMiddle:
if above {
this.SetValue(0)
this.scrollBy(-this.pageSize())
} else {
this.SetValue(1)
this.scrollBy(this.pageSize())
}
case input.ButtonRight:
if above {
this.SetValue(this.Value() - 0.05)
this.scrollBy(-this.stepSize())
} else {
this.SetValue(this.Value() + 0.05)
this.scrollBy(this.stepSize())
}
}
}
@@ -229,6 +229,34 @@ func (this *Scrollbar) fallbackDragOffset () image.Point {
}
}
func (this *Scrollbar) pageSize () int {
if this.layout.linked == nil { return 0 }
viewport := this.layout.linked.InnerBounds()
if this.layout.vertical {
return viewport.Dy()
} else {
return viewport.Dx()
}
}
func (this *Scrollbar) stepSize () int {
// FIXME: this should not be hardcoded, need to get base font metrics
// from theme somehow. should be (emspace, lineheight)
return 16
}
func (this *Scrollbar) scrollBy (distance int) {
if this.layout.linked == nil { return }
var vector image.Point; if this.layout.vertical {
vector.Y = distance
} else {
vector.X = distance
}
this.layout.linked.ScrollTo (
this.layout.linked.ContentBounds().Min.
Add(vector))
}
type scrollbarCookie struct {
owner *Scrollbar
subCookies []event.Cookie