mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
LibGUI: Simplify GUI::Label preferred height calculation
No need to use a TextLayout here, we can just count the number of lines and multiply that by the font's preferred line height. In addition to being much simpler, it also fixes a bug where labels were got too tall if we calculated their preferred height before assigning a final width to them.
This commit is contained in:
parent
ef7eb60f22
commit
3332ce01ce
1 changed files with 1 additions and 2 deletions
|
@ -10,7 +10,6 @@
|
|||
#include <LibGUI/Painter.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibGfx/TextLayout.h>
|
||||
#include <LibGfx/TextWrapping.h>
|
||||
|
||||
REGISTER_WIDGET(GUI, Label)
|
||||
|
@ -117,7 +116,7 @@ void Label::size_to_fit()
|
|||
|
||||
int Label::text_calculated_preferred_height() const
|
||||
{
|
||||
return static_cast<int>(ceilf(Gfx::TextLayout(font(), Utf8View { m_text }, text_rect().to_type<float>()).bounding_rect(Gfx::TextWrapping::Wrap).height()));
|
||||
return static_cast<int>(ceilf(font().preferred_line_height()) * (m_text.count("\n"sv) + 1));
|
||||
}
|
||||
|
||||
Optional<UISize> Label::calculated_preferred_size() const
|
||||
|
|
Loading…
Add table
Reference in a new issue