MCPcopy Create free account
hub / github.com/cogentcore/core / BindSelect

Method BindSelect

core/list.go:468–484  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
468func (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
486func (lb *ListBase) UpdateMaxWidths() {
487 lb.maxWidth = 0

Callers 5

InitMethod · 0.80
InitMethod · 0.80
InitMethod · 0.80
InitMethod · 0.80
InitMethod · 0.80

Calls 7

clickSelectEventMethod · 0.95
SendChangeMethod · 0.80
OnDoubleClickMethod · 0.80
sendKeyMethod · 0.80
CloseMethod · 0.65
SetReadOnlyMethod · 0.45
OnSelectMethod · 0.45

Tested by

no test coverage detected