LibCore: Support write-only Object properties

Some properties are set and then never retrieved, e.g. GUI icon paths.
Add a helper to create such properties, similar to the read-only helper.
This commit is contained in:
Timothy Flynn 2022-12-08 10:59:30 -05:00 committed by Andreas Kling
parent 58f5deba70
commit 746364d7c1
2 changed files with 15 additions and 1 deletions

View file

@ -311,6 +311,15 @@ requires IsBaseOf<Object, T>
[this] { return this->getter(); }, \
{});
#define REGISTER_WRITE_ONLY_STRING_PROPERTY(property_name, setter) \
register_property( \
property_name, \
{}, \
[this](auto& value) { \
this->setter(value.to_deprecated_string()); \
return true; \
});
#define REGISTER_READONLY_SIZE_PROPERTY(property_name, getter) \
register_property( \
property_name, \

View file

@ -26,7 +26,12 @@ public:
return m_setter(value);
}
JsonValue get() const { return m_getter(); }
JsonValue get() const
{
if (!m_getter)
return {};
return m_getter();
}
DeprecatedString const& name() const { return m_name; }
bool is_readonly() const { return !m_setter; }