summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-01-06 13:41:51 +0100
committerAndreas Kling <kling@serenityos.org>2023-01-06 13:43:04 +0100
commit3332ce01ce6a3149fa9c819845244f20bb9bd338 (patch)
tree0c89c06933a66f9ad187edfdef477e3f0532fe4c
parentef7eb60f22761b8bdff0804263f1790ba52c0ce9 (diff)
downloadserenity-3332ce01ce6a3149fa9c819845244f20bb9bd338.zip
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.
-rw-r--r--Userland/Libraries/LibGUI/Label.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/Label.cpp b/Userland/Libraries/LibGUI/Label.cpp
index a4b88b2040..d222e76b3b 100644
--- a/Userland/Libraries/LibGUI/Label.cpp
+++ b/Userland/Libraries/LibGUI/Label.cpp
@@ -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