atomize-element-interface #2

Merged
sashakoshka merged 20 commits from atomize-element-interface into main 2023-01-16 17:24:23 +00:00
4 changed files with 37 additions and 37 deletions
Showing only changes of commit fb0795ec7b - Show all commits

View File

@ -69,13 +69,15 @@ func (window *Window) handleKeyPress (
} }
if key == tomo.KeyTab && modifiers.Alt { if key == tomo.KeyTab && modifiers.Alt {
if _, ok := window.child.(tomo.Selectable); ok { if child, ok := window.child.(tomo.Selectable); ok {
direction := tomo.SelectionDirectionForward direction := tomo.SelectionDirectionForward
if modifiers.Shift { if modifiers.Shift {
direction = tomo.SelectionDirectionBackward direction = tomo.SelectionDirectionBackward
} }
window.advanceSelectionInChild(direction) if !child.HandleSelection(direction) {
child.HandleDeselection()
}
} }
} else if child, ok := window.child.(tomo.KeyboardTarget); ok { } else if child, ok := window.child.(tomo.KeyboardTarget); ok {
// FIXME: pass correct value for repeated // FIXME: pass correct value for repeated
@ -83,17 +85,6 @@ func (window *Window) handleKeyPress (
} }
} }
func (window *Window) advanceSelectionInChild (direction tomo.SelectionDirection) {
child := window.child.(tomo.Selectable)
if child.Selected() {
if !child.HandleSelection(direction) {
child.HandleDeselection()
}
} else {
child.HandleSelection(tomo.SelectionDirectionNeutral)
}
}
func (window *Window) handleKeyRelease ( func (window *Window) handleKeyRelease (
connection *xgbutil.XUtil, connection *xgbutil.XUtil,
event xevent.KeyReleaseEvent, event xevent.KeyReleaseEvent,

View File

@ -79,6 +79,17 @@ const (
SelectionDirectionForward SelectionDirection = 1 SelectionDirectionForward SelectionDirection = 1
) )
// Canon returns a well-formed direction.
func (direction SelectionDirection) Canon () (canon SelectionDirection) {
if direction > 0 {
return SelectionDirectionForward
} else if direction == 0 {
return SelectionDirectionNeutral
} else {
return SelectionDirectionBackward
}
}
// Selectable represents an element that has keyboard navigation support. This // Selectable represents an element that has keyboard navigation support. This
// includes inputs, buttons, sliders, etc. as well as any elements that have // includes inputs, buttons, sliders, etc. as well as any elements that have
// children (so keyboard navigation events can be propagated downward). // children (so keyboard navigation events can be propagated downward).

View File

@ -103,16 +103,17 @@ func (element *Button) HandleSelection (
) ( ) (
accepted bool, accepted bool,
) { ) {
if direction == tomo.SelectionDirectionNeutral && element.enabled { if !element.enabled { return false }
element.selected = true if element.selected && direction != tomo.SelectionDirectionNeutral {
if element.core.HasImage() {
element.draw()
element.core.PushAll()
}
return true
} else {
return false return false
} }
element.selected = true
if element.core.HasImage() {
element.draw()
element.core.PushAll()
}
return true
} }
func (element *Button) HandleDeselection () { func (element *Button) HandleDeselection () {

View File

@ -244,44 +244,41 @@ func (element *Container) Select () {
// FIXME // FIXME
func (element *Container) HandleSelection (direction tomo.SelectionDirection) (ok bool) { func (element *Container) HandleSelection (direction tomo.SelectionDirection) (ok bool) {
if !element.selectable { return false } if !element.selectable { return false }
direction = direction.Canon()
firstSelected := element.firstSelected() firstSelected := element.firstSelected()
if firstSelected < 0 { if firstSelected < 0 {
found := false
switch direction { switch direction {
case tomo.SelectionDirectionNeutral, case tomo.SelectionDirectionBackward:
tomo.SelectionDirectionBackward:
element.forSelectableBackward (func (child tomo.Selectable) bool { element.forSelectableBackward (func (child tomo.Selectable) bool {
if child.HandleSelection ( if child.HandleSelection(direction) {
tomo.SelectionDirectionNeutral,
) {
element.selected = true element.selected = true
found = true
return false return false
} }
return true return true
}) })
return true
case tomo.SelectionDirectionForward: case tomo.SelectionDirectionNeutral, tomo.SelectionDirectionForward:
element.forSelectable (func (child tomo.Selectable) bool { element.forSelectable (func (child tomo.Selectable) bool {
if child.HandleSelection ( if child.HandleSelection(direction) {
tomo.SelectionDirectionNeutral,
) {
element.selected = true element.selected = true
found = true
return false return false
} }
return true return true
}) })
} }
return found
return false
} else { } else {
firstSelectedChild := firstSelectedChild :=
element.children[firstSelected].Element.(tomo.Selectable) element.children[firstSelected].Element.(tomo.Selectable)
step := 1
if direction < 0 { step = - 1 }
for index := firstSelected + step; for index := firstSelected + int(direction);
index < len(element.children) && index >= 0; index < len(element.children) && index >= 0;
index += step { index += int(direction) {
child, selectable := child, selectable :=
element.children[index]. element.children[index].
@ -294,7 +291,7 @@ func (element *Container) HandleSelection (direction tomo.SelectionDirection) (o
} }
} }
return return false
} }
func (element *Container) HandleDeselection () { func (element *Container) HandleDeselection () {