1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:37:45 +00:00

Userland: Move text wrapping/elision into the new TextLayout :^)

This class now contains all the fun bits about laying out text in a
rect. It will handle line wrapping at a certain width, cutting off lines
that don't fit the given rect, and handling text elision.
Painter::draw_text now internally uses this.

Future work here would be not laying out text twice (once actually
preparing the lines to be rendered and once to get the bounding box),
and possibly adding left elision if necessary.

Additionally, this commit makes the Utf32View versions of
Painter::draw_text convert to Utf8View internally. The intention is to
completely remove those versions, but they're kept at the moment to keep
the scope of this PR small.
This commit is contained in:
sin-ack 2021-07-25 21:20:11 +00:00 committed by Ali Mohammad Pur
parent a5a32fbcce
commit e11940fd01
14 changed files with 371 additions and 238 deletions

View file

@ -33,10 +33,9 @@ public:
bool is_autosize() const { return m_autosize; }
void set_autosize(bool);
bool is_word_wrap() const { return m_word_wrap; }
void set_word_wrap(bool);
int preferred_height() const;
Gfx::IntRect text_rect(size_t line = 0) const;
Gfx::IntRect text_rect() const;
protected:
explicit Label(String text = {});
@ -46,15 +45,12 @@ protected:
private:
void size_to_fit();
void wrap_text();
String m_text;
RefPtr<Gfx::Bitmap> m_icon;
Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center };
bool m_should_stretch_icon { false };
bool m_autosize { false };
bool m_word_wrap { false };
Vector<String> m_lines;
};
}