mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
Painter: Add text elision support (only right-hand side supported.)
Some window titles didn't fit on the taskbar buttons, so I needed a way to collapse the remaining part of the text into "..."
This commit is contained in:
parent
ce7341be87
commit
4533539e8a
5 changed files with 56 additions and 15 deletions
|
@ -160,15 +160,20 @@ bool Font::write_to_file(const String& path)
|
|||
|
||||
int Font::width(const String& string) const
|
||||
{
|
||||
if (string.is_empty())
|
||||
return width(string.characters(), string.length());
|
||||
}
|
||||
|
||||
int Font::width(const char* characters, int length) const
|
||||
{
|
||||
if (!length)
|
||||
return 0;
|
||||
|
||||
if (m_fixed_width)
|
||||
return string.length() * m_glyph_width;
|
||||
return length * m_glyph_width;
|
||||
|
||||
int width = 0;
|
||||
for (int i = 0; i < string.length(); ++i)
|
||||
width += glyph_width(string[i]) + 1;
|
||||
for (int i = 0; i < length; ++i)
|
||||
width += glyph_width(characters[i]) + 1;
|
||||
|
||||
return width - 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue