The scroll bar is better
This commit is contained in:
parent
8e1638e054
commit
1c28613981
@ -70,7 +70,9 @@ func (element *ScrollBar) HandleMouseDown (x, y int, button input.Button) {
|
|||||||
// the mouse is pressed down within the bar's handle
|
// the mouse is pressed down within the bar's handle
|
||||||
element.dragging = true
|
element.dragging = true
|
||||||
element.drawAndPush()
|
element.drawAndPush()
|
||||||
element.dragOffset = point
|
element.dragOffset =
|
||||||
|
point.Sub(element.bar.Min).
|
||||||
|
Add(element.Bounds().Min)
|
||||||
element.dragTo(point)
|
element.dragTo(point)
|
||||||
} else {
|
} else {
|
||||||
// the mouse is pressed down within the bar's gutter
|
// the mouse is pressed down within the bar's gutter
|
||||||
@ -178,9 +180,11 @@ func (element *ScrollBar) isAfterHandle (point image.Point) bool {
|
|||||||
|
|
||||||
func (element *ScrollBar) fallbackDragOffset () image.Point {
|
func (element *ScrollBar) fallbackDragOffset () image.Point {
|
||||||
if element.vertical {
|
if element.vertical {
|
||||||
return element.bar.Min.Add(image.Pt(0, element.bar.Dy() / 2))
|
return element.Bounds().Min.
|
||||||
|
Add(image.Pt(0, element.bar.Dy() / 2))
|
||||||
} else {
|
} else {
|
||||||
return element.bar.Min.Add(image.Pt(element.bar.Dx() / 2, 0))
|
return element.Bounds().Min.
|
||||||
|
Add(image.Pt(element.bar.Dx() / 2, 0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,17 +24,27 @@ func run () {
|
|||||||
Gap: true,
|
Gap: true,
|
||||||
})
|
})
|
||||||
list := basicElements.NewList (
|
list := basicElements.NewList (
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 0", nil),
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 1", nil),
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 2", nil),
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 3", nil),
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 4", nil),
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 5", nil),
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 6", nil),
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 7", nil),
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 8", nil),
|
||||||
basicElements.NewListEntry("something", nil),
|
basicElements.NewListEntry("This is list item 9", nil),
|
||||||
basicElements.NewListEntry("something", nil))
|
basicElements.NewListEntry("This is list item 10", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 11", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 12", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 13", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 14", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 15", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 16", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 17", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 18", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 19", nil),
|
||||||
|
basicElements.NewListEntry("This is list item 20", nil))
|
||||||
list.Collapse(0, 32)
|
list.Collapse(0, 32)
|
||||||
scrollBar := basicElements.NewScrollBar(true)
|
scrollBar := basicElements.NewScrollBar(true)
|
||||||
list.OnScrollBoundsChange (func () {
|
list.OnScrollBoundsChange (func () {
|
||||||
@ -46,12 +56,15 @@ func run () {
|
|||||||
list.ScrollTo(viewport)
|
list.ScrollTo(viewport)
|
||||||
})
|
})
|
||||||
|
|
||||||
container.Adopt(basicElements.NewLabel("look at this non sense", false), false)
|
container.Adopt(basicElements.NewLabel("A ScrollContainer:", false), false)
|
||||||
scrollContainer.Adopt(textBox)
|
scrollContainer.Adopt(textBox)
|
||||||
container.Adopt(scrollContainer, false)
|
container.Adopt(scrollContainer, false)
|
||||||
container.Adopt(basicElements.NewLabel("what does that scrollbar do?", false), false)
|
|
||||||
disconnectedContainer.Adopt(list, false)
|
disconnectedContainer.Adopt(list, false)
|
||||||
disconnectedContainer.Adopt(basicElements.NewSpacer(true), true)
|
disconnectedContainer.Adopt (basicElements.NewLabel (
|
||||||
|
"Notice how the scroll bar to the right can be used to " +
|
||||||
|
"control the list, despite not even touching it. It is " +
|
||||||
|
"indeed a thing you can do. It is also terrible UI design so " +
|
||||||
|
"don't do it.", true), true)
|
||||||
disconnectedContainer.Adopt(scrollBar, false)
|
disconnectedContainer.Adopt(scrollBar, false)
|
||||||
container.Adopt(disconnectedContainer, true)
|
container.Adopt(disconnectedContainer, true)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user