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/event"
|
||||
|
||||
var _ tomo.Object = new(Scrollbar)
|
||||
|
||||
// Scrollbar is a special type of slider that can control the scroll of any
|
||||
// overflowing ContainerBox.
|
||||
// overflowing ContainerObject.
|
||||
type Scrollbar struct {
|
||||
tomo.ContainerBox
|
||||
box tomo.ContainerBox
|
||||
handle *sliderHandle
|
||||
layout scrollbarLayout
|
||||
dragging bool
|
||||
@ -23,7 +25,7 @@ type Scrollbar struct {
|
||||
|
||||
func newScrollbar (orient string) *Scrollbar {
|
||||
this := &Scrollbar {
|
||||
ContainerBox: tomo.NewContainerBox(),
|
||||
box: tomo.NewContainerBox(),
|
||||
handle: &sliderHandle {
|
||||
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.SetInputMask(true)
|
||||
this.OnKeyUp(this.handleKeyUp)
|
||||
this.OnKeyDown(this.handleKeyDown)
|
||||
this.OnButtonDown(this.handleButtonDown)
|
||||
this.OnButtonUp(this.handleButtonUp)
|
||||
this.OnMouseMove(this.handleMouseMove)
|
||||
this.OnScroll(this.handleScroll)
|
||||
this.box.SetFocusable(true)
|
||||
this.box.SetInputMask(true)
|
||||
this.box.OnKeyUp(this.handleKeyUp)
|
||||
this.box.OnKeyDown(this.handleKeyDown)
|
||||
this.box.OnButtonDown(this.handleButtonDown)
|
||||
this.box.OnButtonUp(this.handleButtonUp)
|
||||
this.box.OnMouseMove(this.handleMouseMove)
|
||||
this.box.OnScroll(this.handleScroll)
|
||||
|
||||
this.handle.SetRole(tomo.R("objects", "ScrollbarHandle"))
|
||||
this.handle.SetTag(orient, true)
|
||||
this.SetRole(tomo.R("objects", "Scrollbar"))
|
||||
this.SetTag(orient, true)
|
||||
this.box.SetRole(tomo.R("objects", "Scrollbar"))
|
||||
this.box.SetTag(orient, true)
|
||||
return this
|
||||
}
|
||||
|
||||
@ -60,13 +62,18 @@ func NewHorizontalScrollbar () *Scrollbar {
|
||||
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
|
||||
// will unlink it.
|
||||
func (this *Scrollbar) Link (box tomo.ContentObject) event.Cookie {
|
||||
this.layout.linked = box
|
||||
this.linkCookie = this.newLinkCookie (
|
||||
box.OnContentBoundsChange(this.handleLinkedContentBoundsChange))
|
||||
this.SetAttr(tomo.ALayout(this.layout))
|
||||
this.box.SetAttr(tomo.ALayout(this.layout))
|
||||
return this.linkCookie
|
||||
}
|
||||
|
||||
@ -79,7 +86,7 @@ func (this *Scrollbar) handleLinkedContentBoundsChange () {
|
||||
} else {
|
||||
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 {
|
||||
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 {
|
||||
modifiers := this.Window().Modifiers()
|
||||
modifiers := this.box.Window().Modifiers()
|
||||
|
||||
switch key {
|
||||
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 {
|
||||
pointer := this.Window().MousePosition()
|
||||
pointer := this.box.Window().MousePosition()
|
||||
handle := this.handle.Bounds()
|
||||
|
||||
within := pointer.In(handle)
|
||||
@ -199,7 +206,7 @@ func (this *Scrollbar) handleButtonDown (button input.Button) bool {
|
||||
this.dragging = true
|
||||
this.dragOffset =
|
||||
pointer.Sub(this.handle.Bounds().Min).
|
||||
Add(this.InnerBounds().Min)
|
||||
Add(this.box.InnerBounds().Min)
|
||||
this.drag()
|
||||
} else {
|
||||
this.dragOffset = this.fallbackDragOffset()
|
||||
@ -253,8 +260,8 @@ func (this *Scrollbar) handleScroll (x, y float64) bool {
|
||||
}
|
||||
|
||||
func (this *Scrollbar) drag () {
|
||||
pointer := this.Window().MousePosition().Sub(this.dragOffset)
|
||||
gutter := this.InnerBounds()
|
||||
pointer := this.box.Window().MousePosition().Sub(this.dragOffset)
|
||||
gutter := this.box.InnerBounds()
|
||||
handle := this.handle.Bounds()
|
||||
|
||||
if this.layout.vertical {
|
||||
@ -270,10 +277,10 @@ func (this *Scrollbar) drag () {
|
||||
|
||||
func (this *Scrollbar) fallbackDragOffset () image.Point {
|
||||
if this.layout.vertical {
|
||||
return this.InnerBounds().Min.
|
||||
return this.box.InnerBounds().Min.
|
||||
Add(image.Pt(0, this.handle.Bounds().Dy() / 2))
|
||||
} else {
|
||||
return this.InnerBounds().Min.
|
||||
return this.box.InnerBounds().Min.
|
||||
Add(image.Pt(this.handle.Bounds().Dx() / 2, 0))
|
||||
}
|
||||
}
|
||||
@ -307,7 +314,7 @@ func (this *scrollbarCookie) Close () {
|
||||
cookie.Close()
|
||||
}
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user