mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 13:45:06 +00:00
LibGUI: Add Widget shrink-to-fit layout flag
If this flag is enabled for a widget, it will be automatically sized based on its children. This only works for widgets using a layout. This allows you to put widgets inside each other without having to manually calculate how large the container should be. It's not the perfect API but it's a decent progression in ergonomics. :^)
This commit is contained in:
parent
ce7b09a3c5
commit
b03e1b08b5
5 changed files with 90 additions and 0 deletions
|
@ -105,6 +105,8 @@ Widget::Widget()
|
|||
REGISTER_INT_PROPERTY("fixed_height", dummy_fixed_height, set_fixed_height);
|
||||
REGISTER_SIZE_PROPERTY("fixed_size", dummy_fixed_size, set_fixed_size);
|
||||
|
||||
REGISTER_BOOL_PROPERTY("shrink_to_fit", is_shrink_to_fit, set_shrink_to_fit);
|
||||
|
||||
REGISTER_INT_PROPERTY("x", x, set_x);
|
||||
REGISTER_INT_PROPERTY("y", y, set_y);
|
||||
|
||||
|
@ -1010,4 +1012,12 @@ bool Widget::has_focus_within() const
|
|||
return window->focused_widget() == &effective_focus_widget || is_ancestor_of(*window->focused_widget());
|
||||
}
|
||||
|
||||
void Widget::set_shrink_to_fit(bool b)
|
||||
{
|
||||
if (m_shrink_to_fit == b)
|
||||
return;
|
||||
m_shrink_to_fit = b;
|
||||
invalidate_layout();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue