1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:57:44 +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:
Andreas Kling 2020-12-30 01:23:32 +01:00
parent b2bba5ce5c
commit 7dc5a3ead8
83 changed files with 444 additions and 957 deletions

View file

@ -40,21 +40,18 @@ EditorWrapper::EditorWrapper()
set_layout<GUI::VerticalBoxLayout>();
auto& label_wrapper = add<GUI::Widget>();
label_wrapper.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
label_wrapper.set_preferred_size(0, 14);
label_wrapper.set_fixed_height(14);
label_wrapper.set_fill_with_background_color(true);
label_wrapper.set_layout<GUI::HorizontalBoxLayout>();
label_wrapper.layout()->set_margins({ 2, 0, 2, 0 });
m_filename_label = label_wrapper.add<GUI::Label>("(Untitled)");
m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
m_filename_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_filename_label->set_preferred_size(0, 14);
m_filename_label->set_fixed_height(14);
m_cursor_label = label_wrapper.add<GUI::Label>("(Cursor)");
m_cursor_label->set_text_alignment(Gfx::TextAlignment::CenterRight);
m_cursor_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_cursor_label->set_preferred_size(0, 14);
m_cursor_label->set_fixed_height(14);
m_editor = add<Editor>();
m_editor->set_ruler_visible(true);