1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:17:42 +00:00

LibGUI: Add fixed_size/fixed_width/fixed_height helpers to Widget

Fixed sizes are really just shorthands for setting min and max size to
the same value.

This makes it much nicer to express fixed sizes in GML:

Before:

    @GUI::Widget {
        horizontal_size_policy: "Fixed"
        preferred_width: 20
    }

After:

    @GUI::Widget {
        fixed_width: 20
    }
This commit is contained in:
Andreas Kling 2020-12-29 18:46:42 +01:00
parent c9331a96d6
commit ee85713e52
2 changed files with 29 additions and 0 deletions

View file

@ -145,6 +145,10 @@ Widget::Widget()
REGISTER_INT_PROPERTY("min_height", min_height, set_min_height); REGISTER_INT_PROPERTY("min_height", min_height, set_min_height);
REGISTER_INT_PROPERTY("max_height", max_height, set_max_height); REGISTER_INT_PROPERTY("max_height", max_height, set_max_height);
REGISTER_INT_PROPERTY("fixed_width", dummy_fixed_width, set_fixed_width);
REGISTER_INT_PROPERTY("fixed_height", dummy_fixed_height, set_fixed_height);
REGISTER_SIZE_PROPERTY("fixed_size", dummy_fixed_size, set_fixed_size);
register_property( register_property(
"focus_policy", [this]() -> JsonValue { "focus_policy", [this]() -> JsonValue {
auto policy = focus_policy(); auto policy = focus_policy();

View file

@ -138,6 +138,26 @@ public:
void set_max_width(int width) { set_max_size(width, max_height()); } void set_max_width(int width) { set_max_size(width, max_height()); }
void set_max_height(int height) { set_max_size(max_width(), height); } void set_max_height(int height) { set_max_size(max_width(), height); }
void set_fixed_size(const Gfx::IntSize& size)
{
set_min_size(size);
set_max_size(size);
}
void set_fixed_size(int width, int height) { set_fixed_size({ width, height }); }
void set_fixed_width(int width)
{
set_min_width(width);
set_max_width(width);
}
void set_fixed_height(int height)
{
set_min_height(height);
set_max_height(height);
}
Gfx::IntSize preferred_size() const { return m_preferred_size; } Gfx::IntSize preferred_size() const { return m_preferred_size; }
void set_preferred_size(const Gfx::IntSize&); void set_preferred_size(const Gfx::IntSize&);
void set_preferred_size(int width, int height) { set_preferred_size({ width, height }); } void set_preferred_size(int width, int height) { set_preferred_size({ width, height }); }
@ -369,6 +389,11 @@ private:
bool load_from_json(const JsonObject&); bool load_from_json(const JsonObject&);
// HACK: These are used as property getters for the fixed_* size property aliases.
int dummy_fixed_width() { return 0; }
int dummy_fixed_height() { return 0; }
Gfx::IntSize dummy_fixed_size() { return {}; }
Window* m_window { nullptr }; Window* m_window { nullptr };
RefPtr<Layout> m_layout; RefPtr<Layout> m_layout;