From 5cf0b162c048916c4da62b4cc3708854c3033f31 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 15 Apr 2023 00:02:30 -0400 Subject: [PATCH] Child property change events make more sense now --- backends/x/entity.go | 11 +++++++---- element.go | 6 +++--- elements/label.go | 3 +-- entity.go | 19 +++++++++---------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/backends/x/entity.go b/backends/x/entity.go index 53b62ce..d24008d 100644 --- a/backends/x/entity.go +++ b/backends/x/entity.go @@ -79,7 +79,8 @@ func (entity *entity) SetMinimumSize (width, height int) { if entity.parent == nil { entity.window.setMinimumSize(width, height) } else { - entity.parent.element.(tomo.Container).HandleChildMinimumSizeChange() + entity.parent.element.(tomo.Container). + HandleChildMinimumSizeChange(entity.element) } } @@ -172,10 +173,11 @@ func (entity *entity) FocusPrevious () { // ----------- FlexibleEntity ----------- // -func (entity *entity) NotifyFlexibleHeightChange (child tomo.Flexible) { +func (entity *entity) NotifyFlexibleHeightChange () { if entity.parent == nil { return } 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 () { if entity.parent == nil { return } if parent, ok := entity.parent.element.(tomo.ScrollableContainer); ok { - parent.HandleChildScrollBoundsChange() + parent.HandleChildScrollBoundsChange ( + entity.element.(tomo.Scrollable)) } } diff --git a/element.go b/element.go index 66b05a9..38a9ec2 100644 --- a/element.go +++ b/element.go @@ -28,7 +28,7 @@ type Container interface { // HandleChildMinimumSizeChange is called when a child's minimum size is // changed. - HandleChildMinimumSizeChange () + HandleChildMinimumSizeChange (child Element) } // Focusable represents an element that has keyboard navigation support. @@ -115,7 +115,7 @@ type FlexibleContainer interface { // HandleChildFlexibleHeightChange is called when the parameters // 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 @@ -145,7 +145,7 @@ type ScrollableContainer interface { // HandleChildScrollBoundsChange is called when the content bounds, // 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 diff --git a/elements/label.go b/elements/label.go index 2e1cca9..a0951c6 100644 --- a/elements/label.go +++ b/elements/label.go @@ -153,8 +153,7 @@ func (element *Label) updateMinimumSize () { em = element.theme.Padding(tomo.PatternBackground)[0] } width, height = em, element.drawer.LineHeight().Round() - // FIXME we shoudl not have to pass in the element here - element.entity.NotifyFlexibleHeightChange(element) + element.entity.NotifyFlexibleHeightChange() } else { bounds := element.drawer.LayoutBounds() width, height = bounds.Dx(), bounds.Dy() diff --git a/entity.go b/entity.go index 3a1b611..ff371c4 100644 --- a/entity.go +++ b/entity.go @@ -91,20 +91,19 @@ type FlexibleEntity interface { Entity // NotifyFlexibleHeightChange notifies the system that the parameters - // affecting a child's flexible height have changed. This method is - // expected to be called by flexible child element when their content - // changes. - NotifyFlexibleHeightChange (child Flexible) + // affecting the element's flexible height have changed. This method is + // expected to be called by flexible elements when their content changes. + NotifyFlexibleHeightChange () } // ScrollableEntity is given to elements that support the Scrollable interface. type ScrollableEntity interface { Entity - // NotifyScrollBoundsChange notifies the parent that a child's scroll - // content bounds or viewport bounds have changed. This is expected to - // be called by child elements when they change their supported scroll - // axes, their scroll position (either autonomously or as a result of a - // call to ScrollTo()), or their content size. - NotifyScrollBoundsChange (child Scrollable) + // NotifyScrollBoundsChange notifies the system that the element's + // scroll content bounds or viewport bounds have changed. This is + // expected to be called by scrollable elements when they change their + // supported scroll axes, their scroll position (either autonomously or + // as a result of a call to ScrollTo()), or their content size. + NotifyScrollBoundsChange () }