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

Method updateSplits

core/splits.go:370–405  ·  view source on GitHub ↗

updateSplits ensures the Tiles, TileSplits and SubSplits are all configured properly, given the number of children.

()

Source from the content-addressed store, hash-verified

368// updateSplits ensures the Tiles, TileSplits and SubSplits
369// are all configured properly, given the number of children.
370func (sl *Splits) updateSplits() *Splits {
371 nc := len(sl.Children)
372 ntc, hasNonSpans := sl.tilesTotal()
373 if nc == 0 && ntc == 0 {
374 return sl
375 }
376 if nc > 0 && ntc != nc {
377 if ntc != 0 && hasNonSpans {
378 slog.Error("core.Splits: number of children for current Tiles != number of actual children, reverting to 1D", "children", nc, "tiles", ntc)
379 }
380 sl.Tiles = slicesx.SetLength(sl.Tiles, nc)
381 for i := range nc {
382 sl.Tiles[i] = TileSpan
383 }
384 }
385 nt := len(sl.Tiles)
386 sl.TileSplits = slicesx.SetLength(sl.TileSplits, nt)
387 sl.normSplits(sl.TileSplits)
388 sl.SubSplits = slicesx.SetLength(sl.SubSplits, nt)
389 for i, t := range sl.Tiles {
390 ssn := tileNumSubSplits[t]
391 ss := sl.SubSplits[i]
392 ss = slicesx.SetLength(ss, ssn)
393 switch t {
394 case TileSpan:
395 ss[0] = 1
396 case TileSplit:
397 sl.normSplits(ss)
398 case TileFirstLong, TileSecondLong:
399 sl.normSplits(ss[:2]) // first is cross-axis
400 sl.normSplits(ss[2:])
401 }
402 sl.SubSplits[i] = ss
403 }
404 return sl
405}
406
407// normSplits normalizes the given splits proportions,
408// using evenSplits if all zero

Callers 7

InitMethod · 0.95
SetSplitsMethod · 0.95
setSplitIndexMethod · 0.95
setHandlePosMethod · 0.95
restoreChildMethod · 0.95
SizeDownSetAllocsMethod · 0.95
PositionMethod · 0.95

Calls 4

tilesTotalMethod · 0.95
normSplitsMethod · 0.95
SetLengthFunction · 0.92
ErrorMethod · 0.65

Tested by

no test coverage detected