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)
| 407 | // Note: it is important to at least set an empty slice of |
| 408 | // the desired type at the start to enable initial configuration. |
| 409 | func (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. |
nothing calls this directly
no test coverage detected