1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

LibGfx+LibGUI: Use constant for line spacing instead of magic number

This commit is contained in:
lanmonster 2022-11-28 09:02:08 -06:00 committed by Andreas Kling
parent 67de1a8148
commit 2b7aa4a971
3 changed files with 6 additions and 7 deletions

View file

@ -117,9 +117,7 @@ void Label::size_to_fit()
int Label::text_calculated_preferred_height() const int Label::text_calculated_preferred_height() const
{ {
// FIXME: The 4 is taken from Gfx::Painter and should be available as return Gfx::TextLayout(&font(), Utf8View { m_text }, text_rect()).bounding_rect(Gfx::TextWrapping::Wrap, Gfx::Painter::LINE_SPACING).height();
// a constant instead.
return Gfx::TextLayout(&font(), Utf8View { m_text }, text_rect()).bounding_rect(Gfx::TextWrapping::Wrap, 4).height();
} }
Optional<UISize> Label::calculated_preferred_size() const Optional<UISize> Label::calculated_preferred_size() const

View file

@ -1686,11 +1686,10 @@ void Painter::do_draw_text(IntRect const& rect, Utf8View const& text, Font const
TextLayout layout(&font, text, rect); TextLayout layout(&font, text, rect);
static int const line_spacing = 4; int line_height = font.pixel_size() + LINE_SPACING;
int line_height = font.pixel_size() + line_spacing;
auto lines = layout.lines(elision, wrapping, line_spacing); auto lines = layout.lines(elision, wrapping, LINE_SPACING);
auto bounding_rect = layout.bounding_rect(wrapping, line_spacing); auto bounding_rect = layout.bounding_rect(wrapping, LINE_SPACING);
switch (alignment) { switch (alignment) {
case TextAlignment::TopCenter: case TextAlignment::TopCenter:

View file

@ -25,6 +25,8 @@ namespace Gfx {
class Painter { class Painter {
public: public:
static constexpr int LINE_SPACING = 4;
explicit Painter(Gfx::Bitmap&); explicit Painter(Gfx::Bitmap&);
~Painter() = default; ~Painter() = default;