Fixed cringe bug with focus requests being improperly handled

This commit is contained in:
Sasha Koshka 2023-03-04 02:20:48 -05:00
parent 4f6f4e1f1a
commit 9c12cd7e18
2 changed files with 16 additions and 21 deletions

View File

@ -20,8 +20,6 @@ type Container struct {
layout layouts.Layout
children []layouts.LayoutEntry
warping bool
focused bool
focusable bool
flexible bool
config config.Wrapped
@ -277,23 +275,23 @@ func (element *Container) forFlexible (callback func (child elements.Flexible) b
}
func (element *Container) reflectChildProperties () {
element.focusable = false
focusable := false
for _, entry := range element.children {
_, focusable := entry.Element.(elements.Focusable)
if focusable {
element.focusable = true
focusable = true
break
}
}
if !focusable && element.Focused() {
element.Propagator.HandleUnfocus()
}
element.flexible = false
element.forFlexible (func (elements.Flexible) bool {
element.flexible = true
return false
})
if !element.focusable {
element.focused = false
}
}
func (element *Container) childFocusRequestCallback (
@ -302,23 +300,14 @@ func (element *Container) childFocusRequestCallback (
granted bool,
) {
if element.onFocusRequest != nil && element.onFocusRequest() {
element.focused = true
element.unfocusAllChildren()
element.Propagator.HandleUnfocus()
element.Propagator.HandleFocus(input.KeynavDirectionNeutral)
return true
} else {
return false
}
}
func (element *Container) unfocusAllChildren() {
for _, entry := range element.children {
child, focusable := entry.Element.(elements.Focusable)
if focusable && child.Focused() {
child.HandleUnfocus()
}
}
}
func (element *Container) updateMinimumSize () {
margin := element.theme.Margin(theme.PatternBackground)
padding := element.theme.Padding(theme.PatternBackground)

View File

@ -66,15 +66,21 @@ func (propagator *Propagator) HandleFocus (direction input.KeynavDirection) (acc
// the first or last focusable element depending on the
// direction.
switch direction {
case input.KeynavDirectionNeutral, input.KeynavDirectionForward:
// if we recieve a neutral or forward direction, focus
// the first focusable element.
case input.KeynavDirectionForward:
// if we recieve a forward direction, focus the first
// focusable element.
return propagator.focusFirstFocusableElement(direction)
case input.KeynavDirectionBackward:
// if we recieve a backward direction, focus the last
// focusable element.
return propagator.focusLastFocusableElement(direction)
case input.KeynavDirectionNeutral:
// if we recieve a neutral direction, just focus this
// element and nothing else.
propagator.focused = true
return true
}
} else {
// an element is currently focused, so we need to move the