Scrollbar now displays scroll value
This commit is contained in:
parent
134f8016c1
commit
15d7031e22
59
scrollbar.go
59
scrollbar.go
@ -43,6 +43,7 @@ func newScrollbar (orient string) *Scrollbar {
|
|||||||
this.OnMouseDown(this.handleMouseDown)
|
this.OnMouseDown(this.handleMouseDown)
|
||||||
this.OnMouseUp(this.handleMouseUp)
|
this.OnMouseUp(this.handleMouseUp)
|
||||||
this.OnMouseMove(this.handleMouseMove)
|
this.OnMouseMove(this.handleMouseMove)
|
||||||
|
this.OnScroll(this.handleScroll)
|
||||||
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
|
theme.Apply(this.handle, theme.R("objects", "SliderHandle", orient))
|
||||||
theme.Apply(this, theme.R("objects", "Slider", orient))
|
theme.Apply(this, theme.R("objects", "Slider", orient))
|
||||||
return this
|
return this
|
||||||
@ -65,10 +66,13 @@ func (this *Scrollbar) Link (box tomo.ContentBox) event.Cookie {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleLinkedContentBoundsChange () {
|
func (this *Scrollbar) handleLinkedContentBoundsChange () {
|
||||||
if this.layout.linked == 0 { return }
|
if this.layout.linked == nil { return }
|
||||||
this.layout.value =
|
trackLength := this.layout.contentLength() - this.layout.viewportLength()
|
||||||
this.layout.contentPos() /
|
if trackLength == 0 {
|
||||||
(this.layout.contentLength() - this.layout.viewportLength())
|
this.layout.value = 0
|
||||||
|
} else {
|
||||||
|
this.layout.value = this.layout.contentPos() / trackLength
|
||||||
|
}
|
||||||
this.SetLayout(this.layout)
|
this.SetLayout(this.layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +175,13 @@ func (this *Scrollbar) handleMouseMove () {
|
|||||||
this.drag()
|
this.drag()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))))
|
||||||
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) drag () {
|
func (this *Scrollbar) drag () {
|
||||||
pointer := this.MousePosition().Sub(this.dragOffset)
|
pointer := this.MousePosition().Sub(this.dragOffset)
|
||||||
gutter := this.InnerBounds()
|
gutter := this.InnerBounds()
|
||||||
@ -234,18 +245,44 @@ func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
|||||||
handle := image.Rectangle { Max: boxes[0].MinimumSize() }
|
handle := image.Rectangle { Max: boxes[0].MinimumSize() }
|
||||||
gutter := hints.Bounds
|
gutter := hints.Bounds
|
||||||
|
|
||||||
|
var gutterLength float64;
|
||||||
|
var handleMin float64;
|
||||||
|
if this.vertical {
|
||||||
|
gutterLength = float64(gutter.Dy())
|
||||||
|
handleMin = float64(handle.Dy())
|
||||||
|
} else {
|
||||||
|
gutterLength = float64(gutter.Dx())
|
||||||
|
handleMin = float64(handle.Dx())
|
||||||
|
}
|
||||||
|
|
||||||
// TODO
|
// calculate handle length
|
||||||
// - apply (viewportContentRatio) to length of gutter
|
handleLength := gutterLength * this.viewportContentRatio()
|
||||||
// - constrain to minimum length of handle
|
if handleLength < handleMin { handleLength = handleMin }
|
||||||
// - set handle to constrained length
|
if handleLength > gutterLength { handleLength = gutterLength }
|
||||||
// - apply (value) to length of gutter minus length of handle
|
if this.vertical {
|
||||||
// - that is the handle position
|
handle.Max.Y = int(handleLength)
|
||||||
|
} else {
|
||||||
|
handle.Max.X = int(handleLength)
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate handle position
|
||||||
|
handlePosition := (gutterLength - handleLength) * this.value
|
||||||
|
var handleOffset image.Point
|
||||||
|
if this.vertical {
|
||||||
|
handleOffset = image.Pt(0, int(handlePosition))
|
||||||
|
} else {
|
||||||
|
handleOffset = image.Pt(int(handlePosition), 0)
|
||||||
|
}
|
||||||
|
handle = handle.Add(handleOffset).Add(gutter.Min)
|
||||||
|
|
||||||
|
// place handle
|
||||||
|
boxes[0].SetBounds(handle)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this scrollbarLayout) viewportContentRatio () float64 {
|
func (this scrollbarLayout) viewportContentRatio () float64 {
|
||||||
if this.linked == nil { return 0 }
|
if this.linked == nil { return 0 }
|
||||||
return this.viewportLength / this.contentLength
|
return this.viewportLength() / this.contentLength()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this scrollbarLayout) viewportLength () float64 {
|
func (this scrollbarLayout) viewportLength () float64 {
|
||||||
|
Loading…
Reference in New Issue
Block a user