From 3332ce01ce6a3149fa9c819845244f20bb9bd338 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 6 Jan 2023 13:41:51 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibGUI/Label.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGUI/Label.cpp b/Userland/Libraries/LibGUI/Label.cpp index a4b88b20402..d222e76b3b4 100644 --- a/Userland/Libraries/LibGUI/Label.cpp +++ b/Userland/Libraries/LibGUI/Label.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include REGISTER_WIDGET(GUI, Label) @@ -117,7 +116,7 @@ void Label::size_to_fit() int Label::text_calculated_preferred_height() const { - return static_cast(ceilf(Gfx::TextLayout(font(), Utf8View { m_text }, text_rect().to_type()).bounding_rect(Gfx::TextWrapping::Wrap).height())); + return static_cast(ceilf(font().preferred_line_height()) * (m_text.count("\n"sv) + 1)); } Optional Label::calculated_preferred_size() const