Hocus focus

This commit is contained in:
2023-01-30 17:01:47 -05:00
parent 35870951a2
commit 801c3ef6f5
15 changed files with 367 additions and 355 deletions

View File

@@ -124,14 +124,14 @@ func (window *Window) handleKeyPress (
modifiers.NumberPad = numberPad
if key == tomo.KeyTab && modifiers.Alt {
if child, ok := window.child.(tomo.Selectable); ok {
direction := tomo.SelectionDirectionForward
if child, ok := window.child.(tomo.Focusable); ok {
direction := tomo.KeynavDirectionForward
if modifiers.Shift {
direction = tomo.SelectionDirectionBackward
direction = tomo.KeynavDirectionBackward
}
if !child.HandleSelection(direction) {
child.HandleDeselection()
if !child.HandleFocus(direction) {
child.HandleUnfocus()
}
}
} else if child, ok := window.child.(tomo.KeyboardTarget); ok {

View File

@@ -87,11 +87,11 @@ func (window *Window) Adopt (child tomo.Element) {
if previousChild, ok := window.child.(tomo.Flexible); ok {
previousChild.OnFlexibleHeightChange(nil)
}
if previousChild, ok := window.child.(tomo.Selectable); ok {
previousChild.OnSelectionRequest(nil)
previousChild.OnSelectionMotionRequest(nil)
if previousChild.Selected() {
previousChild.HandleDeselection()
if previousChild, ok := window.child.(tomo.Focusable); ok {
previousChild.OnFocusRequest(nil)
previousChild.OnFocusMotionRequest(nil)
if previousChild.Focused() {
previousChild.HandleUnfocus()
}
}
@@ -100,8 +100,8 @@ func (window *Window) Adopt (child tomo.Element) {
if newChild, ok := child.(tomo.Flexible); ok {
newChild.OnFlexibleHeightChange(window.resizeChildToFit)
}
if newChild, ok := child.(tomo.Selectable); ok {
newChild.OnSelectionRequest(window.childSelectionRequestCallback)
if newChild, ok := child.(tomo.Focusable); ok {
newChild.OnFocusRequest(window.childSelectionRequestCallback)
}
if child != nil {
child.OnDamage(window.childDrawCallback)
@@ -282,20 +282,20 @@ func (window *Window) childMinimumSizeChangeCallback (width, height int) {
}
func (window *Window) childSelectionRequestCallback () (granted bool) {
if child, ok := window.child.(tomo.Selectable); ok {
child.HandleSelection(tomo.SelectionDirectionNeutral)
if child, ok := window.child.(tomo.Focusable); ok {
child.HandleFocus(tomo.KeynavDirectionNeutral)
}
return true
}
func (window *Window) childSelectionMotionRequestCallback (
direction tomo.SelectionDirection,
direction tomo.KeynavDirection,
) (
granted bool,
) {
if child, ok := window.child.(tomo.Selectable); ok {
if !child.HandleSelection(direction) {
child.HandleDeselection()
if child, ok := window.child.(tomo.Focusable); ok {
if !child.HandleFocus(direction) {
child.HandleUnfocus()
}
return true
}