Scrollbars can be dragged
This commit is contained in:
parent
15d7031e22
commit
c9e556f47b
30
scrollbar.go
30
scrollbar.go
@ -67,6 +67,7 @@ func (this *Scrollbar) Link (box tomo.ContentBox) event.Cookie {
|
|||||||
|
|
||||||
func (this *Scrollbar) handleLinkedContentBoundsChange () {
|
func (this *Scrollbar) handleLinkedContentBoundsChange () {
|
||||||
if this.layout.linked == nil { return }
|
if this.layout.linked == nil { return }
|
||||||
|
previousValue := this.layout.value
|
||||||
trackLength := this.layout.contentLength() - this.layout.viewportLength()
|
trackLength := this.layout.contentLength() - this.layout.viewportLength()
|
||||||
if trackLength == 0 {
|
if trackLength == 0 {
|
||||||
this.layout.value = 0
|
this.layout.value = 0
|
||||||
@ -74,13 +75,29 @@ func (this *Scrollbar) handleLinkedContentBoundsChange () {
|
|||||||
this.layout.value = this.layout.contentPos() / trackLength
|
this.layout.value = this.layout.contentPos() / trackLength
|
||||||
}
|
}
|
||||||
this.SetLayout(this.layout)
|
this.SetLayout(this.layout)
|
||||||
|
if this.layout.value != previousValue {
|
||||||
|
this.on.valueChange.Broadcast()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetValue sets the value of the scrollbar between 0 and 1, where 0 is scrolled
|
// SetValue sets the value of the scrollbar between 0 and 1, where 0 is scrolled
|
||||||
// all the way to the left/top, and 1 is scrolled all the way to the
|
// all the way to the left/top, and 1 is scrolled all the way to the
|
||||||
// right/bottom.
|
// right/bottom.
|
||||||
func (this *Scrollbar) SetValue (value float64) {
|
func (this *Scrollbar) SetValue (value float64) {
|
||||||
// TODO
|
if this.layout.linked == nil { return }
|
||||||
|
if value > 1 { value = 1 }
|
||||||
|
if value < 0 { value = 0 }
|
||||||
|
|
||||||
|
trackLength := this.layout.contentLength() - this.layout.viewportLength()
|
||||||
|
position := trackLength * value
|
||||||
|
point := this.layout.linked.ContentBounds().Min
|
||||||
|
if this.layout.vertical {
|
||||||
|
point.Y = int(position)
|
||||||
|
} else {
|
||||||
|
point.X = int(position)
|
||||||
|
}
|
||||||
|
this.layout.linked.ScrollTo(point)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value returns the value of the scrollbar between 0 and 1 where 0 is scrolled
|
// Value returns the value of the scrollbar between 0 and 1 where 0 is scrolled
|
||||||
@ -127,14 +144,12 @@ func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) {
|
|||||||
func (this *Scrollbar) handleMouseDown (button input.Button) {
|
func (this *Scrollbar) handleMouseDown (button input.Button) {
|
||||||
pointer := this.MousePosition()
|
pointer := this.MousePosition()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
var above, within bool
|
|
||||||
|
|
||||||
if pointer.In(handle) {
|
within := pointer.In(handle)
|
||||||
within = true
|
var above bool; if this.layout.vertical {
|
||||||
} else if this.layout.vertical {
|
above = pointer.Y < handle.Min.Y + handle.Dy() / 2
|
||||||
above = pointer.Y < handle.Min.Y
|
|
||||||
} else {
|
} else {
|
||||||
above = pointer.X < handle.Min.X
|
above = pointer.X < handle.Min.X + handle.Dx() / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
switch button {
|
switch button {
|
||||||
@ -189,7 +204,6 @@ func (this *Scrollbar) drag () {
|
|||||||
|
|
||||||
if this.layout.vertical {
|
if this.layout.vertical {
|
||||||
this.SetValue (
|
this.SetValue (
|
||||||
1 -
|
|
||||||
float64(pointer.Y) /
|
float64(pointer.Y) /
|
||||||
float64(gutter.Dy() - handle.Dy()))
|
float64(gutter.Dy() - handle.Dy()))
|
||||||
} else {
|
} else {
|
||||||
|
12
slider.go
12
slider.go
@ -115,14 +115,12 @@ func (this *Slider) handleKeyDown (key input.Key, numpad bool) {
|
|||||||
func (this *Slider) handleMouseDown (button input.Button) {
|
func (this *Slider) handleMouseDown (button input.Button) {
|
||||||
pointer := this.MousePosition()
|
pointer := this.MousePosition()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
var above, within bool
|
|
||||||
|
within := pointer.In(handle)
|
||||||
if pointer.In(handle) {
|
var above bool; if this.layout.vertical {
|
||||||
within = true
|
above = pointer.Y < handle.Min.Y + handle.Dy() / 2
|
||||||
} else if this.layout.vertical {
|
|
||||||
above = pointer.Y < handle.Min.Y
|
|
||||||
} else {
|
} else {
|
||||||
above = pointer.X < handle.Min.X
|
above = pointer.X < handle.Min.X + handle.Dx() / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
switch button {
|
switch button {
|
||||||
|
Loading…
Reference in New Issue
Block a user