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

Method SetSlice

core/table.go:124–155  ·  view source on GitHub ↗

SetSlice sets the source slice that we are viewing.

(sl any)

Source from the content-addressed store, hash-verified

122
123// SetSlice sets the source slice that we are viewing.
124func (tb *Table) SetSlice(sl any) *Table {
125 if reflectx.AnyIsNil(sl) {
126 tb.Slice = nil
127 return tb
128 }
129 if tb.Slice == sl {
130 tb.MakeIter = 0
131 return tb
132 }
133
134 slpTyp := reflect.TypeOf(sl)
135 if slpTyp.Kind() != reflect.Pointer {
136 slog.Error("Table requires that you pass a pointer to a slice of struct elements, but type is not a Ptr", "type", slpTyp)
137 return tb
138 }
139 if slpTyp.Elem().Kind() != reflect.Slice {
140 slog.Error("Table requires that you pass a pointer to a slice of struct elements, but ptr doesn't point to a slice", "type", slpTyp.Elem())
141 return tb
142 }
143 eltyp := reflectx.NonPointerType(reflectx.SliceElementType(sl))
144 if eltyp.Kind() != reflect.Struct {
145 slog.Error("Table requires that you pass a slice of struct elements, but type is not a Struct", "type", eltyp.String())
146 return tb
147 }
148
149 tb.SetSliceBase()
150 tb.Slice = sl
151 tb.sliceUnderlying = reflectx.Underlying(reflect.ValueOf(tb.Slice))
152 tb.elementValue = reflectx.Underlying(reflectx.SliceElementValue(sl))
153 tb.cacheVisibleFields()
154 return tb
155}
156
157// cacheVisibleFields caches the visible struct fields.
158func (tb *Table) cacheVisibleFields() {

Callers 15

InitMethod · 0.95
mainFunction · 0.95
InitMethod · 0.45
TestTableFunction · 0.45
TestTableReadOnlyFunction · 0.45
makeFilesRowMethod · 0.45
editRecentPathsMethod · 0.45
TestListFunction · 0.45
TestListScrollFunction · 0.45
TestListStringsFunction · 0.45
TestListReadOnlyFunction · 0.45
InitMethod · 0.45

Implementers 1

_cogentcore_org_core_plot_plots_Tableyaegicore/symbols/cogentcore_org-core-

Calls 11

cacheVisibleFieldsMethod · 0.95
AnyIsNilFunction · 0.92
NonPointerTypeFunction · 0.92
SliceElementTypeFunction · 0.92
UnderlyingFunction · 0.92
SliceElementValueFunction · 0.92
KindMethod · 0.80
ElemMethod · 0.80
SetSliceBaseMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.65

Tested by 7

TestTableFunction · 0.36
TestTableReadOnlyFunction · 0.36
TestListFunction · 0.36
TestListScrollFunction · 0.36
TestListStringsFunction · 0.36
TestListReadOnlyFunction · 0.36
TestInlineListFunction · 0.36