1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-07 08:37:34 +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:
Andreas Kling 2020-09-15 21:33:37 +02:00
parent 1e96e46a81
commit e2f32b8f9d
23 changed files with 373 additions and 250 deletions

View file

@ -40,6 +40,20 @@ namespace GUI {
TabWidget::TabWidget()
{
REGISTER_INT_PROPERTY("container_padding", container_padding, set_container_padding);
REGISTER_BOOL_PROPERTY("uniform_tabs", uniform_tabs, set_uniform_tabs);
register_property(
"text_alignment",
[this] { return Gfx::to_string(text_alignment()); },
[this](auto& value) {
auto alignment = Gfx::text_alignment_from_string(value.to_string());
if (alignment.has_value()) {
set_text_alignment(alignment.value());
return true;
}
return false;
});
}
TabWidget::~TabWidget()
@ -396,26 +410,4 @@ void TabWidget::context_menu_event(ContextMenuEvent& context_menu_event)
}
}
bool TabWidget::set_property(const StringView& name, const JsonValue& value)
{
if (name == "container_padding") {
set_container_padding(value.to_i32());
return true;
}
if (name == "uniform_tabs") {
set_uniform_tabs(value.to_bool());
return true;
}
if (name == "text_alignment") {
auto alignment = Gfx::text_alignment_from_string(value.to_string());
if (alignment.has_value())
set_text_alignment(alignment.value());
return true;
}
return Widget::set_property(name, value);
}
}