mirror of
https://github.com/RGBCube/serenity
synced 2025-05-29 20:25:12 +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
23 changed files with 373 additions and 250 deletions
|
@ -65,6 +65,24 @@ Window::Window(Core::Object* parent)
|
|||
all_windows->set(this);
|
||||
m_rect_when_windowless = { -5000, -5000, 140, 140 };
|
||||
m_title_when_windowless = "GUI::Window";
|
||||
|
||||
register_property(
|
||||
"title",
|
||||
[this] { return title(); },
|
||||
[this](auto& value) {
|
||||
set_title(value.to_string());
|
||||
return true;
|
||||
});
|
||||
|
||||
register_property("visible", [this] { return is_visible(); });
|
||||
register_property("active", [this] { return is_active(); });
|
||||
|
||||
REGISTER_BOOL_PROPERTY("minimizable", is_minimizable, set_minimizable);
|
||||
REGISTER_BOOL_PROPERTY("resizable", is_resizable, set_resizable);
|
||||
REGISTER_BOOL_PROPERTY("fullscreen", is_fullscreen, set_fullscreen);
|
||||
REGISTER_RECT_PROPERTY("rect", rect, set_rect);
|
||||
REGISTER_SIZE_PROPERTY("base_size", base_size, set_base_size);
|
||||
REGISTER_SIZE_PROPERTY("size_increment", size_increment, set_size_increment);
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
|
@ -724,20 +742,6 @@ Vector<Widget*> Window::focusable_widgets() const
|
|||
return collected_widgets;
|
||||
}
|
||||
|
||||
void Window::save_to(AK::JsonObject& json)
|
||||
{
|
||||
json.set("title", title());
|
||||
json.set("visible", is_visible());
|
||||
json.set("active", is_active());
|
||||
json.set("minimizable", is_minimizable());
|
||||
json.set("resizable", is_resizable());
|
||||
json.set("fullscreen", is_fullscreen());
|
||||
json.set("rect", rect().to_string());
|
||||
json.set("base_size", base_size().to_string());
|
||||
json.set("size_increment", size_increment().to_string());
|
||||
Core::Object::save_to(json);
|
||||
}
|
||||
|
||||
void Window::set_fullscreen(bool fullscreen)
|
||||
{
|
||||
if (m_fullscreen == fullscreen)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue