94 lines
2.8 KiB
Go
94 lines
2.8 KiB
Go
package objects
|
|
|
|
import "image"
|
|
import "git.tebibyte.media/tomo/tomo"
|
|
import "git.tebibyte.media/tomo/tomo/event"
|
|
|
|
type abstractContainer struct {
|
|
box tomo.ContainerBox
|
|
}
|
|
|
|
func (this *abstractContainer) init (layout tomo.Layout, children ...tomo.Object) {
|
|
this.box = tomo.NewContainerBox()
|
|
this.SetLayout(layout)
|
|
for _, child := range children {
|
|
this.Add(child)
|
|
}
|
|
}
|
|
|
|
// GetBox returns the underlying box.
|
|
func (this *abstractContainer) GetBox () tomo.Box {
|
|
return this.box
|
|
}
|
|
|
|
// ContentBounds returns the bounds of the inner content of the container
|
|
// relative to the container's InnerBounds.
|
|
func (this *abstractContainer) ContentBounds () image.Rectangle {
|
|
return this.box.ContentBounds()
|
|
}
|
|
|
|
// ScrollTo shifts the origin of the container's content to the origin of the
|
|
// container's InnerBounds, offset by the given point.
|
|
func (this *abstractContainer) ScrollTo (position image.Point) {
|
|
this.box.ScrollTo(position)
|
|
}
|
|
|
|
// OnContentBoundsChange specifies a function to be called when the container's
|
|
// ContentBounds or InnerBounds changes.
|
|
func (this *abstractContainer) OnContentBoundsChange (callback func ()) event.Cookie {
|
|
return this.box.OnContentBoundsChange(callback)
|
|
}
|
|
|
|
// SetLayout sets the layout of the container.
|
|
func (this *abstractContainer) SetLayout (layout tomo.Layout) {
|
|
if layout == nil {
|
|
this.box.UnsetAttr(tomo.AttrKindLayout)
|
|
} else {
|
|
this.box.SetAttr(tomo.ALayout(layout))
|
|
}
|
|
}
|
|
|
|
// SetAlign sets the X and Y alignment of the container.
|
|
func (this *abstractContainer) SetAlign (x, y tomo.Align) {
|
|
this.box.SetAttr(tomo.AAlign(x, y))
|
|
}
|
|
|
|
// SetOverflow sets the X and Y overflow of the container.
|
|
func (this *abstractContainer) SetOverflow (x, y bool) {
|
|
this.box.SetAttr(tomo.AOverflow(x, y))
|
|
}
|
|
|
|
// Add appends a child object. If the object is already a child of another
|
|
// object, it will be removed from that object first.
|
|
func (this *abstractContainer) Add (object tomo.Object) {
|
|
this.box.Add(object)
|
|
}
|
|
|
|
// Remove removes a child object, if it is a child of this container.
|
|
func (this *abstractContainer) Remove (object tomo.Object) {
|
|
this.box.Remove(object)
|
|
}
|
|
|
|
// Insert inserts a child object before a specified object. If the before object
|
|
// is nil or is not contained within this container, the inserted object is
|
|
// appended. If the inserted object is already a child of another object, it
|
|
// will be removed from that object first.
|
|
func (this *abstractContainer) Insert (child tomo.Object, before tomo.Object) {
|
|
this.box.Insert(child, before)
|
|
}
|
|
|
|
// Clear removes all child objects.
|
|
func (this *abstractContainer) Clear () {
|
|
this.box.Clear()
|
|
}
|
|
|
|
// Len returns hte amount of child objects.
|
|
func (this *abstractContainer) Len () int {
|
|
return this.box.Len()
|
|
}
|
|
|
|
// At returns the child object at the specified index.
|
|
func (this *abstractContainer) At (index int) tomo.Object {
|
|
return this.box.At(index)
|
|
}
|