Fixed cringe bug with focus requests being improperly handled
This commit is contained in:
parent
4f6f4e1f1a
commit
9c12cd7e18
@ -20,8 +20,6 @@ type Container struct {
|
|||||||
layout layouts.Layout
|
layout layouts.Layout
|
||||||
children []layouts.LayoutEntry
|
children []layouts.LayoutEntry
|
||||||
warping bool
|
warping bool
|
||||||
focused bool
|
|
||||||
focusable bool
|
|
||||||
flexible bool
|
flexible bool
|
||||||
|
|
||||||
config config.Wrapped
|
config config.Wrapped
|
||||||
@ -277,23 +275,23 @@ func (element *Container) forFlexible (callback func (child elements.Flexible) b
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (element *Container) reflectChildProperties () {
|
func (element *Container) reflectChildProperties () {
|
||||||
element.focusable = false
|
focusable := false
|
||||||
for _, entry := range element.children {
|
for _, entry := range element.children {
|
||||||
_, focusable := entry.Element.(elements.Focusable)
|
_, focusable := entry.Element.(elements.Focusable)
|
||||||
if focusable {
|
if focusable {
|
||||||
element.focusable = true
|
focusable = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !focusable && element.Focused() {
|
||||||
|
element.Propagator.HandleUnfocus()
|
||||||
|
}
|
||||||
|
|
||||||
element.flexible = false
|
element.flexible = false
|
||||||
element.forFlexible (func (elements.Flexible) bool {
|
element.forFlexible (func (elements.Flexible) bool {
|
||||||
element.flexible = true
|
element.flexible = true
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
if !element.focusable {
|
|
||||||
element.focused = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Container) childFocusRequestCallback (
|
func (element *Container) childFocusRequestCallback (
|
||||||
@ -302,23 +300,14 @@ func (element *Container) childFocusRequestCallback (
|
|||||||
granted bool,
|
granted bool,
|
||||||
) {
|
) {
|
||||||
if element.onFocusRequest != nil && element.onFocusRequest() {
|
if element.onFocusRequest != nil && element.onFocusRequest() {
|
||||||
element.focused = true
|
element.Propagator.HandleUnfocus()
|
||||||
element.unfocusAllChildren()
|
element.Propagator.HandleFocus(input.KeynavDirectionNeutral)
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
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 () {
|
func (element *Container) updateMinimumSize () {
|
||||||
margin := element.theme.Margin(theme.PatternBackground)
|
margin := element.theme.Margin(theme.PatternBackground)
|
||||||
padding := element.theme.Padding(theme.PatternBackground)
|
padding := element.theme.Padding(theme.PatternBackground)
|
||||||
|
@ -66,15 +66,21 @@ func (propagator *Propagator) HandleFocus (direction input.KeynavDirection) (acc
|
|||||||
// the first or last focusable element depending on the
|
// the first or last focusable element depending on the
|
||||||
// direction.
|
// direction.
|
||||||
switch direction {
|
switch direction {
|
||||||
case input.KeynavDirectionNeutral, input.KeynavDirectionForward:
|
case input.KeynavDirectionForward:
|
||||||
// if we recieve a neutral or forward direction, focus
|
// if we recieve a forward direction, focus the first
|
||||||
// the first focusable element.
|
// focusable element.
|
||||||
return propagator.focusFirstFocusableElement(direction)
|
return propagator.focusFirstFocusableElement(direction)
|
||||||
|
|
||||||
case input.KeynavDirectionBackward:
|
case input.KeynavDirectionBackward:
|
||||||
// if we recieve a backward direction, focus the last
|
// if we recieve a backward direction, focus the last
|
||||||
// focusable element.
|
// focusable element.
|
||||||
return propagator.focusLastFocusableElement(direction)
|
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 {
|
} else {
|
||||||
// an element is currently focused, so we need to move the
|
// an element is currently focused, so we need to move the
|
||||||
|
Reference in New Issue
Block a user