mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-08 01:27:31 +00:00
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.
This commit is contained in:
@@ -37,6 +37,8 @@ namespace GUI {
|
||||
BoxLayout::BoxLayout(Orientation orientation)
|
||||
: m_orientation(orientation)
|
||||
{
|
||||
register_property(
|
||||
"orientation", [this] { return m_orientation == Gfx::Orientation::Vertical ? "Vertical" : "Horizontal"; }, nullptr);
|
||||
}
|
||||
|
||||
void BoxLayout::run(Widget& widget)
|
||||
@@ -174,11 +176,4 @@ void BoxLayout::run(Widget& widget)
|
||||
current_y += rect.height() + spacing();
|
||||
}
|
||||
}
|
||||
|
||||
void BoxLayout::save_to(JsonObject& json)
|
||||
{
|
||||
Layout::save_to(json);
|
||||
json.set("orientation", m_orientation == Gfx::Orientation::Vertical ? "Vertical" : "Horizontal");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user