Found a flaw in the focusing model, rectifying.
Still need to fix on X backend window, that will be in the next commit.
This commit is contained in:
parent
2f60abdfa3
commit
ef325d5161
@ -18,7 +18,15 @@ type FocusableParent interface {
|
|||||||
// keyboard focus. If the parent grants the request, the method will
|
// keyboard focus. If the parent grants the request, the method will
|
||||||
// return true and the child element should behave as if a HandleFocus
|
// return true and the child element should behave as if a HandleFocus
|
||||||
// call was made.
|
// call was made.
|
||||||
RequestFocus (child Focusable, direction input.KeynavDirection) (granted bool)
|
RequestFocus (child Focusable) (granted bool)
|
||||||
|
|
||||||
|
// RequestFocusMotion notifies the parent that a child element wants the
|
||||||
|
// focus to be moved to the next focusable element.
|
||||||
|
RequestFocusNext (child Focusable)
|
||||||
|
|
||||||
|
// RequestFocusMotion notifies the parent that a child element wants the
|
||||||
|
// focus to be moved to the previous focusable element.
|
||||||
|
RequestFocusPrevious (child Focusable)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlexibleParent represents a parent that accounts for elements with
|
// FlexibleParent represents a parent that accounts for elements with
|
||||||
|
@ -122,6 +122,43 @@ func (propagator *Propagator) HandleFocus (direction input.KeynavDirection) (acc
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequestFocus notifies the parent that a child element is requesting
|
||||||
|
// keyboard focus. If the parent grants the request, the method will
|
||||||
|
// return true and the child element should behave as if a HandleFocus
|
||||||
|
// call was made.
|
||||||
|
func (propagator *Propagator) RequestFocus (
|
||||||
|
child elements.Focusable,
|
||||||
|
) (
|
||||||
|
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) {
|
||||||
|
propagator.focused = true
|
||||||
|
granted = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// RequestFocusMotion notifies the parent that a child element wants the
|
||||||
|
// focus to be moved to the next focusable element.
|
||||||
|
func (propagator *Propagator) RequestFocusNext (child elements.Focusable) {
|
||||||
|
if !propagator.focused { return }
|
||||||
|
if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok {
|
||||||
|
parent.RequestFocusNext(propagator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RequestFocusMotion notifies the parent that a child element wants the
|
||||||
|
// focus to be moved to the previous focusable element.
|
||||||
|
func (propagator *Propagator) RequestFocusPrevious (child elements.Focusable) {
|
||||||
|
if !propagator.focused { return }
|
||||||
|
if parent, ok := propagator.core.Parent().(elements.FocusableParent); ok {
|
||||||
|
parent.RequestFocusPrevious(propagator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HandleDeselection causes this element to mark itself and all of its children
|
// HandleDeselection causes this element to mark itself and all of its children
|
||||||
// as unfocused.
|
// as unfocused.
|
||||||
func (propagator *Propagator) HandleUnfocus () {
|
func (propagator *Propagator) HandleUnfocus () {
|
||||||
|
@ -44,8 +44,7 @@ func (core *FocusableCore) Focus () {
|
|||||||
parent := core.core.Parent()
|
parent := core.core.Parent()
|
||||||
if parent, ok := parent.(elements.FocusableParent); ok && parent != nil {
|
if parent, ok := parent.(elements.FocusableParent); ok && parent != nil {
|
||||||
core.focused = parent.RequestFocus (
|
core.focused = parent.RequestFocus (
|
||||||
core.core.Outer().(elements.Focusable),
|
core.core.Outer().(elements.Focusable))
|
||||||
input.KeynavDirectionNeutral)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user