RowGrabFocus grabs the focus for the first focusable widget in given row; returns that element or nil if not successful. Note: grid must have already rendered for focus to be grabbed!
(row int)
| 472 | // returns that element or nil if not successful. Note: grid must have |
| 473 | // already rendered for focus to be grabbed! |
| 474 | func (tb *Table) RowGrabFocus(row int) *WidgetBase { |
| 475 | if !tb.IsRowInBounds(row) || tb.InFocusGrab { // range check |
| 476 | return nil |
| 477 | } |
| 478 | nWidgPerRow, idxOff := tb.RowWidgetNs() |
| 479 | ridx := nWidgPerRow * row |
| 480 | lg := tb.ListGrid |
| 481 | // first check if we already have focus |
| 482 | for fli := 0; fli < tb.numVisibleFields; fli++ { |
| 483 | w := lg.Child(ridx + idxOff + fli).(Widget).AsWidget() |
| 484 | if w.StateIs(states.Focused) || w.ContainsFocus() { |
| 485 | return w |
| 486 | } |
| 487 | } |
| 488 | tb.InFocusGrab = true |
| 489 | defer func() { tb.InFocusGrab = false }() |
| 490 | for fli := 0; fli < tb.numVisibleFields; fli++ { |
| 491 | w := lg.Child(ridx + idxOff + fli).(Widget).AsWidget() |
| 492 | if w.CanFocus() { |
| 493 | w.SetFocusEvent() |
| 494 | return w |
| 495 | } |
| 496 | } |
| 497 | return nil |
| 498 | } |
| 499 | |
| 500 | // selectFieldValue sets SelectedField and SelectedValue and attempts to find |
| 501 | // corresponding row, setting SelectedIndex and selecting row if found; returns |
nothing calls this directly
no test coverage detected