ScrollContainer no longer embeds ContainerBox
This commit is contained in:
parent
bc175bb5ae
commit
8b79fec1bd
@ -37,9 +37,11 @@ func (sides ScrollSide) String () string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ tomo.Object = new(ScrollContainer)
|
||||||
|
|
||||||
// ScrollContainer couples a ContentBox with one or two Scrollbars.
|
// ScrollContainer couples a ContentBox with one or two Scrollbars.
|
||||||
type ScrollContainer struct {
|
type ScrollContainer struct {
|
||||||
tomo.ContainerBox
|
box tomo.ContainerBox
|
||||||
|
|
||||||
root tomo.ContentObject
|
root tomo.ContentObject
|
||||||
horizontal *Scrollbar
|
horizontal *Scrollbar
|
||||||
@ -55,30 +57,35 @@ type ScrollContainer struct {
|
|||||||
|
|
||||||
// NewScrollContainer creates a new scroll container.
|
// NewScrollContainer creates a new scroll container.
|
||||||
func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
||||||
this := &ScrollContainer {
|
scrollContainer := &ScrollContainer {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
box: tomo.NewContainerBox(),
|
||||||
}
|
}
|
||||||
if sides.Vertical() {
|
if sides.Vertical() {
|
||||||
this.vertical = NewVerticalScrollbar()
|
scrollContainer.vertical = NewVerticalScrollbar()
|
||||||
this.vertical.OnValueChange(this.handleValueChange)
|
scrollContainer.vertical.OnValueChange(scrollContainer.handleValueChange)
|
||||||
this.Add(this.vertical)
|
scrollContainer.box.Add(scrollContainer.vertical)
|
||||||
}
|
}
|
||||||
if sides.Horizontal() {
|
if sides.Horizontal() {
|
||||||
this.horizontal = NewHorizontalScrollbar()
|
scrollContainer.horizontal = NewHorizontalScrollbar()
|
||||||
this.horizontal.OnValueChange(this.handleValueChange)
|
scrollContainer.horizontal.OnValueChange(scrollContainer.handleValueChange)
|
||||||
this.Add(this.horizontal)
|
scrollContainer.box.Add(scrollContainer.horizontal)
|
||||||
}
|
}
|
||||||
this.OnScroll(this.handleScroll)
|
scrollContainer.box.OnScroll(scrollContainer.handleScroll)
|
||||||
this.OnKeyDown(this.handleKeyDown)
|
scrollContainer.box.OnKeyDown(scrollContainer.handleKeyDown)
|
||||||
this.OnKeyUp(this.handleKeyUp)
|
scrollContainer.box.OnKeyUp(scrollContainer.handleKeyUp)
|
||||||
this.SetRole(tomo.R("objects", "ScrollContainer"))
|
scrollContainer.box.SetRole(tomo.R("objects", "ScrollContainer"))
|
||||||
this.SetTag(sides.String(), true)
|
scrollContainer.box.SetTag(sides.String(), true)
|
||||||
if sides == ScrollHorizontal {
|
if sides == ScrollHorizontal {
|
||||||
this.SetAttr(tomo.ALayout(layouts.NewGrid(true)(true, false)))
|
scrollContainer.box.SetAttr(tomo.ALayout(layouts.NewGrid(true)(true, false)))
|
||||||
} else {
|
} 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
|
// 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) {
|
func (this *ScrollContainer) SetRoot (root tomo.ContentObject) {
|
||||||
if this.root != nil {
|
if this.root != nil {
|
||||||
// remove root and close cookies
|
// remove root and close cookies
|
||||||
this.Remove(this.root)
|
this.box.Remove(this.root)
|
||||||
if this.horizontalCookie != nil {
|
if this.horizontalCookie != nil {
|
||||||
this.horizontalCookie.Close()
|
this.horizontalCookie.Close()
|
||||||
this.horizontalCookie = nil
|
this.horizontalCookie = nil
|
||||||
@ -102,11 +109,11 @@ func (this *ScrollContainer) SetRoot (root tomo.ContentObject) {
|
|||||||
// insert root at the beginning (for keynav)
|
// insert root at the beginning (for keynav)
|
||||||
switch {
|
switch {
|
||||||
case this.vertical != nil:
|
case this.vertical != nil:
|
||||||
this.Insert(root, this.vertical)
|
this.box.Insert(root, this.vertical)
|
||||||
case this.horizontal != nil:
|
case this.horizontal != nil:
|
||||||
this.Insert(root, this.horizontal)
|
this.box.Insert(root, this.horizontal)
|
||||||
default:
|
default:
|
||||||
this.Add(root)
|
this.box.Add(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
// link root and remember cookies
|
// 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 {
|
func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
|
||||||
modifiers := this.Window().Modifiers()
|
modifiers := this.box.Window().Modifiers()
|
||||||
vector := image.Point { }
|
vector := image.Point { }
|
||||||
switch key {
|
switch key {
|
||||||
case input.KeyPageUp:
|
case input.KeyPageUp:
|
||||||
|
Loading…
Reference in New Issue
Block a user