diff options
author | Andreas Kling <kling@serenityos.org> | 2020-09-15 21:33:37 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-15 21:46:26 +0200 |
commit | e2f32b8f9d4ce0ce8f92d4817273fb9b32cd8ccd (patch) | |
tree | bcc49c2fd5a87ffbfc992d0b1406b4c64e47941b /Libraries/LibGUI/Widget.h | |
parent | 1e96e46a8137e297d1d38271373145ac21f4da3e (diff) | |
download | serenity-e2f32b8f9d4ce0ce8f92d4817273fb9b32cd8ccd.zip |
LibCore: Make Core::Object properties more dynamic
Instead of everyone overriding save_to() and set_property() and doing
a pretty asymmetric job of implementing the various properties, let's
add a bit of structure here.
Object properties are now represented by a Core::Property. Properties
are registered with a getter and setter (optional) in constructors.
I've added some convenience macros for creating and registering
properties, but this does still feel a bit bulky. We'll have to
iterate on this and see where it goes.
Diffstat (limited to 'Libraries/LibGUI/Widget.h')
-rw-r--r-- | Libraries/LibGUI/Widget.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Libraries/LibGUI/Widget.h b/Libraries/LibGUI/Widget.h index 901945c260..17bb3864d2 100644 --- a/Libraries/LibGUI/Widget.h +++ b/Libraries/LibGUI/Widget.h @@ -109,11 +109,18 @@ public: 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 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&); @@ -261,8 +268,6 @@ public: virtual bool is_radio_button() const { return false; } virtual bool is_abstract_button() const { return false; } - virtual void save_to(AK::JsonObject&) override; - void do_layout(); Gfx::Palette palette() const; @@ -317,8 +322,6 @@ protected: virtual void did_begin_inspection() override; virtual void did_end_inspection() override; - virtual bool set_property(const StringView& name, const JsonValue& value) override; - private: void handle_paint_event(PaintEvent&); void handle_resize_event(ResizeEvent&); |