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

Method positionSplits

core/splits.go:718–799  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

716}
717
718func (sl *Splits) positionSplits() {
719 if sl.NumChildren() <= 1 {
720 return
721 }
722 if sl.Parts != nil {
723 sl.Parts.Geom.Size = sl.Geom.Size // inherit: allows bbox to include handle
724 }
725 sz := &sl.Geom.Size
726 dim := sl.Styles.Direction.Dim()
727 odim := dim.Other()
728 csz := sz.Alloc.Content
729 cszd := csz.Dim(dim)
730 cszo := csz.Dim(odim)
731 gap := sl.Styles.Gap.Dots().Floor()
732 gapd := gap.Dim(dim)
733 gapo := gap.Dim(odim)
734
735 hand := sl.Parts.Child(0).(*Handle)
736 hwd := hand.Geom.Size.Actual.Total.Dim(dim)
737 hht := hand.Geom.Size.Actual.Total.Dim(odim)
738 cszd -= float32(len(sl.TileSplits)-1) * (hwd + gapd)
739 hwdg := hwd + 0.5*gapd
740
741 setChildPos := func(idx int, dpos, opos float32) {
742 cwb := AsWidget(sl.Child(idx))
743 cwb.Geom.RelPos.SetDim(dim, dpos)
744 cwb.Geom.RelPos.SetDim(odim, opos)
745 }
746 setHandlePos := func(idx int, dpos, opos, lpos, mn, mx float32) {
747 hl := sl.Parts.Child(idx).(*Handle)
748 hl.Geom.RelPos.SetDim(dim, dpos)
749 hl.Geom.RelPos.SetDim(odim, opos)
750 hl.Pos = lpos
751 hl.Min = mn
752 hl.Max = mx
753 }
754
755 tpos := float32(0) // tile position
756 ci := 0
757 nt := len(sl.Tiles)
758 hi := nt - 1 // extra handles
759
760 for i, t := range sl.Tiles {
761 szt := math32.Round(sl.TileSplits[i] * cszd) // tile size, main axis
762 szcs := cszo - hwd - gapo // cross axis spilt
763 szs := szt - hwd - gapd
764 tn := tileNumElements[t]
765 if i > 0 {
766 setHandlePos(i-1, tpos-hwdg, .5*(cszo-hht), tpos, 0, cszd)
767 }
768 switch t {
769 case TileSpan:
770 setChildPos(ci, tpos, 0)
771 case TileSplit:
772 fcht := math32.Round(szcs * sl.SubSplits[i][0])
773 setHandlePos(hi, tpos+.5*(szt-hht), fcht+0.5*gapo, fcht, 0, szcs)
774 hi++
775 setChildPos(ci, tpos, 0)

Callers 1

PositionMethod · 0.95

Calls 9

RoundFunction · 0.92
AsWidgetFunction · 0.85
NumChildrenMethod · 0.80
ChildMethod · 0.80
DimMethod · 0.45
OtherMethod · 0.45
FloorMethod · 0.45
DotsMethod · 0.45
SetDimMethod · 0.45

Tested by

no test coverage detected