mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-25 11:42:11 +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:
parent
1e96e46a81
commit
e2f32b8f9d
Notes:
sideshowbarker
2024-07-19 02:23:40 +09:00
Author: https://github.com/awesomekling
Commit: e2f32b8f9d
23 changed files with 373 additions and 250 deletions
|
@ -39,6 +39,11 @@ AbstractButton::AbstractButton(const StringView& text)
|
|||
m_auto_repeat_timer->on_timeout = [this] {
|
||||
click();
|
||||
};
|
||||
|
||||
REGISTER_STRING_PROPERTY("text", text, set_text);
|
||||
REGISTER_BOOL_PROPERTY("checked", is_checked, set_checked);
|
||||
REGISTER_BOOL_PROPERTY("checkable", is_checkable, set_checkable);
|
||||
REGISTER_BOOL_PROPERTY("exclusive", is_exclusive, set_exclusive);
|
||||
}
|
||||
|
||||
AbstractButton::~AbstractButton()
|
||||
|
@ -185,35 +190,4 @@ void AbstractButton::change_event(Event& event)
|
|||
Widget::change_event(event);
|
||||
}
|
||||
|
||||
void AbstractButton::save_to(JsonObject& json)
|
||||
{
|
||||
json.set("text", m_text);
|
||||
json.set("checked", m_checked);
|
||||
json.set("checkable", m_checkable);
|
||||
json.set("exclusive", m_exclusive);
|
||||
Widget::save_to(json);
|
||||
}
|
||||
|
||||
bool AbstractButton::set_property(const StringView& name, const JsonValue& value)
|
||||
{
|
||||
if (name == "text") {
|
||||
set_text(value.to_string());
|
||||
return true;
|
||||
}
|
||||
if (name == "checked") {
|
||||
set_checked(value.to_bool());
|
||||
return true;
|
||||
}
|
||||
if (name == "checkable") {
|
||||
set_checkable(value.to_bool());
|
||||
return true;
|
||||
}
|
||||
if (name == "exclusive") {
|
||||
set_exclusive(value.to_bool());
|
||||
return true;
|
||||
}
|
||||
|
||||
return Widget::set_property(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue