diff --git a/backends/x/window.go b/backends/x/window.go index 5af14e2..92b2251 100644 --- a/backends/x/window.go +++ b/backends/x/window.go @@ -94,6 +94,30 @@ func (window *window) NotifyMinimumSizeChange (child elements.Element) { window.childMinimumSizeChangeCallback(child.MinimumSize()) } +func (window *window) RequestFocus ( + child elements.Focusable, +) ( + granted bool, +) { + return true +} + +func (window *window) RequestFocusNext (child elements.Focusable) { + if child, ok := window.child.(elements.Focusable); ok { + if !child.HandleFocus(input.KeynavDirectionForward) { + child.HandleUnfocus() + } + } +} + +func (window *window) RequestFocusPrevious (child elements.Focusable) { + if child, ok := window.child.(elements.Focusable); ok { + if !child.HandleFocus(input.KeynavDirectionBackward) { + child.HandleUnfocus() + } + } +} + func (window *window) Adopt (child elements.Element) { // disown previous child if window.child != nil { @@ -305,27 +329,6 @@ func (window *window) childMinimumSizeChangeCallback (width, height int) (resize return false } -func (window *window) childSelectionRequestCallback () (granted bool) { - if _, ok := window.child.(elements.Focusable); ok { - return true - } - return false -} - -func (window *window) childSelectionMotionRequestCallback ( - direction input.KeynavDirection, -) ( - granted bool, -) { - if child, ok := window.child.(elements.Focusable); ok { - if !child.HandleFocus(direction) { - child.HandleUnfocus() - } - return true - } - return true -} - func (window *window) pushRegion (region image.Rectangle) { if window.xCanvas == nil { panic("whoopsie!!!!!!!!!!!!!!") } image, ok := window.xCanvas.SubImage(region).(*xgraphics.Image) diff --git a/elements/container.go b/elements/container.go index ec09d8a..6b6235b 100644 --- a/elements/container.go +++ b/elements/container.go @@ -1,7 +1,5 @@ package elements -import "git.tebibyte.media/sashakoshka/tomo/input" - // Parent represents a type capable of containing child elements. type Parent interface { // NotifyMinimumSizeChange notifies the container that a child element's diff --git a/elements/core/propagator.go b/elements/core/propagator.go index 76284d6..d0f7bc0 100644 --- a/elements/core/propagator.go +++ b/elements/core/propagator.go @@ -51,8 +51,7 @@ func (propagator *Propagator) Focus () { parent := propagator.core.Parent() if parent, ok := parent.(elements.FocusableParent); ok && parent != nil { propagator.focused = parent.RequestFocus ( - propagator.core.Outer().(elements.Focusable), - input.KeynavDirectionNeutral) + propagator.core.Outer().(elements.Focusable)) } } @@ -131,9 +130,8 @@ func (propagator *Propagator) RequestFocus ( ) ( granted bool, ) { - // TODO implement this, and also implement it for the x backend window if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok { - if parent.RequestFocus(propagator) { + if parent.RequestFocus(propagator.core.Outer().(elements.Focusable)) { propagator.focused = true granted = true } @@ -146,7 +144,7 @@ func (propagator *Propagator) RequestFocus ( func (propagator *Propagator) RequestFocusNext (child elements.Focusable) { if !propagator.focused { return } if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok { - parent.RequestFocusNext(propagator) + parent.RequestFocusNext(propagator.core.Outer().(elements.Focusable)) } } @@ -155,7 +153,7 @@ func (propagator *Propagator) RequestFocusNext (child elements.Focusable) { func (propagator *Propagator) RequestFocusPrevious (child elements.Focusable) { if !propagator.focused { return } if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok { - parent.RequestFocusPrevious(propagator) + parent.RequestFocusPrevious(propagator.core.Outer().(elements.Focusable)) } }