GTextEditor: Allow setting a custom font for each span

This commit is contained in:
Andreas Kling 2019-10-26 00:13:07 +02:00
parent 5e5a7fbd40
commit 59107a7cfe
Notes: sideshowbarker 2024-07-19 11:32:33 +09:00
2 changed files with 5 additions and 1 deletions

View File

@ -371,6 +371,7 @@ void GTextEditor::paint_event(GPaintEvent& event)
int advance = font().glyph_width(' ') + font().glyph_spacing();
Rect character_rect = { visual_line_rect.location(), { font().glyph_width(' '), line_height() } };
for (int i = 0; i < visual_line_text.length(); ++i) {
const Font* font = &this->font();
Color color;
int physical_line = line_index;
int physical_column = start_of_visual_line + i;
@ -379,9 +380,11 @@ void GTextEditor::paint_event(GPaintEvent& event)
if (!span.contains(GTextPosition(physical_line, physical_column)))
continue;
color = span.color;
if (span.font)
font = span.font;
break;
}
painter.draw_text(character_rect, visual_line_text.substring_view(i, 1), m_text_alignment, color);
painter.draw_text(character_rect, visual_line_text.substring_view(i, 1), *font, m_text_alignment, color);
character_rect.move_by(advance, 0);
}
}

View File

@ -180,6 +180,7 @@ public:
GTextPosition start;
GTextPosition end;
Color color;
const Font* font { nullptr };
};
void set_spans(const Vector<Span>& spans)