mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 13:05:12 +00:00
LibGUI: Use full text width for Label's preferred width
A label would prefer to be exactly as wide as its contained text requires. This makes min_width: "fit" work better.
This commit is contained in:
parent
9f5f6b3868
commit
376e7243a9
Notes:
sideshowbarker
2024-07-17 05:02:35 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/376e7243a9 Pull-request: https://github.com/SerenityOS/serenity/pull/17391 Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/frhun
2 changed files with 9 additions and 2 deletions
|
@ -111,7 +111,12 @@ void Label::paint_event(PaintEvent& event)
|
|||
|
||||
void Label::size_to_fit()
|
||||
{
|
||||
set_fixed_width(static_cast<int>(ceilf(font().width(m_text))) + m_autosize_padding * 2);
|
||||
set_fixed_width(text_calculated_preferred_width());
|
||||
}
|
||||
|
||||
int Label::text_calculated_preferred_width() const
|
||||
{
|
||||
return static_cast<int>(ceilf(font().width(m_text))) + m_autosize_padding * 2;
|
||||
}
|
||||
|
||||
int Label::text_calculated_preferred_height() const
|
||||
|
@ -121,6 +126,7 @@ int Label::text_calculated_preferred_height() const
|
|||
|
||||
Optional<UISize> Label::calculated_preferred_size() const
|
||||
{
|
||||
return GUI::UISize(SpecialDimension::Grow, text_calculated_preferred_height());
|
||||
return GUI::UISize(text_calculated_preferred_width(), text_calculated_preferred_height());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
|
||||
virtual Optional<UISize> calculated_preferred_size() const override;
|
||||
int text_calculated_preferred_height() const;
|
||||
int text_calculated_preferred_width() const;
|
||||
|
||||
Gfx::IntRect text_rect() const;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue