1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 09:17:35 +00:00

LibGUI: Tweak GUI::Label auto-sizing logic for floating point font sizes

We have to ceil the font size or we risk being 1px too small.
This commit is contained in:
Andreas Kling 2023-01-06 11:27:05 +01:00
parent d2195f8088
commit dd8d65ada0

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers. * Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
@ -112,12 +112,12 @@ void Label::paint_event(PaintEvent& event)
void Label::size_to_fit() void Label::size_to_fit()
{ {
set_fixed_width(font().width(m_text) + m_autosize_padding * 2); set_fixed_width(static_cast<int>(ceilf(font().width(m_text))) + m_autosize_padding * 2);
} }
int Label::text_calculated_preferred_height() const int Label::text_calculated_preferred_height() const
{ {
return int(AK::ceil(Gfx::TextLayout(font(), Utf8View { m_text }, text_rect().to_type<float>()).bounding_rect(Gfx::TextWrapping::Wrap, Gfx::Painter::LINE_SPACING).height())); return static_cast<int>(ceilf(Gfx::TextLayout(font(), Utf8View { m_text }, text_rect().to_type<float>()).bounding_rect(Gfx::TextWrapping::Wrap, Gfx::Painter::LINE_SPACING).height()));
} }
Optional<UISize> Label::calculated_preferred_size() const Optional<UISize> Label::calculated_preferred_size() const