ScrollContainer no longer embeds ContainerBox

This commit is contained in:
Sasha Koshka 2024-08-24 21:41:16 -04:00
parent bc175bb5ae
commit 8b79fec1bd

View File

@ -37,9 +37,11 @@ func (sides ScrollSide) String () string {
}
}
var _ tomo.Object = new(ScrollContainer)
// ScrollContainer couples a ContentBox with one or two Scrollbars.
type ScrollContainer struct {
tomo.ContainerBox
box tomo.ContainerBox
root tomo.ContentObject
horizontal *Scrollbar
@ -55,30 +57,35 @@ type ScrollContainer struct {
// NewScrollContainer creates a new scroll container.
func NewScrollContainer (sides ScrollSide) *ScrollContainer {
this := &ScrollContainer {
ContainerBox: tomo.NewContainerBox(),
scrollContainer := &ScrollContainer {
box: tomo.NewContainerBox(),
}
if sides.Vertical() {
this.vertical = NewVerticalScrollbar()
this.vertical.OnValueChange(this.handleValueChange)
this.Add(this.vertical)
scrollContainer.vertical = NewVerticalScrollbar()
scrollContainer.vertical.OnValueChange(scrollContainer.handleValueChange)
scrollContainer.box.Add(scrollContainer.vertical)
}
if sides.Horizontal() {
this.horizontal = NewHorizontalScrollbar()
this.horizontal.OnValueChange(this.handleValueChange)
this.Add(this.horizontal)
scrollContainer.horizontal = NewHorizontalScrollbar()
scrollContainer.horizontal.OnValueChange(scrollContainer.handleValueChange)
scrollContainer.box.Add(scrollContainer.horizontal)
}
this.OnScroll(this.handleScroll)
this.OnKeyDown(this.handleKeyDown)
this.OnKeyUp(this.handleKeyUp)
this.SetRole(tomo.R("objects", "ScrollContainer"))
this.SetTag(sides.String(), true)
scrollContainer.box.OnScroll(scrollContainer.handleScroll)
scrollContainer.box.OnKeyDown(scrollContainer.handleKeyDown)
scrollContainer.box.OnKeyUp(scrollContainer.handleKeyUp)
scrollContainer.box.SetRole(tomo.R("objects", "ScrollContainer"))
scrollContainer.box.SetTag(sides.String(), true)
if sides == ScrollHorizontal {
this.SetAttr(tomo.ALayout(layouts.NewGrid(true)(true, false)))
scrollContainer.box.SetAttr(tomo.ALayout(layouts.NewGrid(true)(true, false)))
} else {
this.SetAttr(tomo.ALayout(layouts.NewGrid(true, false)(true, false)))
scrollContainer.box.SetAttr(tomo.ALayout(layouts.NewGrid(true, false)(true, false)))
}
return this
return scrollContainer
}
// GetBox returns the underlying box.
func (this *ScrollContainer) GetBox () tomo.Box {
return this.box
}
// SetRoot sets the root child of the ScrollContainer. There can only be one at
@ -87,7 +94,7 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
func (this *ScrollContainer) SetRoot (root tomo.ContentObject) {
if this.root != nil {
// remove root and close cookies
this.Remove(this.root)
this.box.Remove(this.root)
if this.horizontalCookie != nil {
this.horizontalCookie.Close()
this.horizontalCookie = nil
@ -102,11 +109,11 @@ func (this *ScrollContainer) SetRoot (root tomo.ContentObject) {
// insert root at the beginning (for keynav)
switch {
case this.vertical != nil:
this.Insert(root, this.vertical)
this.box.Insert(root, this.vertical)
case this.horizontal != nil:
this.Insert(root, this.horizontal)
this.box.Insert(root, this.horizontal)
default:
this.Add(root)
this.box.Add(root)
}
// link root and remember cookies
@ -191,7 +198,7 @@ func (this *ScrollContainer) handleScroll (x, y float64) bool {
}
func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
modifiers := this.Window().Modifiers()
modifiers := this.box.Window().Modifiers()
vector := image.Point { }
switch key {
case input.KeyPageUp: