BindSelect makes the list a read-only selection list and then binds its events to its scene and its current selection index to the given value. It will send an [events.Change] event when the user changes the selection row.
(val *int)
| 466 | // binds its events to its scene and its current selection index to the given value. |
| 467 | // It will send an [events.Change] event when the user changes the selection row. |
| 468 | func (lb *ListBase) BindSelect(val *int) *ListBase { |
| 469 | lb.SetReadOnly(true) |
| 470 | lb.OnSelect(func(e events.Event) { |
| 471 | *val = lb.SelectedIndex |
| 472 | lb.SendChange(e) |
| 473 | }) |
| 474 | lb.OnDoubleClick(func(e events.Event) { |
| 475 | if lb.clickSelectEvent(e) { |
| 476 | *val = lb.SelectedIndex |
| 477 | lb.Scene.sendKey(keymap.Accept, e) // activate OK button |
| 478 | if lb.Scene.Stage.Type == DialogStage { |
| 479 | lb.Scene.Close() // also directly close dialog for value dialogs without OK button |
| 480 | } |
| 481 | } |
| 482 | }) |
| 483 | return lb |
| 484 | } |
| 485 | |
| 486 | func (lb *ListBase) UpdateMaxWidths() { |
| 487 | lb.maxWidth = 0 |
no test coverage detected