From 5ca9206f6591cfffa1d6fb139215d2e2ac2fd691 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 16 Mar 2023 00:24:40 -0400 Subject: [PATCH] DocumentContainer properly adopts children now --- elements/basic/documentContainer.go | 2 ++ elements/basic/list.go | 4 +--- elements/basic/scrollbar.go | 4 ++-- elements/basic/scrollcontainer.go | 2 +- elements/basic/slider.go | 4 ++-- elements/basic/switch.go | 3 --- elements/basic/textbox.go | 4 +--- elements/core/propagator.go | 6 +++--- elements/core/selectable.go | 2 +- 9 files changed, 13 insertions(+), 18 deletions(-) diff --git a/elements/basic/documentContainer.go b/elements/basic/documentContainer.go index 194488a..d82eaf5 100644 --- a/elements/basic/documentContainer.go +++ b/elements/basic/documentContainer.go @@ -49,6 +49,8 @@ func (element *DocumentContainer) Adopt (child elements.Element) { Element: child, }) + child.SetParent(element) + // refresh stale data element.reflectChildProperties() if element.core.HasImage() && !element.warping { diff --git a/elements/basic/list.go b/elements/basic/list.go index 03d0bd6..6ae823f 100644 --- a/elements/basic/list.go +++ b/elements/basic/list.go @@ -148,7 +148,7 @@ func (element *List) HandleMouseUp (x, y int, button input.Button) { element.pressed = false } -func (element *List) HandleMouseMove (x, y int) { +func (element *List) HandleMotion (x, y int) { if element.pressed { if element.selectUnderMouse(x, y) && element.core.HasImage() { element.draw() @@ -157,8 +157,6 @@ func (element *List) HandleMouseMove (x, y int) { } } -func (element *List) HandleMouseScroll (x, y int, deltaX, deltaY float64) { } - func (element *List) HandleKeyDown (key input.Key, modifiers input.Modifiers) { if !element.Enabled() { return } diff --git a/elements/basic/scrollbar.go b/elements/basic/scrollbar.go index 8ced13a..d554f80 100644 --- a/elements/basic/scrollbar.go +++ b/elements/basic/scrollbar.go @@ -115,13 +115,13 @@ func (element *ScrollBar) HandleMouseUp (x, y int, button input.Button) { } } -func (element *ScrollBar) HandleMouseMove (x, y int) { +func (element *ScrollBar) HandleMotion (x, y int) { if element.dragging { element.dragTo(image.Pt(x, y)) } } -func (element *ScrollBar) HandleMouseScroll (x, y int, deltaX, deltaY float64) { +func (element *ScrollBar) HandleScroll (x, y int, deltaX, deltaY float64) { if element.vertical { element.scrollBy(int(deltaY)) } else { diff --git a/elements/basic/scrollcontainer.go b/elements/basic/scrollcontainer.go index cf86e90..df02fde 100644 --- a/elements/basic/scrollcontainer.go +++ b/elements/basic/scrollcontainer.go @@ -147,7 +147,7 @@ func (element *ScrollContainer) SetConfig (new config.Config) { element.redoAll() } -func (element *ScrollContainer) HandleMouseScroll ( +func (element *ScrollContainer) HandleScroll ( x, y int, deltaX, deltaY float64, ) { diff --git a/elements/basic/slider.go b/elements/basic/slider.go index fef9fe4..7951af7 100644 --- a/elements/basic/slider.go +++ b/elements/basic/slider.go @@ -68,7 +68,7 @@ func (element *Slider) HandleMouseUp (x, y int, button input.Button) { element.redo() } -func (element *Slider) HandleMouseMove (x, y int) { +func (element *Slider) HandleMotion (x, y int) { if element.dragging { element.dragging = true element.value = element.valueFor(x, y) @@ -79,7 +79,7 @@ func (element *Slider) HandleMouseMove (x, y int) { } } -func (element *Slider) HandleMouseScroll (x, y int, deltaX, deltaY float64) { } +func (element *Slider) HandleScroll (x, y int, deltaX, deltaY float64) { } func (element *Slider) HandleKeyDown (key input.Key, modifiers input.Modifiers) { switch key { diff --git a/elements/basic/switch.go b/elements/basic/switch.go index 01462d2..1133524 100644 --- a/elements/basic/switch.go +++ b/elements/basic/switch.go @@ -67,9 +67,6 @@ func (element *Switch) HandleMouseUp (x, y int, button input.Button) { } } -func (element *Switch) HandleMouseMove (x, y int) { } -func (element *Switch) HandleMouseScroll (x, y int, deltaX, deltaY float64) { } - func (element *Switch) HandleKeyDown (key input.Key, modifiers input.Modifiers) { if key == input.KeyEnter { element.pressed = true diff --git a/elements/basic/textbox.go b/elements/basic/textbox.go index 4646324..393a0c7 100644 --- a/elements/basic/textbox.go +++ b/elements/basic/textbox.go @@ -80,7 +80,7 @@ func (element *TextBox) HandleMouseDown (x, y int, button input.Button) { } } -func (element *TextBox) HandleMouseMove (x, y int) { +func (element *TextBox) HandleMotion (x, y int) { if !element.Enabled() { return } if element.dragging { @@ -115,8 +115,6 @@ func (element *TextBox) HandleMouseUp (x, y int, button input.Button) { } } -func (element *TextBox) HandleMouseScroll (x, y int, deltaX, deltaY float64) { } - func (element *TextBox) HandleKeyDown(key input.Key, modifiers input.Modifiers) { if element.onKeyDown != nil && element.onKeyDown(key, modifiers) { return diff --git a/elements/core/propagator.go b/elements/core/propagator.go index 7afb353..b6e8dc5 100644 --- a/elements/core/propagator.go +++ b/elements/core/propagator.go @@ -212,10 +212,10 @@ func (propagator *Propagator) HandleMouseUp (x, y int, button input.Button) { } } -// HandleMouseMove propagates the mouse event to the element that was last +// HandleMotion propagates the mouse event to the element that was last // pressed down by the mouse if the mouse is currently being held down, else it // propagates the event to whichever element is underneath the mouse pointer. -func (propagator *Propagator) HandleMouseMove (x, y int) { +func (propagator *Propagator) HandleMotion (x, y int) { handled := false for _, child := range propagator.drags { if child, ok := child.(elements.MotionTarget); ok { @@ -234,7 +234,7 @@ func (propagator *Propagator) HandleMouseMove (x, y int) { // HandleScroll propagates the mouse event to the element under the mouse // pointer. -func (propagator *Propagator) HandleMouseScroll (x, y int, deltaX, deltaY float64) { +func (propagator *Propagator) HandleScroll (x, y int, deltaX, deltaY float64) { child := propagator.childAt(image.Pt(x, y)) if child, ok := child.(elements.ScrollTarget); ok { child.HandleScroll(x, y, deltaX, deltaY) diff --git a/elements/core/selectable.go b/elements/core/selectable.go index 903841a..37947aa 100644 --- a/elements/core/selectable.go +++ b/elements/core/selectable.go @@ -42,7 +42,7 @@ func (core *FocusableCore) Focused () (focused bool) { func (core *FocusableCore) Focus () { if !core.enabled || core.focused { return } parent := core.core.Parent() - if parent, ok := parent.(elements.FocusableParent); ok && parent != nil { + if parent, ok := parent.(elements.FocusableParent); ok { core.focused = parent.RequestFocus ( core.core.Outer().(elements.Focusable)) }