diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-10-26 00:13:07 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-26 00:13:07 +0200 |
commit | 59107a7cfe94867cd4012e4d1915e81462093d26 (patch) | |
tree | e7975d25e9e135c5d0b0414a1aa4a963c21ea8b2 /Libraries/LibGUI | |
parent | 5e5a7fbd40892fc776f2bc1d85d2320713c5f0f5 (diff) | |
download | serenity-59107a7cfe94867cd4012e4d1915e81462093d26.zip |
GTextEditor: Allow setting a custom font for each span
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r-- | Libraries/LibGUI/GTextEditor.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibGUI/GTextEditor.h | 1 |
2 files changed, 5 insertions, 1 deletions
diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp index 151f1c175b..64ca67ebb8 100644 --- a/Libraries/LibGUI/GTextEditor.cpp +++ b/Libraries/LibGUI/GTextEditor.cpp @@ -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); } } diff --git a/Libraries/LibGUI/GTextEditor.h b/Libraries/LibGUI/GTextEditor.h index 3952c03881..80e1cd5beb 100644 --- a/Libraries/LibGUI/GTextEditor.h +++ b/Libraries/LibGUI/GTextEditor.h @@ -180,6 +180,7 @@ public: GTextPosition start; GTextPosition end; Color color; + const Font* font { nullptr }; }; void set_spans(const Vector<Span>& spans) |