mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:07:36 +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:
parent
6e101adc28
commit
3aaffa2c47
13 changed files with 134 additions and 85 deletions
|
@ -19,6 +19,35 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
#define REGISTER_CORE_OBJECT(namespace_, class_name) \
|
||||
namespace Core { \
|
||||
namespace Registration { \
|
||||
Core::ObjectClassRegistration registration_##class_name(#namespace_ "::" #class_name, []() { return namespace_::class_name::construct(); }); \
|
||||
} \
|
||||
}
|
||||
|
||||
class ObjectClassRegistration {
|
||||
AK_MAKE_NONCOPYABLE(ObjectClassRegistration);
|
||||
AK_MAKE_NONMOVABLE(ObjectClassRegistration);
|
||||
|
||||
public:
|
||||
ObjectClassRegistration(const String& class_name, Function<NonnullRefPtr<Object>()> factory, ObjectClassRegistration* parent_class = nullptr);
|
||||
~ObjectClassRegistration();
|
||||
|
||||
String class_name() const { return m_class_name; }
|
||||
const ObjectClassRegistration* parent_class() const { return m_parent_class; }
|
||||
NonnullRefPtr<Object> construct() const { return m_factory(); }
|
||||
bool is_derived_from(const ObjectClassRegistration& base_class) const;
|
||||
|
||||
static void for_each(Function<void(const ObjectClassRegistration&)>);
|
||||
static const ObjectClassRegistration* find(const String& class_name);
|
||||
|
||||
private:
|
||||
String m_class_name;
|
||||
Function<NonnullRefPtr<Object>()> m_factory;
|
||||
ObjectClassRegistration* m_parent_class { nullptr };
|
||||
};
|
||||
|
||||
class RPCClient;
|
||||
|
||||
enum class TimerShouldFireWhenNotVisible {
|
||||
|
@ -129,6 +158,8 @@ public:
|
|||
void increment_inspector_count(Badge<RPCClient>);
|
||||
void decrement_inspector_count(Badge<RPCClient>);
|
||||
|
||||
virtual bool load_from_json(const JsonObject&, RefPtr<Core::Object> (*)(const String&)) { return false; }
|
||||
|
||||
protected:
|
||||
explicit Object(Object* parent = nullptr);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue