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)
| 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. |
| 1375 | func (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 |
| 1407 | func (tf *TextField) renderSelect() { |
no test coverage detected