Child property change events make more sense now

This commit is contained in:
Sasha Koshka 2023-04-15 00:02:30 -04:00
parent 6e4310b9ad
commit 5cf0b162c0
4 changed files with 20 additions and 19 deletions

View File

@ -79,7 +79,8 @@ func (entity *entity) SetMinimumSize (width, height int) {
if entity.parent == nil { if entity.parent == nil {
entity.window.setMinimumSize(width, height) entity.window.setMinimumSize(width, height)
} else { } else {
entity.parent.element.(tomo.Container).HandleChildMinimumSizeChange() entity.parent.element.(tomo.Container).
HandleChildMinimumSizeChange(entity.element)
} }
} }
@ -172,10 +173,11 @@ func (entity *entity) FocusPrevious () {
// ----------- FlexibleEntity ----------- // // ----------- FlexibleEntity ----------- //
func (entity *entity) NotifyFlexibleHeightChange (child tomo.Flexible) { func (entity *entity) NotifyFlexibleHeightChange () {
if entity.parent == nil { return } if entity.parent == nil { return }
if parent, ok := entity.parent.element.(tomo.FlexibleContainer); ok { if parent, ok := entity.parent.element.(tomo.FlexibleContainer); ok {
parent.HandleChildFlexibleHeightChange() parent.HandleChildFlexibleHeightChange (
entity.element.(tomo.Flexible))
} }
} }
@ -184,6 +186,7 @@ func (entity *entity) NotifyFlexibleHeightChange (child tomo.Flexible) {
func (entity *entity) NotifyScrollBoundsChange () { func (entity *entity) NotifyScrollBoundsChange () {
if entity.parent == nil { return } if entity.parent == nil { return }
if parent, ok := entity.parent.element.(tomo.ScrollableContainer); ok { if parent, ok := entity.parent.element.(tomo.ScrollableContainer); ok {
parent.HandleChildScrollBoundsChange() parent.HandleChildScrollBoundsChange (
entity.element.(tomo.Scrollable))
} }
} }

View File

@ -28,7 +28,7 @@ type Container interface {
// HandleChildMinimumSizeChange is called when a child's minimum size is // HandleChildMinimumSizeChange is called when a child's minimum size is
// changed. // changed.
HandleChildMinimumSizeChange () HandleChildMinimumSizeChange (child Element)
} }
// Focusable represents an element that has keyboard navigation support. // Focusable represents an element that has keyboard navigation support.
@ -115,7 +115,7 @@ type FlexibleContainer interface {
// HandleChildFlexibleHeightChange is called when the parameters // HandleChildFlexibleHeightChange is called when the parameters
// affecting a child's flexible height are changed. // affecting a child's flexible height are changed.
HandleChildFlexibleHeightChange () HandleChildFlexibleHeightChange (child Flexible)
} }
// Scrollable represents an element that can be scrolled. It acts as a viewport // Scrollable represents an element that can be scrolled. It acts as a viewport
@ -145,7 +145,7 @@ type ScrollableContainer interface {
// HandleChildScrollBoundsChange is called when the content bounds, // HandleChildScrollBoundsChange is called when the content bounds,
// viewport bounds, or scroll axes of a child are changed. // viewport bounds, or scroll axes of a child are changed.
HandleChildScrollBoundsChange() HandleChildScrollBoundsChange (child Scrollable)
} }
// Collapsible represents an element who's minimum width and height can be // Collapsible represents an element who's minimum width and height can be

View File

@ -153,8 +153,7 @@ func (element *Label) updateMinimumSize () {
em = element.theme.Padding(tomo.PatternBackground)[0] em = element.theme.Padding(tomo.PatternBackground)[0]
} }
width, height = em, element.drawer.LineHeight().Round() width, height = em, element.drawer.LineHeight().Round()
// FIXME we shoudl not have to pass in the element here element.entity.NotifyFlexibleHeightChange()
element.entity.NotifyFlexibleHeightChange(element)
} else { } else {
bounds := element.drawer.LayoutBounds() bounds := element.drawer.LayoutBounds()
width, height = bounds.Dx(), bounds.Dy() width, height = bounds.Dx(), bounds.Dy()

View File

@ -91,20 +91,19 @@ type FlexibleEntity interface {
Entity Entity
// NotifyFlexibleHeightChange notifies the system that the parameters // NotifyFlexibleHeightChange notifies the system that the parameters
// affecting a child's flexible height have changed. This method is // affecting the element's flexible height have changed. This method is
// expected to be called by flexible child element when their content // expected to be called by flexible elements when their content changes.
// changes. NotifyFlexibleHeightChange ()
NotifyFlexibleHeightChange (child Flexible)
} }
// ScrollableEntity is given to elements that support the Scrollable interface. // ScrollableEntity is given to elements that support the Scrollable interface.
type ScrollableEntity interface { type ScrollableEntity interface {
Entity Entity
// NotifyScrollBoundsChange notifies the parent that a child's scroll // NotifyScrollBoundsChange notifies the system that the element's
// content bounds or viewport bounds have changed. This is expected to // scroll content bounds or viewport bounds have changed. This is
// be called by child elements when they change their supported scroll // expected to be called by scrollable elements when they change their
// axes, their scroll position (either autonomously or as a result of a // supported scroll axes, their scroll position (either autonomously or
// call to ScrollTo()), or their content size. // as a result of a call to ScrollTo()), or their content size.
NotifyScrollBoundsChange (child Scrollable) NotifyScrollBoundsChange ()
} }