summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/Window.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-03 21:42:48 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-03 22:37:48 +0100
commit03e0ddce5237b6ad7b84724ef03039e413944f00 (patch)
treeee45767b85f54584ce6c3f08dd34b7f8e84ef1cd /Libraries/LibGUI/Window.h
parent0cafbbf09c303a51a48b67ef951fa828979cde6e (diff)
downloadserenity-03e0ddce5237b6ad7b84724ef03039e413944f00.zip
LibGUI: Some more convenience functions for constructing widgets
This patch adds two new API's: - WidgetType& GUI::Window::set_main_widget<WidgetType>(); This creates a new main widget for a window, assigns it, and returns it to you as a WidgetType&. - LayoutType& GUI::Widget::set_layout<LayoutType>(); Same basic idea, creates a new layout, assigns it, and returns it to you as a LayoutType&.
Diffstat (limited to 'Libraries/LibGUI/Window.h')
-rw-r--r--Libraries/LibGUI/Window.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/Libraries/LibGUI/Window.h b/Libraries/LibGUI/Window.h
index 65db147a96..c056637c50 100644
--- a/Libraries/LibGUI/Window.h
+++ b/Libraries/LibGUI/Window.h
@@ -125,6 +125,14 @@ public:
const Widget* main_widget() const { return m_main_widget; }
void set_main_widget(Widget*);
+ template<class T, class... Args>
+ inline T& set_main_widget(Args&&... args)
+ {
+ auto widget = T::construct(forward<Args>(args)...);
+ set_main_widget(widget.ptr());
+ return *widget;
+ }
+
Widget* focused_widget() { return m_focused_widget; }
const Widget* focused_widget() const { return m_focused_widget; }
void set_focused_widget(Widget*);