1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +00:00

LibGUI: Add GUI::Window::try_set_main_widget<T>(...)

This is a fallible variant of set_main_widget<T>() that returns ErrorOr.
This commit is contained in:
Andreas Kling 2021-11-24 13:12:39 +01:00
parent bde9c2bc65
commit dc47fce2d9

View file

@ -135,6 +135,14 @@ public:
const Widget* main_widget() const { return m_main_widget; }
void set_main_widget(Widget*);
template<class T, class... Args>
inline ErrorOr<NonnullRefPtr<T>> try_set_main_widget(Args&&... args)
{
auto widget = TRY(T::try_create(forward<Args>(args)...));
set_main_widget(widget.ptr());
return widget;
}
template<class T, class... Args>
inline T& set_main_widget(Args&&... args)
{