mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 10:25:10 +00:00
LibGUI: Rewrite layout system in terms of min and max sizes
This patch removes size policies and preferred sizes, and replaces them with min-size and max-size for each widget. Box layout now works in 3 passes: 1) Set all items (widgets/spacers) to their min-size 2) Distribute remaining space evenly, respecting max-size 3) Place widgets one after the other, adding spacing in between I've also added convenience helpers for setting a fixed size (which is the same as setting min-size and max-size to the same value.) This significantly reduces the verbosity of widget layout and makes GML a bit more pleasant to write, too. :^)
This commit is contained in:
parent
b2bba5ce5c
commit
7dc5a3ead8
83 changed files with 444 additions and 957 deletions
|
@ -64,15 +64,13 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView&
|
|||
m_table_view->on_activation = [this](const ModelIndex& index) { set_pid_from_index_and_close(index); };
|
||||
|
||||
auto& button_container = widget.add<GUI::Widget>();
|
||||
button_container.set_preferred_size(0, 30);
|
||||
button_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
button_container.set_fixed_height(30);
|
||||
button_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
button_container.layout()->set_margins({ 0, 0, 4, 0 });
|
||||
button_container.layout()->add_spacer();
|
||||
|
||||
auto& select_button = button_container.add<GUI::Button>(m_button_label);
|
||||
select_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
select_button.set_preferred_size(80, 24);
|
||||
select_button.set_fixed_size(80, 24);
|
||||
select_button.on_click = [this](auto) {
|
||||
if (m_table_view->selection().is_empty()) {
|
||||
GUI::MessageBox::show(this, "No process selected!", m_window_title, GUI::MessageBox::Type::Error);
|
||||
|
@ -82,8 +80,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView&
|
|||
set_pid_from_index_and_close(index);
|
||||
};
|
||||
auto& cancel_button = button_container.add<GUI::Button>("Cancel");
|
||||
cancel_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
cancel_button.set_preferred_size(80, 24);
|
||||
cancel_button.set_fixed_size(80, 24);
|
||||
cancel_button.on_click = [this](auto) {
|
||||
done(ExecCancel);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue