Make value getters/setters more consistent

See #6
This commit is contained in:
2024-06-27 14:01:14 -04:00
parent d0ee6c432c
commit 638fc61d83
11 changed files with 128 additions and 105 deletions

View File

@@ -42,6 +42,10 @@ type ScrollContainer struct {
horizontalCookie event.Cookie
verticalCookie event.Cookie
on struct {
valueChange event.FuncBroadcaster
}
}
// NewScrollContainer creates a new scroll container.
@@ -52,10 +56,12 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
}
if sides.Vertical() {
this.layout.vertical = NewVerticalScrollbar()
this.layout.vertical.OnValueChange(this.handleValueChange)
this.Add(this.layout.vertical)
}
if sides.Horizontal() {
this.layout.horizontal = NewHorizontalScrollbar()
this.layout.horizontal.OnValueChange(this.handleValueChange)
this.Add(this.layout.horizontal)
}
this.CaptureScroll(true)
@@ -103,6 +109,18 @@ func (this *ScrollContainer) SetRoot (root tomo.ContentObject) {
}
}
// Value returns the horizontal and vertical scrollbar values where 0 is all the
// way to the left/top, and 1 is all the way to the right/bottom.
func (this *ScrollContainer) Value () (x, y float64) {
if this.layout.horizontal != nil {
x = this.layout.horizontal.Value()
}
if this.layout.vertical != nil {
y = this.layout.vertical.Value()
}
return x, y
}
// SetValue sets the horizontal and vertical scrollbar values where 0 is all the
// way to the left/top, and 1 is all the way to the right/bottom.
func (this *ScrollContainer) SetValue (x, y float64) {
@@ -114,16 +132,14 @@ func (this *ScrollContainer) SetValue (x, y float64) {
}
}
// Value returns the horizontal and vertical scrollbar values where 0 is all the
// way to the left/top, and 1 is all the way to the right/bottom.
func (this *ScrollContainer) Value () (x, y float64) {
if this.layout.horizontal != nil {
x = this.layout.horizontal.Value()
}
if this.layout.vertical != nil {
y = this.layout.vertical.Value()
}
return x, y
// OnValueChange specifies a function to be called when the user changes the
// position of the horizontal or vertical scrollbars.
func (this *ScrollContainer) OnValueChange (callback func ()) event.Cookie {
return this.on.valueChange.Connect(callback)
}
func (this *ScrollContainer) handleValueChange () {
this.on.valueChange.Broadcast()
}
func (this *ScrollContainer) handleScroll (x, y float64) {