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

Method renderLineNumber

texteditor/render.go:437–500  ·  view source on GitHub ↗

renderLineNumber renders given line number; called within context of other render. if defFill is true, it fills box color for default background color (use false for batch mode).

(ln int, defFill bool)

Source from the content-addressed store, hash-verified

435// if defFill is true, it fills box color for default background color (use false for
436// batch mode).
437func (ed *Editor) renderLineNumber(ln int, defFill bool) {
438 if !ed.hasLineNumbers || ed.Buffer == nil {
439 return
440 }
441 bb := ed.renderBBox()
442 tpos := math32.Vector2{
443 X: float32(bb.Min.X), // + spc.Pos().X
444 Y: ed.charEndPos(lexer.Pos{Ln: ln}).Y - ed.fontDescent,
445 }
446 if tpos.Y > float32(bb.Max.Y) {
447 return
448 }
449
450 sc := ed.Scene
451 sty := &ed.Styles
452 fst := sty.FontRender()
453 pc := &sc.PaintContext
454
455 fst.Background = nil
456 lfmt := fmt.Sprintf("%d", ed.lineNumberDigits)
457 lfmt = "%" + lfmt + "d"
458 lnstr := fmt.Sprintf(lfmt, ln+1)
459
460 if ed.CursorPos.Ln == ln {
461 fst.Color = colors.Scheme.Primary.Base
462 fst.Weight = styles.WeightBold
463 // need to open with new weight
464 fst.Font = paint.OpenFont(fst, &ed.Styles.UnitContext)
465 } else {
466 fst.Color = colors.Scheme.OnSurfaceVariant
467 }
468 ed.lineNumberRender.SetString(lnstr, fst, &sty.UnitContext, &sty.Text, true, 0, 0)
469
470 ed.lineNumberRender.Render(pc, tpos)
471
472 // render circle
473 lineColor := ed.Buffer.LineColors[ln]
474 if lineColor != nil {
475 start := ed.charStartPos(lexer.Pos{Ln: ln})
476 end := ed.charEndPos(lexer.Pos{Ln: ln + 1})
477
478 if ln < ed.NumLines-1 {
479 end.Y -= ed.lineHeight
480 }
481 if end.Y >= float32(bb.Max.Y) {
482 return
483 }
484
485 // starts at end of line number text
486 start.X = tpos.X + ed.lineNumberRender.BBox.Size().X
487 // ends at end of line number offset
488 end.X = float32(bb.Min.X) + ed.LineNumberOffset
489
490 r := (end.X - start.X) / 2
491 center := start.AddScalar(r)
492
493 // cut radius in half so that it doesn't look too big
494 r /= 2

Callers 1

renderAllLinesMethod · 0.95

Calls 11

renderBBoxMethod · 0.95
charEndPosMethod · 0.95
charStartPosMethod · 0.95
OpenFontFunction · 0.92
FontRenderMethod · 0.80
DrawCircleMethod · 0.80
SetStringMethod · 0.65
RenderMethod · 0.65
SizeMethod · 0.65
FillMethod · 0.65
AddScalarMethod · 0.45

Tested by

no test coverage detected