1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:57:35 +00:00

LibGUI: Move widget registration to LibCore

This also moves Widget::load_from_json into Core::Object as a virtual
function in order to allow loading non-widget objects in GML (e.g.
BoxLayout).

Co-authored-by: Gunnar Beutner <gbeutner@serenityos.org>
This commit is contained in:
Tom 2021-04-04 15:40:34 -06:00 committed by Andreas Kling
parent 6e101adc28
commit 3aaffa2c47
13 changed files with 134 additions and 85 deletions

View file

@ -799,7 +799,11 @@ void HackStudioWidget::create_form_editor(GUI::Widget& parent)
form_widgets_toolbar.add_action(cursor_tool_action);
GUI::WidgetClassRegistration::for_each([&, this](const GUI::WidgetClassRegistration& reg) {
auto& widget_class = *Core::ObjectClassRegistration::find("GUI::Widget");
Core::ObjectClassRegistration::for_each([&, this](const Core::ObjectClassRegistration& reg) {
if (!reg.is_derived_from(widget_class))
return;
constexpr size_t gui_namespace_prefix_length = sizeof("GUI::") - 1;
auto icon_path = String::formatted("/res/icons/hackstudio/G{}.png",
reg.class_name().substring(gui_namespace_prefix_length, reg.class_name().length() - gui_namespace_prefix_length));
@ -808,7 +812,7 @@ void HackStudioWidget::create_form_editor(GUI::Widget& parent)
auto action = GUI::Action::create_checkable(reg.class_name(), Gfx::Bitmap::load_from_file(icon_path), [&reg, this](auto&) {
m_form_editor_widget->set_tool(make<WidgetTool>(*m_form_editor_widget, reg));
auto widget = reg.construct();
auto widget = static_ptr_cast<Widget>(reg.construct());
m_form_editor_widget->form_widget().add_child(widget);
widget->set_relative_rect(30, 30, 30, 30);
m_form_editor_widget->model().update();

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Noncopyable.h>
#include <LibCore/Forward.h>
#include <LibGUI/Forward.h>
namespace HackStudio {

View file

@ -12,7 +12,7 @@ namespace HackStudio {
class WidgetTool final : public Tool {
public:
explicit WidgetTool(FormEditorWidget& editor, const GUI::WidgetClassRegistration& meta_class)
explicit WidgetTool(FormEditorWidget& editor, const Core::ObjectClassRegistration& meta_class)
: Tool(editor)
, m_meta_class(meta_class)
{
@ -26,7 +26,7 @@ private:
virtual void on_mousemove(GUI::MouseEvent&) override;
virtual void on_keydown(GUI::KeyEvent&) override;
const GUI::WidgetClassRegistration& m_meta_class;
const Core::ObjectClassRegistration& m_meta_class;
};
}