1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

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&.
This commit is contained in:
Andreas Kling 2020-03-03 21:42:48 +01:00
parent 0cafbbf09c
commit 03e0ddce52
10 changed files with 66 additions and 60 deletions

View file

@ -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*);