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

Method SetSlice

core/list.go:409–433  ·  view source on GitHub ↗

SetSlice sets the source slice that we are viewing. This ReMakes the view for this slice if different. Note: it is important to at least set an empty slice of the desired type at the start to enable initial configuration.

(sl any)

Source from the content-addressed store, hash-verified

407// Note: it is important to at least set an empty slice of
408// the desired type at the start to enable initial configuration.
409func (lb *ListBase) SetSlice(sl any) *ListBase {
410 if reflectx.AnyIsNil(sl) {
411 lb.Slice = nil
412 return lb
413 }
414 // TODO: a lot of this garbage needs to be cleaned up.
415 // New is not working!
416 newslc := false
417 if reflect.TypeOf(sl).Kind() != reflect.Pointer { // prevent crash on non-comparable
418 newslc = true
419 } else {
420 newslc = lb.Slice != sl
421 }
422 if !newslc {
423 lb.MakeIter = 0
424 return lb
425 }
426
427 lb.SetSliceBase()
428 lb.Slice = sl
429 lb.sliceUnderlying = reflectx.Underlying(reflect.ValueOf(lb.Slice))
430 lb.isArray = reflectx.NonPointerType(reflect.TypeOf(sl)).Kind() == reflect.Array
431 lb.elementValue = reflectx.SliceElementValue(sl)
432 return lb
433}
434
435// rowFromEventPos returns the widget row, slice index, and
436// whether the index is in slice range, for given event position.

Callers

nothing calls this directly

Calls 6

SetSliceBaseMethod · 0.95
AnyIsNilFunction · 0.92
UnderlyingFunction · 0.92
NonPointerTypeFunction · 0.92
SliceElementValueFunction · 0.92
KindMethod · 0.80

Tested by

no test coverage detected