def* Canvas key_nav {direction} { if {[llength $@selection] == 1} { set group "" set distences "" set distencesx "" set distencesy "" switch $direction { up { foreach item $@children { if {$_($item:y1) < $_($@selection:y1)} { lappend group $item lappend distences [expr abs ($_($item:x1) - $_($@selection:x1))] #lappend distencesx [expr abs ($_($item:x1) - $_($@selection:x1))] #lappend distencesy [expr abs ($_($item:y1) - $_($@selection:y1))] } } } down { foreach item $@children { if {$_($item:y1) > $_($@selection:y1)} { lappend group $item lappend distences [expr abs ($_($item:x1) - $_($@selection:x1))] #lappend distencesx [expr abs ($_($item:x1) - $_($@selection:x1))] #lappend distencesy [expr abs ($_($item:y1) - $_($@selection:y1))] } } } right { foreach item $@children { if {$_($item:x1) > $_($@selection:x1)} { lappend group $item lappend distences [expr abs ($_($item:y1) - $_($@selection:y1))] #lappend distencesy [expr abs ($_($item:y1) - $_($@selection:y1))] #lappend distencesx [expr abs ($_($item:x1) - $_($@selection:x1))] } } } left { foreach item $@children { if {$_($item:x1) < $_($@selection:x1)} { lappend group $item lappend distences [expr abs ($_($item:y1) - $_($@selection:y1))] #lappend distencesy [expr abs ($_($item:y1) - $_($@selection:y1))] #lappend distencesx [expr abs ($_($item:x1) - $_($@selection:x1))] } } } } if {[llength $group] > 0} { set closestx 0 #set closest [expr abs([lindex $distencesx 0] + [lindex $distencesy 0])/2] set closest [lindex $distences 0] for {set i 1} {$i<[llength $distencesx]} {incr i} { #set val [expr abs([lindex $distencesx $i] + [lindex $distencesy $i])/2] set val [lindex $distences $i] if {$val < $closest} {set closest [lindex $distences $i]} } set index [lsearch $distences $closest] set next [lindex $group $index] } else { set next $@selection } $self deselect_all $next selected?= 1 set @selection $next } }