robust-parenting #12
@ -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 {
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
) {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user