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 {
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))
}
}

View File

@ -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

View File

@ -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()

View File

@ -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 ()
}