Example #1
0
// DefaultTextBoxLine overrides
func (t *CodeEditorLine) Paint(c gxui.Canvas) {
	font := t.ce.font
	rect := t.Size().Rect().OffsetX(t.caretWidth)
	controller := t.ce.controller
	runes := controller.LineRunes(t.lineIndex)
	start := controller.LineStart(t.lineIndex)
	end := controller.LineEnd(t.lineIndex)

	if start != end {
		lineSpan := interval.CreateIntData(start, end, nil)

		lineHeight := t.Size().H
		glyphWidth := font.GlyphMaxSize().W
		offsets := font.Layout(&gxui.TextBlock{
			Runes:     runes,
			AlignRect: rect,
			H:         gxui.AlignLeft,
			V:         gxui.AlignMiddle,
		})

		info := CodeEditorLinePaintInfo{
			LineSpan:     lineSpan,
			Runes:        runes, // TODO gxui.TextBlock?
			GlyphOffsets: offsets,
			GlyphWidth:   glyphWidth,
			LineHeight:   lineHeight,
			Font:         font,
		}

		// Background
		t.outer.PaintBackgroundSpans(c, info)

		// Selections
		if t.textbox.HasFocus() {
			t.outer.PaintSelections(c)
		}

		// Glyphs
		t.outer.PaintGlyphs(c, info)

		// Borders
		t.outer.PaintBorders(c, info)
	}

	// Carets
	if t.textbox.HasFocus() {
		t.outer.PaintCarets(c)
	}
}
Example #2
0
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())
		}
	}
}
Example #3
0
func (l *CodeSyntaxLayer) AddData(start, count int, data interface{}) {
	span := interval.CreateIntData(start, start+count, data)
	interval.Replace(&l.spans, span)
}