focusOnName processes key events to look for an element starting with given name
(e events.Event)
| 296 | |
| 297 | // focusOnName processes key events to look for an element starting with given name |
| 298 | func (fr *Frame) focusOnName(e events.Event) bool { |
| 299 | kf := keymap.Of(e.KeyChord()) |
| 300 | if DebugSettings.KeyEventTrace { |
| 301 | slog.Info("Layout FocusOnName", "widget", fr, "keyFunction", kf) |
| 302 | } |
| 303 | delay := e.Time().Sub(fr.focusNameTime) |
| 304 | fr.focusNameTime = e.Time() |
| 305 | if kf == keymap.FocusNext { // tab means go to next match -- don't worry about time |
| 306 | if fr.focusName == "" || delay > SystemSettings.LayoutFocusNameTabTime { |
| 307 | fr.focusName = "" |
| 308 | fr.focusNameLast = nil |
| 309 | return false |
| 310 | } |
| 311 | } else { |
| 312 | if delay > SystemSettings.LayoutFocusNameTimeout { |
| 313 | fr.focusName = "" |
| 314 | } |
| 315 | if !unicode.IsPrint(e.KeyRune()) || e.Modifiers() != 0 { |
| 316 | return false |
| 317 | } |
| 318 | sr := string(e.KeyRune()) |
| 319 | if fr.focusName == sr { |
| 320 | // re-search same letter |
| 321 | } else { |
| 322 | fr.focusName += sr |
| 323 | fr.focusNameLast = nil // only use last if tabbing |
| 324 | } |
| 325 | } |
| 326 | // e.SetHandled() |
| 327 | // fmt.Printf("searching for: %v last: %v\n", ly.FocusName, ly.FocusNameLast) |
| 328 | focel := childByLabelCanFocus(fr, fr.focusName, fr.focusNameLast) |
| 329 | if focel != nil { |
| 330 | em := fr.Events() |
| 331 | if em != nil { |
| 332 | em.setFocusEvent(focel.(Widget)) // this will also scroll by default! |
| 333 | } |
| 334 | fr.focusNameLast = focel |
| 335 | return true |
| 336 | } else { |
| 337 | if fr.focusNameLast == nil { |
| 338 | fr.focusName = "" // nothing being found |
| 339 | } |
| 340 | fr.focusNameLast = nil // start over |
| 341 | } |
| 342 | return false |
| 343 | } |
| 344 | |
| 345 | // childByLabelCanFocus uses breadth-first search to find |
| 346 | // the first focusable element within the layout whose Label (using |
no test coverage detected