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

Method SplitAtLR

paint/span.go:639–661  ·  view source on GitHub ↗

SplitAt splits current span at given index, returning a new span with remainder after index -- space is trimmed from both spans and relative positions updated, for LR direction

(idx int)

Source from the content-addressed store, hash-verified

637// remainder after index -- space is trimmed from both spans and relative
638// positions updated, for LR direction
639func (sr *Span) SplitAtLR(idx int) *Span {
640 if idx <= 0 || idx >= len(sr.Text)-1 { // shouldn't happen
641 return nil
642 }
643 nsr := Span{Text: sr.Text[idx:], Render: sr.Render[idx:], Dir: sr.Dir, HasDeco: sr.HasDeco}
644 sr.Text = sr.Text[:idx]
645 sr.Render = sr.Render[:idx]
646 sr.LastPos.X = sr.Render[idx-1].RelPosAfterLR()
647 // sr.TrimSpaceLR()
648 // nsr.TrimSpaceLeftLR() // don't trim right!
649 // go back and find latest face and color -- each sr must start with valid one
650 if len(nsr.Render) > 0 {
651 nrr0 := &(nsr.Render[0])
652 face, color := sr.LastFont()
653 if nrr0.Face == nil {
654 nrr0.Face = face
655 }
656 if nrr0.Color == nil {
657 nrr0.Color = color
658 }
659 }
660 return &nsr
661}
662
663// LastFont finds the last font and color from given span
664func (sr *Span) LastFont() (face font.Face, color image.Image) {

Callers 1

LayoutStdLRMethod · 0.80

Calls 2

LastFontMethod · 0.95
RelPosAfterLRMethod · 0.80

Tested by

no test coverage detected