atomize-element-interface #3

Merged
sashakoshka merged 10 commits from atomize-element-interface into main 2023-01-17 12:33:23 -07:00
8 changed files with 91 additions and 34 deletions
Showing only changes of commit e94e170a04 - Show all commits

View File

@ -89,7 +89,7 @@ func (window *Window) Adopt (child tomo.Element) {
child.SetParentHooks (tomo.ParentHooks { child.SetParentHooks (tomo.ParentHooks {
Draw: window.childDrawCallback, Draw: window.childDrawCallback,
MinimumSizeChange: window.childMinimumSizeChangeCallback, MinimumSizeChange: window.childMinimumSizeChangeCallback,
ExpandingHeightChange: window.resizeChildToFit, FlexibleHeightChange: window.resizeChildToFit,
SelectionRequest: window.childSelectionRequestCallback, SelectionRequest: window.childSelectionRequestCallback,
}) })

View File

@ -16,9 +16,9 @@ type ParentHooks struct {
// event. // event.
MinimumSizeChange func (width, height int) MinimumSizeChange func (width, height int)
// ExpandingHeightChange is called when the parameters affecting the // FlexibleHeightChange is called when the parameters affecting the
// element's expanding height have changed. // element's expanding height have changed.
ExpandingHeightChange func () FlexibleHeightChange func ()
// SelectionRequest is called when the child element element wants // SelectionRequest is called when the child element element wants
// itself to be selected. If the parent element chooses to grant the // itself to be selected. If the parent element chooses to grant the
@ -46,11 +46,11 @@ func (hooks ParentHooks) RunMinimumSizeChange (width, height int) {
} }
} }
// RunExpandingHeightChange runs the ExpandingHeightChange hook if it is not // RunFlexibleHeightChange runs the ExpandingHeightChange hook if it is not
// nil. If it is nil, it does nothing. // nil. If it is nil, it does nothing.
func (hooks ParentHooks) RunExpandingHeightChange () { func (hooks ParentHooks) RunFlexibleHeightChange () {
if hooks.ExpandingHeightChange != nil { if hooks.FlexibleHeightChange != nil {
hooks.ExpandingHeightChange() hooks.FlexibleHeightChange()
} }
} }

View File

@ -18,6 +18,7 @@ type Container struct {
warping bool warping bool
selected bool selected bool
selectable bool selectable bool
flexible bool
} }
// NewContainer creates a new container. // NewContainer creates a new container.
@ -49,6 +50,7 @@ func (element *Container) Adopt (child tomo.Element, expand bool) {
MinimumSizeChange: func (int, int) { MinimumSizeChange: func (int, int) {
element.updateMinimumSize() element.updateMinimumSize()
}, },
FlexibleHeightChange: element.updateMinimumSize,
SelectionRequest: func () (granted bool) { SelectionRequest: func () (granted bool) {
child, selectable := child.(tomo.Selectable) child, selectable := child.(tomo.Selectable)
if !selectable { return } if !selectable { return }