mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 06:18:12 +00:00
Playground: Show placeholders for unregistered widgets
With this, Playground can be used to interactively edit e.g. DisplaySettingsWindow.gml.
This commit is contained in:
parent
1b2364846f
commit
009c753a12
3 changed files with 56 additions and 11 deletions
|
@ -953,14 +953,22 @@ void Widget::set_override_cursor(Gfx::StandardCursor cursor)
|
|||
}
|
||||
|
||||
bool Widget::load_from_gml(const StringView& gml_string)
|
||||
{
|
||||
return load_from_gml(gml_string, [](const String& class_name) -> RefPtr<Widget> {
|
||||
dbgln("Class '{}' not registered", class_name);
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
bool Widget::load_from_gml(const StringView& gml_string, RefPtr<Widget> (*unregistered_child_handler)(const String&))
|
||||
{
|
||||
auto value = parse_gml(gml_string);
|
||||
if (!value.is_object())
|
||||
return false;
|
||||
return load_from_json(value.as_object());
|
||||
return load_from_json(value.as_object(), unregistered_child_handler);
|
||||
}
|
||||
|
||||
bool Widget::load_from_json(const JsonObject& json)
|
||||
bool Widget::load_from_json(const JsonObject& json, RefPtr<Widget> (*unregistered_child_handler)(const String&))
|
||||
{
|
||||
json.for_each_member([&](auto& key, auto& value) {
|
||||
set_property(key, value);
|
||||
|
@ -1004,15 +1012,17 @@ bool Widget::load_from_json(const JsonObject& json)
|
|||
dbgln("No class name in entry");
|
||||
return false;
|
||||
}
|
||||
auto* registration = WidgetClassRegistration::find(class_name.as_string());
|
||||
if (!registration) {
|
||||
dbg() << "Class '" << class_name.as_string() << "' not registered";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto child_widget = registration->construct();
|
||||
RefPtr<Widget> child_widget;
|
||||
if (auto* registration = WidgetClassRegistration::find(class_name.as_string())) {
|
||||
child_widget = registration->construct();
|
||||
} else {
|
||||
child_widget = unregistered_child_handler(class_name.as_string());
|
||||
if (!child_widget)
|
||||
return false;
|
||||
}
|
||||
add_child(*child_widget);
|
||||
child_widget->load_from_json(child_json);
|
||||
child_widget->load_from_json(child_json, unregistered_child_handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -298,6 +298,7 @@ public:
|
|||
void set_override_cursor(Gfx::StandardCursor);
|
||||
|
||||
bool load_from_gml(const StringView&);
|
||||
bool load_from_gml(const StringView&, RefPtr<Widget> (*unregistered_child_handler)(const String&));
|
||||
|
||||
void set_shrink_to_fit(bool);
|
||||
bool is_shrink_to_fit() const { return m_shrink_to_fit; }
|
||||
|
@ -350,7 +351,7 @@ private:
|
|||
void focus_previous_widget(FocusSource, bool siblings_only);
|
||||
void focus_next_widget(FocusSource, bool siblings_only);
|
||||
|
||||
bool load_from_json(const JsonObject&);
|
||||
bool load_from_json(const JsonObject&, RefPtr<Widget> (*unregistered_child_handler)(const String&));
|
||||
|
||||
// HACK: These are used as property getters for the fixed_* size property aliases.
|
||||
int dummy_fixed_width() { return 0; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue