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

Method cursorSprite

texteditor/cursor.go:127–154  ·  view source on GitHub ↗

cursorSprite returns the sprite for the cursor, which is only rendered once with a vertical bar, and just activated and inactivated depending on render status.

(on bool)

Source from the content-addressed store, hash-verified

125// only rendered once with a vertical bar, and just activated and inactivated
126// depending on render status.
127func (ed *Editor) cursorSprite(on bool) *core.Sprite {
128 sc := ed.Scene
129 if sc == nil {
130 return nil
131 }
132 ms := sc.Stage.Main
133 if ms == nil {
134 return nil // only MainStage has sprites
135 }
136 spnm := ed.cursorSpriteName()
137 sp, ok := ms.Sprites.SpriteByName(spnm)
138 if !ok {
139 bbsz := image.Point{int(math32.Ceil(ed.CursorWidth.Dots)), int(math32.Ceil(ed.fontHeight))}
140 if bbsz.X < 2 { // at least 2
141 bbsz.X = 2
142 }
143 sp = core.NewSprite(spnm, bbsz, image.Point{})
144 ibox := sp.Pixels.Bounds()
145 draw.Draw(sp.Pixels, ibox, ed.CursorColor, image.Point{}, draw.Src)
146 ms.Sprites.Add(sp)
147 }
148 if on {
149 ms.Sprites.ActivateSprite(sp.Name)
150 } else {
151 ms.Sprites.InactivateSprite(sp.Name)
152 }
153 return sp
154}

Callers 1

renderCursorMethod · 0.95

Calls 9

cursorSpriteNameMethod · 0.95
CeilFunction · 0.92
NewSpriteFunction · 0.92
SpriteByNameMethod · 0.80
ActivateSpriteMethod · 0.80
InactivateSpriteMethod · 0.80
DrawMethod · 0.65
AddMethod · 0.65
BoundsMethod · 0.45

Tested by

no test coverage detected