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

Method cursorSprite

core/textfield.go:1375–1404  ·  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 sets the On status of the cursor.

(on bool)

Source from the content-addressed store, hash-verified

1373// only rendered once with a vertical bar, and just activated and inactivated
1374// depending on render status). On sets the On status of the cursor.
1375func (tf *TextField) cursorSprite(on bool) *Sprite {
1376 sc := tf.Scene
1377 if sc == nil {
1378 return nil
1379 }
1380 ms := sc.Stage.Main
1381 if ms == nil {
1382 return nil // only MainStage has sprites
1383 }
1384 spnm := fmt.Sprintf("%v-%v", textFieldSpriteName, tf.fontHeight)
1385 sp, ok := ms.Sprites.SpriteByName(spnm)
1386 // TODO: figure out how to update caret color on color scheme change
1387 if !ok {
1388 bbsz := image.Point{int(math32.Ceil(tf.CursorWidth.Dots)), int(math32.Ceil(tf.fontHeight))}
1389 if bbsz.X < 2 { // at least 2
1390 bbsz.X = 2
1391 }
1392 sp = NewSprite(spnm, bbsz, image.Point{})
1393 sp.Active = on
1394 ibox := sp.Pixels.Bounds()
1395 draw.Draw(sp.Pixels, ibox, tf.CursorColor, image.Point{}, draw.Src)
1396 ms.Sprites.Add(sp)
1397 }
1398 if on {
1399 ms.Sprites.ActivateSprite(sp.Name)
1400 } else {
1401 ms.Sprites.InactivateSprite(sp.Name)
1402 }
1403 return sp
1404}
1405
1406// renderSelect renders the selected region, if any, underneath the text
1407func (tf *TextField) renderSelect() {

Callers 1

renderCursorMethod · 0.95

Calls 8

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

Tested by

no test coverage detected