mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
LibGUI: Add effective and calculated sizes to Widget
Effective sizes are the ones that are actually to be used for layout. They are just their respective propertys value, or the value returned by the calculated_<min/preferred>_size, when the respective property is set to shrink or fit. The "calculated" values in turn are specific to the widget. Container widgets for example can calculate their values depending on their layout and child widget requirement. Simple widgets like labels and buttons can for example calculate their values based upon their current text.
This commit is contained in:
parent
d825c8ad18
commit
ec1e25929e
2 changed files with 41 additions and 0 deletions
|
@ -809,6 +809,24 @@ void Widget::set_preferred_size(UISize const& size)
|
|||
invalidate_layout();
|
||||
}
|
||||
|
||||
Optional<UISize> Widget::calculated_preferred_size() const
|
||||
{
|
||||
if (layout())
|
||||
return { layout()->preferred_size() };
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<UISize> Widget::calculated_min_size() const
|
||||
{
|
||||
if (layout())
|
||||
return { layout()->min_size() };
|
||||
// Fall back to at least displaying the margins, so the Widget is not 0 size.
|
||||
auto m = content_margins();
|
||||
if (!m.is_null())
|
||||
return UISize { m.left() + m.right(), m.top() + m.bottom() };
|
||||
return {};
|
||||
}
|
||||
|
||||
void Widget::invalidate_layout()
|
||||
{
|
||||
if (window())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue