Re-organized module structure
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
package containers
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/input"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||
|
||||
// Container is an element capable of containg other elements, and arranging
|
||||
@@ -17,8 +16,8 @@ type Container struct {
|
||||
*core.Propagator
|
||||
core core.CoreControl
|
||||
|
||||
layout layouts.Layout
|
||||
children []layouts.LayoutEntry
|
||||
layout tomo.Layout
|
||||
children []tomo.LayoutEntry
|
||||
warping bool
|
||||
|
||||
config config.Wrapped
|
||||
@@ -29,9 +28,9 @@ type Container struct {
|
||||
}
|
||||
|
||||
// NewContainer creates a new container.
|
||||
func NewContainer (layout layouts.Layout) (element *Container) {
|
||||
func NewContainer (layout tomo.Layout) (element *Container) {
|
||||
element = &Container { }
|
||||
element.theme.Case = theme.C("containers", "container")
|
||||
element.theme.Case = theme.C("tomo", "container")
|
||||
element.Core, element.core = core.NewCore(element, element.redoAll)
|
||||
element.Propagator = core.NewPropagator(element, element.core)
|
||||
element.SetLayout(layout)
|
||||
@@ -39,7 +38,7 @@ func NewContainer (layout layouts.Layout) (element *Container) {
|
||||
}
|
||||
|
||||
// SetLayout sets the layout of this container.
|
||||
func (element *Container) SetLayout (layout layouts.Layout) {
|
||||
func (element *Container) SetLayout (layout tomo.Layout) {
|
||||
element.layout = layout
|
||||
element.updateMinimumSize()
|
||||
if element.core.HasImage() {
|
||||
@@ -51,17 +50,17 @@ func (element *Container) SetLayout (layout layouts.Layout) {
|
||||
// Adopt adds a new child element to the container. If expand is set to true,
|
||||
// the element will expand (instead of contract to its minimum size), in
|
||||
// whatever way is defined by the current layout.
|
||||
func (element *Container) Adopt (child elements.Element, expand bool) {
|
||||
if child0, ok := child.(elements.Themeable); ok {
|
||||
func (element *Container) Adopt (child tomo.Element, expand bool) {
|
||||
if child0, ok := child.(tomo.Themeable); ok {
|
||||
child0.SetTheme(element.theme.Theme)
|
||||
}
|
||||
if child0, ok := child.(elements.Configurable); ok {
|
||||
if child0, ok := child.(tomo.Configurable); ok {
|
||||
child0.SetConfig(element.config.Config)
|
||||
}
|
||||
child.SetParent(element)
|
||||
|
||||
// add child
|
||||
element.children = append (element.children, layouts.LayoutEntry {
|
||||
element.children = append (element.children, tomo.LayoutEntry {
|
||||
Element: child,
|
||||
Expand: expand,
|
||||
})
|
||||
@@ -98,7 +97,7 @@ func (element *Container) Warp (callback func ()) {
|
||||
|
||||
// Disown removes the given child from the container if it is contained within
|
||||
// it.
|
||||
func (element *Container) Disown (child elements.Element) {
|
||||
func (element *Container) Disown (child tomo.Element) {
|
||||
for index, entry := range element.children {
|
||||
if entry.Element == child {
|
||||
element.clearChildEventHandlers(entry.Element)
|
||||
@@ -116,11 +115,11 @@ func (element *Container) Disown (child elements.Element) {
|
||||
}
|
||||
}
|
||||
|
||||
func (element *Container) clearChildEventHandlers (child elements.Element) {
|
||||
func (element *Container) clearChildEventHandlers (child tomo.Element) {
|
||||
child.DrawTo(nil, image.Rectangle { }, nil)
|
||||
child.SetParent(nil)
|
||||
|
||||
if child, ok := child.(elements.Focusable); ok {
|
||||
if child, ok := child.(tomo.Focusable); ok {
|
||||
if child.Focused() {
|
||||
child.HandleUnfocus()
|
||||
}
|
||||
@@ -142,8 +141,8 @@ func (element *Container) DisownAll () {
|
||||
}
|
||||
|
||||
// Children returns a slice containing this element's children.
|
||||
func (element *Container) Children () (children []elements.Element) {
|
||||
children = make([]elements.Element, len(element.children))
|
||||
func (element *Container) Children () (children []tomo.Element) {
|
||||
children = make([]tomo.Element, len(element.children))
|
||||
for index, entry := range element.children {
|
||||
children[index] = entry.Element
|
||||
}
|
||||
@@ -157,14 +156,14 @@ func (element *Container) CountChildren () (count int) {
|
||||
|
||||
// Child returns the child at the specified index. If the index is out of
|
||||
// bounds, this method will return nil.
|
||||
func (element *Container) Child (index int) (child elements.Element) {
|
||||
func (element *Container) Child (index int) (child tomo.Element) {
|
||||
if index < 0 || index > len(element.children) { return }
|
||||
return element.children[index].Element
|
||||
}
|
||||
|
||||
// ChildAt returns the child that contains the specified x and y coordinates. If
|
||||
// there are no children at the coordinates, this method will return nil.
|
||||
func (element *Container) ChildAt (point image.Point) (child elements.Element) {
|
||||
func (element *Container) ChildAt (point image.Point) (child tomo.Element) {
|
||||
for _, entry := range element.children {
|
||||
if point.In(entry.Bounds) {
|
||||
child = entry.Element
|
||||
@@ -207,7 +206,7 @@ func (element *Container) redoAll () {
|
||||
|
||||
// NotifyMinimumSizeChange notifies the container that the minimum size of a
|
||||
// child element has changed.
|
||||
func (element *Container) NotifyMinimumSizeChange (child elements.Element) {
|
||||
func (element *Container) NotifyMinimumSizeChange (child tomo.Element) {
|
||||
element.updateMinimumSize()
|
||||
element.redoAll()
|
||||
element.core.DamageAll()
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package containers
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||
|
||||
type DocumentContainer struct {
|
||||
@@ -14,7 +13,7 @@ type DocumentContainer struct {
|
||||
*core.Propagator
|
||||
core core.CoreControl
|
||||
|
||||
children []layouts.LayoutEntry
|
||||
children []tomo.LayoutEntry
|
||||
scroll image.Point
|
||||
warping bool
|
||||
contentBounds image.Rectangle
|
||||
@@ -28,24 +27,24 @@ type DocumentContainer struct {
|
||||
// NewDocumentContainer creates a new document container.
|
||||
func NewDocumentContainer () (element *DocumentContainer) {
|
||||
element = &DocumentContainer { }
|
||||
element.theme.Case = theme.C("containers", "documentContainer")
|
||||
element.theme.Case = theme.C("tomo", "documentContainer")
|
||||
element.Core, element.core = core.NewCore(element, element.redoAll)
|
||||
element.Propagator = core.NewPropagator(element, element.core)
|
||||
return
|
||||
}
|
||||
|
||||
// Adopt adds a new child element to the container.
|
||||
func (element *DocumentContainer) Adopt (child elements.Element) {
|
||||
func (element *DocumentContainer) Adopt (child tomo.Element) {
|
||||
// set event handlers
|
||||
if child0, ok := child.(elements.Themeable); ok {
|
||||
if child0, ok := child.(tomo.Themeable); ok {
|
||||
child0.SetTheme(element.theme.Theme)
|
||||
}
|
||||
if child0, ok := child.(elements.Configurable); ok {
|
||||
if child0, ok := child.(tomo.Configurable); ok {
|
||||
child0.SetConfig(element.config.Config)
|
||||
}
|
||||
|
||||
// add child
|
||||
element.children = append (element.children, layouts.LayoutEntry {
|
||||
element.children = append (element.children, tomo.LayoutEntry {
|
||||
Element: child,
|
||||
})
|
||||
|
||||
@@ -80,7 +79,7 @@ func (element *DocumentContainer) Warp (callback func ()) {
|
||||
|
||||
// Disown removes the given child from the container if it is contained within
|
||||
// it.
|
||||
func (element *DocumentContainer) Disown (child elements.Element) {
|
||||
func (element *DocumentContainer) Disown (child tomo.Element) {
|
||||
for index, entry := range element.children {
|
||||
if entry.Element == child {
|
||||
element.clearChildEventHandlers(entry.Element)
|
||||
@@ -98,11 +97,11 @@ func (element *DocumentContainer) Disown (child elements.Element) {
|
||||
}
|
||||
}
|
||||
|
||||
func (element *DocumentContainer) clearChildEventHandlers (child elements.Element) {
|
||||
func (element *DocumentContainer) clearChildEventHandlers (child tomo.Element) {
|
||||
child.DrawTo(nil, image.Rectangle { }, nil)
|
||||
child.SetParent(nil)
|
||||
|
||||
if child, ok := child.(elements.Focusable); ok {
|
||||
if child, ok := child.(tomo.Focusable); ok {
|
||||
if child.Focused() {
|
||||
child.HandleUnfocus()
|
||||
}
|
||||
@@ -124,8 +123,8 @@ func (element *DocumentContainer) DisownAll () {
|
||||
}
|
||||
|
||||
// Children returns a slice containing this element's children.
|
||||
func (element *DocumentContainer) Children () (children []elements.Element) {
|
||||
children = make([]elements.Element, len(element.children))
|
||||
func (element *DocumentContainer) Children () (children []tomo.Element) {
|
||||
children = make([]tomo.Element, len(element.children))
|
||||
for index, entry := range element.children {
|
||||
children[index] = entry.Element
|
||||
}
|
||||
@@ -139,14 +138,14 @@ func (element *DocumentContainer) CountChildren () (count int) {
|
||||
|
||||
// Child returns the child at the specified index. If the index is out of
|
||||
// bounds, this method will return nil.
|
||||
func (element *DocumentContainer) Child (index int) (child elements.Element) {
|
||||
func (element *DocumentContainer) Child (index int) (child tomo.Element) {
|
||||
if index < 0 || index > len(element.children) { return }
|
||||
return element.children[index].Element
|
||||
}
|
||||
|
||||
// ChildAt returns the child that contains the specified x and y coordinates. If
|
||||
// there are no children at the coordinates, this method will return nil.
|
||||
func (element *DocumentContainer) ChildAt (point image.Point) (child elements.Element) {
|
||||
func (element *DocumentContainer) ChildAt (point image.Point) (child tomo.Element) {
|
||||
for _, entry := range element.children {
|
||||
if point.In(entry.Bounds) {
|
||||
child = entry.Element
|
||||
@@ -178,7 +177,7 @@ func (element *DocumentContainer) redoAll () {
|
||||
artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
|
||||
|
||||
element.partition()
|
||||
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok {
|
||||
if parent, ok := element.core.Parent().(tomo.ScrollableParent); ok {
|
||||
parent.NotifyScrollBoundsChange(element)
|
||||
}
|
||||
if element.onScrollBoundsChange != nil {
|
||||
@@ -205,7 +204,7 @@ func (element *DocumentContainer) partition () {
|
||||
|
||||
// NotifyMinimumSizeChange notifies the container that the minimum size of a
|
||||
// child element has changed.
|
||||
func (element *DocumentContainer) NotifyMinimumSizeChange (child elements.Element) {
|
||||
func (element *DocumentContainer) NotifyMinimumSizeChange (child tomo.Element) {
|
||||
element.redoAll()
|
||||
element.core.DamageAll()
|
||||
}
|
||||
@@ -214,7 +213,7 @@ func (element *DocumentContainer) NotifyMinimumSizeChange (child elements.Elemen
|
||||
// affecting a child's flexible height have changed. This method is
|
||||
// expected to be called by flexible child element when their content
|
||||
// changes.
|
||||
func (element *DocumentContainer) NotifyFlexibleHeightChange (child elements.Flexible) {
|
||||
func (element *DocumentContainer) NotifyFlexibleHeightChange (child tomo.Flexible) {
|
||||
element.redoAll()
|
||||
element.core.DamageAll()
|
||||
}
|
||||
@@ -300,7 +299,7 @@ func (element *DocumentContainer) doLayout () {
|
||||
if width < bounds.Dx() {
|
||||
width = bounds.Dx()
|
||||
}
|
||||
if typedChild, ok := entry.Element.(elements.Flexible); ok {
|
||||
if typedChild, ok := entry.Element.(tomo.Flexible); ok {
|
||||
height = typedChild.FlexibleHeightFor(width)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package containers
|
||||
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/input"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
|
||||
|
||||
// ScrollContainer is a container that is capable of holding a scrollable
|
||||
// element.
|
||||
@@ -16,9 +16,9 @@ type ScrollContainer struct {
|
||||
*core.Propagator
|
||||
core core.CoreControl
|
||||
|
||||
child elements.Scrollable
|
||||
horizontal *basicElements.ScrollBar
|
||||
vertical *basicElements.ScrollBar
|
||||
child tomo.Scrollable
|
||||
horizontal *elements.ScrollBar
|
||||
vertical *elements.ScrollBar
|
||||
|
||||
config config.Wrapped
|
||||
theme theme.Wrapped
|
||||
@@ -31,12 +31,12 @@ type ScrollContainer struct {
|
||||
// bars.
|
||||
func NewScrollContainer (horizontal, vertical bool) (element *ScrollContainer) {
|
||||
element = &ScrollContainer { }
|
||||
element.theme.Case = theme.C("containers", "scrollContainer")
|
||||
element.theme.Case = theme.C("tomo", "scrollContainer")
|
||||
element.Core, element.core = core.NewCore(element, element.redoAll)
|
||||
element.Propagator = core.NewPropagator(element, element.core)
|
||||
|
||||
if horizontal {
|
||||
element.horizontal = basicElements.NewScrollBar(false)
|
||||
element.horizontal = elements.NewScrollBar(false)
|
||||
element.setUpChild(element.horizontal)
|
||||
element.horizontal.OnScroll (func (viewport image.Point) {
|
||||
if element.child != nil {
|
||||
@@ -50,7 +50,7 @@ func NewScrollContainer (horizontal, vertical bool) (element *ScrollContainer) {
|
||||
})
|
||||
}
|
||||
if vertical {
|
||||
element.vertical = basicElements.NewScrollBar(true)
|
||||
element.vertical = elements.NewScrollBar(true)
|
||||
element.setUpChild(element.vertical)
|
||||
element.vertical.OnScroll (func (viewport image.Point) {
|
||||
if element.child != nil {
|
||||
@@ -70,7 +70,7 @@ func NewScrollContainer (horizontal, vertical bool) (element *ScrollContainer) {
|
||||
// Adopt adds a scrollable element to the scroll container. The container can
|
||||
// only contain one scrollable element at a time, and when a new one is adopted
|
||||
// it replaces the last one.
|
||||
func (element *ScrollContainer) Adopt (child elements.Scrollable) {
|
||||
func (element *ScrollContainer) Adopt (child tomo.Scrollable) {
|
||||
// disown previous child if it exists
|
||||
if element.child != nil {
|
||||
element.disownChild(child)
|
||||
@@ -90,20 +90,20 @@ func (element *ScrollContainer) Adopt (child elements.Scrollable) {
|
||||
}
|
||||
}
|
||||
|
||||
func (element *ScrollContainer) setUpChild (child elements.Element) {
|
||||
func (element *ScrollContainer) setUpChild (child tomo.Element) {
|
||||
child.SetParent(element)
|
||||
if child, ok := child.(elements.Themeable); ok {
|
||||
if child, ok := child.(tomo.Themeable); ok {
|
||||
child.SetTheme(element.theme.Theme)
|
||||
}
|
||||
if child, ok := child.(elements.Configurable); ok {
|
||||
if child, ok := child.(tomo.Configurable); ok {
|
||||
child.SetConfig(element.config.Config)
|
||||
}
|
||||
}
|
||||
|
||||
func (element *ScrollContainer) disownChild (child elements.Scrollable) {
|
||||
func (element *ScrollContainer) disownChild (child tomo.Scrollable) {
|
||||
child.DrawTo(nil, image.Rectangle { }, nil)
|
||||
child.SetParent(nil)
|
||||
if child, ok := child.(elements.Focusable); ok {
|
||||
if child, ok := child.(tomo.Focusable); ok {
|
||||
if child.Focused() {
|
||||
child.HandleUnfocus()
|
||||
}
|
||||
@@ -112,14 +112,14 @@ func (element *ScrollContainer) disownChild (child elements.Scrollable) {
|
||||
|
||||
// NotifyMinimumSizeChange notifies the container that the minimum size of a
|
||||
// child element has changed.
|
||||
func (element *ScrollContainer) NotifyMinimumSizeChange (child elements.Element) {
|
||||
func (element *ScrollContainer) NotifyMinimumSizeChange (child tomo.Element) {
|
||||
element.redoAll()
|
||||
element.core.DamageAll()
|
||||
}
|
||||
|
||||
// NotifyScrollBoundsChange notifies the container that the scroll bounds or
|
||||
// axes of a child have changed.
|
||||
func (element *ScrollContainer) NotifyScrollBoundsChange (child elements.Scrollable) {
|
||||
func (element *ScrollContainer) NotifyScrollBoundsChange (child tomo.Scrollable) {
|
||||
element.updateEnabled()
|
||||
viewportBounds := element.child.ScrollViewportBounds()
|
||||
contentBounds := element.child.ScrollContentBounds()
|
||||
@@ -165,7 +165,7 @@ func (element *ScrollContainer) CountChildren () (count int) {
|
||||
|
||||
// Child returns the child at the specified index. If the index is out of
|
||||
// bounds, this method will return nil.
|
||||
func (element *ScrollContainer) Child (index int) (child elements.Element) {
|
||||
func (element *ScrollContainer) Child (index int) (child tomo.Element) {
|
||||
switch index {
|
||||
case 0: return element.child
|
||||
case 1:
|
||||
|
||||
Reference in New Issue
Block a user