1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +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

@ -112,14 +112,6 @@ public:
return layout;
}
SizePolicy horizontal_size_policy() const { return m_horizontal_size_policy; }
SizePolicy vertical_size_policy() const { return m_vertical_size_policy; }
SizePolicy size_policy(Orientation orientation) { return orientation == Orientation::Horizontal ? m_horizontal_size_policy : m_vertical_size_policy; }
void set_size_policy(SizePolicy horizontal_policy, SizePolicy vertical_policy);
void set_size_policy(Orientation, SizePolicy);
void set_horizontal_size_policy(SizePolicy policy) { set_size_policy(policy, vertical_size_policy()); }
void set_vertical_size_policy(SizePolicy policy) { set_size_policy(horizontal_size_policy(), policy); }
Gfx::IntSize min_size() const { return m_min_size; }
void set_min_size(const Gfx::IntSize&);
void set_min_size(int width, int height) { set_min_size({ width, height }); }
@ -158,15 +150,6 @@ public:
set_max_height(height);
}
Gfx::IntSize preferred_size() const { return m_preferred_size; }
void set_preferred_size(const Gfx::IntSize&);
void set_preferred_size(int width, int height) { set_preferred_size({ width, height }); }
int preferred_width() const { return preferred_size().width(); }
int preferred_height() const { return preferred_size().height(); }
void set_preferred_width(int w) { set_preferred_size(w, preferred_height()); }
void set_preferred_height(int h) { set_preferred_size(preferred_width(), h); }
bool has_tooltip() const { return !m_tooltip.is_empty(); }
String tooltip() const { return m_tooltip; }
void set_tooltip(const StringView&);
@ -405,9 +388,6 @@ private:
NonnullRefPtr<Gfx::Font> m_font;
String m_tooltip;
SizePolicy m_horizontal_size_policy { SizePolicy::Fill };
SizePolicy m_vertical_size_policy { SizePolicy::Fill };
Gfx::IntSize m_preferred_size;
Gfx::IntSize m_min_size { -1, -1 };
Gfx::IntSize m_max_size { -1, -1 };
Margins m_content_margins;