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

Method renderSelect

core/textfield.go:1407–1449  ·  view source on GitHub ↗

renderSelect renders the selected region, if any, underneath the text

()

Source from the content-addressed store, hash-verified

1405
1406// renderSelect renders the selected region, if any, underneath the text
1407func (tf *TextField) renderSelect() {
1408 if !tf.hasSelection() {
1409 return
1410 }
1411 effst := max(tf.startPos, tf.selectStart)
1412 if effst >= tf.endPos {
1413 return
1414 }
1415 effed := min(tf.endPos, tf.selectEnd)
1416 if effed < tf.startPos {
1417 return
1418 }
1419 if effed <= effst {
1420 return
1421 }
1422
1423 spos := tf.charRenderPos(effst, false)
1424
1425 pc := &tf.Scene.PaintContext
1426 tsz := tf.relCharPos(effst, effed)
1427 if !tf.hasWordWrap() || tsz.Y == 0 {
1428 pc.FillBox(spos, math32.Vec2(tsz.X, tf.fontHeight), tf.SelectColor)
1429 return
1430 }
1431 ex := float32(tf.Geom.ContentBBox.Max.X)
1432 sx := float32(tf.Geom.ContentBBox.Min.X)
1433 ssi, _, _ := tf.renderAll.RuneSpanPos(effst)
1434 esi, _, _ := tf.renderAll.RuneSpanPos(effed)
1435 ep := tf.charRenderPos(effed, false)
1436
1437 pc.FillBox(spos, math32.Vec2(ex-spos.X, tf.fontHeight), tf.SelectColor)
1438
1439 spos.X = sx
1440 spos.Y += tf.renderAll.Spans[ssi+1].RelPos.Y - tf.renderAll.Spans[ssi].RelPos.Y
1441 for si := ssi + 1; si <= esi; si++ {
1442 if si < esi {
1443 pc.FillBox(spos, math32.Vec2(ex-spos.X, tf.fontHeight), tf.SelectColor)
1444 } else {
1445 pc.FillBox(spos, math32.Vec2(ep.X-spos.X, tf.fontHeight), tf.SelectColor)
1446 }
1447 spos.Y += tf.renderAll.Spans[si].RelPos.Y - tf.renderAll.Spans[si-1].RelPos.Y
1448 }
1449}
1450
1451// autoScroll scrolls the starting position to keep the cursor visible
1452func (tf *TextField) autoScroll() {

Callers 1

RenderMethod · 0.95

Calls 7

hasSelectionMethod · 0.95
charRenderPosMethod · 0.95
relCharPosMethod · 0.95
hasWordWrapMethod · 0.95
Vec2Function · 0.92
FillBoxMethod · 0.80
RuneSpanPosMethod · 0.80

Tested by

no test coverage detected