diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-30 01:23:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-30 01:36:41 +0100 |
commit | 7dc5a3ead86627d11b1bf8d243750e5e3390c067 (patch) | |
tree | bfcab42f5b00c5b368ac9ee4a288d7c0d9c4bd01 /Applications/FileManager/PropertiesDialog.cpp | |
parent | b2bba5ce5c06d40e2fbcfff4cf1412532f93ae6b (diff) | |
download | serenity-7dc5a3ead86627d11b1bf8d243750e5e3390c067.zip |
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. :^)
Diffstat (limited to 'Applications/FileManager/PropertiesDialog.cpp')
-rw-r--r-- | Applications/FileManager/PropertiesDialog.cpp | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/Applications/FileManager/PropertiesDialog.cpp b/Applications/FileManager/PropertiesDialog.cpp index 7f3015bed7..91310d31bc 100644 --- a/Applications/FileManager/PropertiesDialog.cpp +++ b/Applications/FileManager/PropertiesDialog.cpp @@ -63,25 +63,20 @@ PropertiesDialog::PropertiesDialog(const String& path, bool disable_rename, Wind general_tab.layout()->set_margins({ 12, 8, 12, 8 }); general_tab.layout()->set_spacing(10); - general_tab.layout()->add_spacer(); - auto& file_container = general_tab.add<GUI::Widget>(); file_container.set_layout<GUI::HorizontalBoxLayout>(); - file_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); file_container.layout()->set_spacing(20); - file_container.set_preferred_size(0, 34); + file_container.set_fixed_height(34); m_icon = file_container.add<GUI::ImageWidget>(); - m_icon->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); - m_icon->set_preferred_size(32, 32); + m_icon->set_fixed_size(32, 32); m_name = lexical_path.basename(); m_path = lexical_path.string(); m_parent_path = lexical_path.dirname(); m_name_box = file_container.add<GUI::TextBox>(); - m_name_box->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - m_name_box->set_preferred_size({ 0, 22 }); + m_name_box->set_fixed_height(22); m_name_box->set_text(m_name); m_name_box->set_mode(disable_rename ? GUI::TextBox::Mode::DisplayOnly : GUI::TextBox::Mode::Editable); m_name_box->on_change = [&]() { @@ -151,8 +146,7 @@ PropertiesDialog::PropertiesDialog(const String& path, bool disable_rename, Wind auto& button_widget = main_widget.add<GUI::Widget>(); button_widget.set_layout<GUI::HorizontalBoxLayout>(); - button_widget.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - button_widget.set_preferred_size(0, 24); + button_widget.set_fixed_height(24); button_widget.layout()->set_spacing(5); button_widget.layout()->add_spacer(); @@ -237,8 +231,7 @@ void PropertiesDialog::make_permission_checkboxes(GUI::Widget& parent, Permissio { auto& widget = parent.add<GUI::Widget>(); widget.set_layout<GUI::HorizontalBoxLayout>(); - widget.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - widget.set_preferred_size(0, 16); + widget.set_fixed_height(16); widget.layout()->set_spacing(10); auto& label = widget.add<GUI::Label>(label_string); @@ -277,13 +270,11 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair> for (auto pair : pairs) { auto& label_container = parent.add<GUI::Widget>(); label_container.set_layout<GUI::HorizontalBoxLayout>(); - label_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - label_container.set_preferred_size(0, 14); + label_container.set_fixed_height(14); label_container.layout()->set_spacing(12); auto& label_property = label_container.add<GUI::Label>(pair.property); label_property.set_text_alignment(Gfx::TextAlignment::CenterLeft); - label_property.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); if (!pair.link.has_value()) { label_container.add<GUI::Label>(pair.value).set_text_alignment(Gfx::TextAlignment::CenterLeft); @@ -300,24 +291,18 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair> } for (auto label : property_labels) - label->set_preferred_size({ max_width, 0 }); + label->set_fixed_width(max_width); } GUI::Button& PropertiesDialog::make_button(String text, GUI::Widget& parent) { auto& button = parent.add<GUI::Button>(text); - button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); - button.set_preferred_size(70, 22); + button.set_fixed_size(70, 22); return button; } void PropertiesDialog::make_divider(GUI::Widget& parent) { - parent.layout()->add_spacer(); - auto& divider = parent.add<GUI::Frame>(); - divider.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); - divider.set_preferred_size({ 0, 2 }); - - parent.layout()->add_spacer(); + divider.set_fixed_height(2); } |