robust-parenting #12

Merged
sashakoshka merged 17 commits from robust-parenting into main 2023-03-15 22:34:08 -06:00
9 changed files with 13 additions and 18 deletions
Showing only changes of commit 5ca9206f65 - Show all commits

View File

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

View File

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

View File

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

View File

@ -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,
) {

View File

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

View File

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

View File

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

View File

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

View File

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