// DefaultTextBoxLine overrides func (l *CodeEditorLine) Paint(c gxui.Canvas) { font := l.ce.Font() controller := l.ce.Controller() if l.lineIndex >= controller.LineCount() { // The controller's text differs slightly from the // CodeEditor's lines - best to avoid the panic on // the next few lines. return } start := controller.LineStart(l.lineIndex) end := controller.LineEnd(l.lineIndex) var info CodeEditorLinePaintInfo if start != end { info = CodeEditorLinePaintInfo{ LineSpan: interval.CreateIntData(start, end, nil), Runes: controller.LineRunes(l.lineIndex), GlyphOffsets: l.offsets(font), GlyphWidth: font.GlyphMaxSize().W, LineHeight: l.Size().H, Font: font, } l.outer.PaintBackgroundSpans(c, info) l.outer.PaintEditorSelections(c, info) l.outer.PaintGlyphs(c, info) l.outer.PaintBorders(c, info) } if l.textbox.HasFocus() { l.outer.PaintEditorCarets(c, info) } }
func (l *CodeSyntaxLayer) UpdateSpans(runeCount int, edits []TextBoxEdit) { min := 0 max := runeCount for _, e := range edits { if l == nil { continue } for j, s := range l.spans { at := e.At start, end := s.Range() if start >= at { start = math.Clamp(start+e.Delta, min, max) } if end > at { end = math.Clamp(end+e.Delta, min, max) } if end < start { end = start } l.spans[j] = interval.CreateIntData(start, end, s.Data()) } } }
func (l *CodeSyntaxLayer) AddData(start, count int, data interface{}) { span := interval.CreateIntData(start, start+count, data) interval.Replace(&l.spans, span) }