mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:47:46 +00:00
GMLCompiler: Add common pattern for a user-defined fallible initializer
Many widget classes need to run substantial initialization code after they have been setup from GML. With this change, an initialize_fallibles() function is called if available, allowing the initialization to be invoked from the GML setup automatically. This means that the GML-generated creation function can now be used directly for many more cases, and reduces code duplication.
This commit is contained in:
parent
8878e0c815
commit
dec066fa5c
3 changed files with 24 additions and 0 deletions
|
@ -71,6 +71,15 @@ enum class AllowCallback {
|
|||
Yes
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
ALWAYS_INLINE ErrorOr<void> initialize(T& object)
|
||||
{
|
||||
if constexpr (requires { { object.initialize() } -> SameAs<ErrorOr<void>>; })
|
||||
return object.initialize();
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
class Widget : public GUI::Object {
|
||||
C_OBJECT(Widget)
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue