Scrollbar no longer embeds tomo.ContainerBox
This commit is contained in:
parent
02fed8ce48
commit
bc175bb5ae
55
scrollbar.go
55
scrollbar.go
@ -5,10 +5,12 @@ import "git.tebibyte.media/tomo/tomo"
|
|||||||
import "git.tebibyte.media/tomo/tomo/input"
|
import "git.tebibyte.media/tomo/tomo/input"
|
||||||
import "git.tebibyte.media/tomo/tomo/event"
|
import "git.tebibyte.media/tomo/tomo/event"
|
||||||
|
|
||||||
|
var _ tomo.Object = new(Scrollbar)
|
||||||
|
|
||||||
// Scrollbar is a special type of slider that can control the scroll of any
|
// Scrollbar is a special type of slider that can control the scroll of any
|
||||||
// overflowing ContainerBox.
|
// overflowing ContainerObject.
|
||||||
type Scrollbar struct {
|
type Scrollbar struct {
|
||||||
tomo.ContainerBox
|
box tomo.ContainerBox
|
||||||
handle *sliderHandle
|
handle *sliderHandle
|
||||||
layout scrollbarLayout
|
layout scrollbarLayout
|
||||||
dragging bool
|
dragging bool
|
||||||
@ -23,7 +25,7 @@ type Scrollbar struct {
|
|||||||
|
|
||||||
func newScrollbar (orient string) *Scrollbar {
|
func newScrollbar (orient string) *Scrollbar {
|
||||||
this := &Scrollbar {
|
this := &Scrollbar {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
box: tomo.NewContainerBox(),
|
||||||
handle: &sliderHandle {
|
handle: &sliderHandle {
|
||||||
Box: tomo.NewBox(),
|
Box: tomo.NewBox(),
|
||||||
},
|
},
|
||||||
@ -32,21 +34,21 @@ func newScrollbar (orient string) *Scrollbar {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Add(this.handle)
|
this.box.Add(this.handle)
|
||||||
|
|
||||||
this.SetFocusable(true)
|
this.box.SetFocusable(true)
|
||||||
this.SetInputMask(true)
|
this.box.SetInputMask(true)
|
||||||
this.OnKeyUp(this.handleKeyUp)
|
this.box.OnKeyUp(this.handleKeyUp)
|
||||||
this.OnKeyDown(this.handleKeyDown)
|
this.box.OnKeyDown(this.handleKeyDown)
|
||||||
this.OnButtonDown(this.handleButtonDown)
|
this.box.OnButtonDown(this.handleButtonDown)
|
||||||
this.OnButtonUp(this.handleButtonUp)
|
this.box.OnButtonUp(this.handleButtonUp)
|
||||||
this.OnMouseMove(this.handleMouseMove)
|
this.box.OnMouseMove(this.handleMouseMove)
|
||||||
this.OnScroll(this.handleScroll)
|
this.box.OnScroll(this.handleScroll)
|
||||||
|
|
||||||
this.handle.SetRole(tomo.R("objects", "ScrollbarHandle"))
|
this.handle.SetRole(tomo.R("objects", "ScrollbarHandle"))
|
||||||
this.handle.SetTag(orient, true)
|
this.handle.SetTag(orient, true)
|
||||||
this.SetRole(tomo.R("objects", "Scrollbar"))
|
this.box.SetRole(tomo.R("objects", "Scrollbar"))
|
||||||
this.SetTag(orient, true)
|
this.box.SetTag(orient, true)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,13 +62,18 @@ func NewHorizontalScrollbar () *Scrollbar {
|
|||||||
return newScrollbar("horizontal")
|
return newScrollbar("horizontal")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBox returns the underlying box.
|
||||||
|
func (this *Scrollbar) GetBox () tomo.Box {
|
||||||
|
return this.box
|
||||||
|
}
|
||||||
|
|
||||||
// Link assigns this scrollbar to a ContentObject. Closing the returned cookie
|
// Link assigns this scrollbar to a ContentObject. Closing the returned cookie
|
||||||
// will unlink it.
|
// will unlink it.
|
||||||
func (this *Scrollbar) Link (box tomo.ContentObject) event.Cookie {
|
func (this *Scrollbar) Link (box tomo.ContentObject) event.Cookie {
|
||||||
this.layout.linked = box
|
this.layout.linked = box
|
||||||
this.linkCookie = this.newLinkCookie (
|
this.linkCookie = this.newLinkCookie (
|
||||||
box.OnContentBoundsChange(this.handleLinkedContentBoundsChange))
|
box.OnContentBoundsChange(this.handleLinkedContentBoundsChange))
|
||||||
this.SetAttr(tomo.ALayout(this.layout))
|
this.box.SetAttr(tomo.ALayout(this.layout))
|
||||||
return this.linkCookie
|
return this.linkCookie
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +86,7 @@ func (this *Scrollbar) handleLinkedContentBoundsChange () {
|
|||||||
} else {
|
} else {
|
||||||
this.layout.value = this.layout.contentPos() / trackLength
|
this.layout.value = this.layout.contentPos() / trackLength
|
||||||
}
|
}
|
||||||
this.SetAttr(tomo.ALayout(this.layout))
|
this.box.SetAttr(tomo.ALayout(this.layout))
|
||||||
if this.layout.value != previousValue {
|
if this.layout.value != previousValue {
|
||||||
this.on.valueChange.Broadcast()
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
@ -150,7 +157,7 @@ func (this *Scrollbar) handleKeyUp (key input.Key, numpad bool) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) bool {
|
func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) bool {
|
||||||
modifiers := this.Window().Modifiers()
|
modifiers := this.box.Window().Modifiers()
|
||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyUp, input.KeyLeft:
|
case input.KeyUp, input.KeyLeft:
|
||||||
@ -183,7 +190,7 @@ func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) handleButtonDown (button input.Button) bool {
|
func (this *Scrollbar) handleButtonDown (button input.Button) bool {
|
||||||
pointer := this.Window().MousePosition()
|
pointer := this.box.Window().MousePosition()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
|
|
||||||
within := pointer.In(handle)
|
within := pointer.In(handle)
|
||||||
@ -199,7 +206,7 @@ func (this *Scrollbar) handleButtonDown (button input.Button) bool {
|
|||||||
this.dragging = true
|
this.dragging = true
|
||||||
this.dragOffset =
|
this.dragOffset =
|
||||||
pointer.Sub(this.handle.Bounds().Min).
|
pointer.Sub(this.handle.Bounds().Min).
|
||||||
Add(this.InnerBounds().Min)
|
Add(this.box.InnerBounds().Min)
|
||||||
this.drag()
|
this.drag()
|
||||||
} else {
|
} else {
|
||||||
this.dragOffset = this.fallbackDragOffset()
|
this.dragOffset = this.fallbackDragOffset()
|
||||||
@ -253,8 +260,8 @@ func (this *Scrollbar) handleScroll (x, y float64) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Scrollbar) drag () {
|
func (this *Scrollbar) drag () {
|
||||||
pointer := this.Window().MousePosition().Sub(this.dragOffset)
|
pointer := this.box.Window().MousePosition().Sub(this.dragOffset)
|
||||||
gutter := this.InnerBounds()
|
gutter := this.box.InnerBounds()
|
||||||
handle := this.handle.Bounds()
|
handle := this.handle.Bounds()
|
||||||
|
|
||||||
if this.layout.vertical {
|
if this.layout.vertical {
|
||||||
@ -270,10 +277,10 @@ func (this *Scrollbar) drag () {
|
|||||||
|
|
||||||
func (this *Scrollbar) fallbackDragOffset () image.Point {
|
func (this *Scrollbar) fallbackDragOffset () image.Point {
|
||||||
if this.layout.vertical {
|
if this.layout.vertical {
|
||||||
return this.InnerBounds().Min.
|
return this.box.InnerBounds().Min.
|
||||||
Add(image.Pt(0, this.handle.Bounds().Dy() / 2))
|
Add(image.Pt(0, this.handle.Bounds().Dy() / 2))
|
||||||
} else {
|
} else {
|
||||||
return this.InnerBounds().Min.
|
return this.box.InnerBounds().Min.
|
||||||
Add(image.Pt(this.handle.Bounds().Dx() / 2, 0))
|
Add(image.Pt(this.handle.Bounds().Dx() / 2, 0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +314,7 @@ func (this *scrollbarCookie) Close () {
|
|||||||
cookie.Close()
|
cookie.Close()
|
||||||
}
|
}
|
||||||
this.owner.layout.linked = nil
|
this.owner.layout.linked = nil
|
||||||
this.owner.SetAttr(tomo.ALayout(this.owner.layout))
|
this.owner.box.SetAttr(tomo.ALayout(this.owner.layout))
|
||||||
}
|
}
|
||||||
|
|
||||||
type scrollbarLayout struct {
|
type scrollbarLayout struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user