mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +00:00
GTextEditor: Allow setting a custom font for each span
This commit is contained in:
parent
5e5a7fbd40
commit
59107a7cfe
2 changed files with 5 additions and 1 deletions
|
@ -371,6 +371,7 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
||||||
int advance = font().glyph_width(' ') + font().glyph_spacing();
|
int advance = font().glyph_width(' ') + font().glyph_spacing();
|
||||||
Rect character_rect = { visual_line_rect.location(), { font().glyph_width(' '), line_height() } };
|
Rect character_rect = { visual_line_rect.location(), { font().glyph_width(' '), line_height() } };
|
||||||
for (int i = 0; i < visual_line_text.length(); ++i) {
|
for (int i = 0; i < visual_line_text.length(); ++i) {
|
||||||
|
const Font* font = &this->font();
|
||||||
Color color;
|
Color color;
|
||||||
int physical_line = line_index;
|
int physical_line = line_index;
|
||||||
int physical_column = start_of_visual_line + i;
|
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)))
|
if (!span.contains(GTextPosition(physical_line, physical_column)))
|
||||||
continue;
|
continue;
|
||||||
color = span.color;
|
color = span.color;
|
||||||
|
if (span.font)
|
||||||
|
font = span.font;
|
||||||
break;
|
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);
|
character_rect.move_by(advance, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,7 @@ public:
|
||||||
GTextPosition start;
|
GTextPosition start;
|
||||||
GTextPosition end;
|
GTextPosition end;
|
||||||
Color color;
|
Color color;
|
||||||
|
const Font* font { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_spans(const Vector<Span>& spans)
|
void set_spans(const Vector<Span>& spans)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue