diff --git a/Applications/Browser/InspectorWidget.cpp b/Applications/Browser/InspectorWidget.cpp index d2d87b72642..cf8416e4173 100644 --- a/Applications/Browser/InspectorWidget.cpp +++ b/Applications/Browser/InspectorWidget.cpp @@ -54,15 +54,14 @@ InspectorWidget::InspectorWidget() m_computed_style_table_view->set_model(nullptr); } }; - m_style_table_view = GUI::TableView::construct(); + + auto tab_widget = splitter->add(); + + m_style_table_view = tab_widget->add_tab("Styles"); m_style_table_view->set_size_columns_to_fit_content(true); - m_computed_style_table_view = GUI::TableView::construct(); + m_computed_style_table_view = tab_widget->add_tab("Computed"); m_computed_style_table_view->set_size_columns_to_fit_content(true); - - auto tabwidget = splitter->add(); - tabwidget->add_widget("Styles", m_style_table_view); - tabwidget->add_widget("Computed", m_computed_style_table_view); } InspectorWidget::~InspectorWidget() diff --git a/Applications/DisplayProperties/DisplayProperties.cpp b/Applications/DisplayProperties/DisplayProperties.cpp index 1760dfd47f3..da6c96f4993 100644 --- a/Applications/DisplayProperties/DisplayProperties.cpp +++ b/Applications/DisplayProperties/DisplayProperties.cpp @@ -124,17 +124,15 @@ void DisplayPropertiesWidget::create_frame() { auto tab_widget = m_root_widget->add(); - // First, let's create the "Background" tab - auto background_splitter = GUI::VerticalSplitter::construct(); - tab_widget->add_widget("Wallpaper", background_splitter); + auto wallpaper_splitter = tab_widget->add_tab("Wallpaper"); - auto background_content = background_splitter->add(); - background_content->set_layout(make()); - background_content->layout()->set_margins({ 4, 4, 4, 4 }); + auto wallpaper_content = wallpaper_splitter->add(); + wallpaper_content->set_layout(make()); + wallpaper_content->layout()->set_margins({ 4, 4, 4, 4 }); - m_wallpaper_preview = background_splitter->add(); + m_wallpaper_preview = wallpaper_splitter->add(); - auto wallpaper_list = background_content->add(); + auto wallpaper_list = wallpaper_content->add(); wallpaper_list->set_background_color(Color::White); wallpaper_list->set_model(*ItemListModel::create(m_wallpapers)); @@ -154,9 +152,7 @@ void DisplayPropertiesWidget::create_frame() m_wallpaper_preview->set_should_stretch_icon(true); }; - // Let's add the settings tab - auto settings_splitter = GUI::VerticalSplitter::construct(); - tab_widget->add_widget("Settings", settings_splitter); + auto settings_splitter = tab_widget->add_tab("Settings"); auto settings_content = settings_splitter->add(); settings_content->set_layout(make()); diff --git a/Applications/FileManager/PropertiesDialog.cpp b/Applications/FileManager/PropertiesDialog.cpp index 6c7a867cf36..c8fb51aca9d 100644 --- a/Applications/FileManager/PropertiesDialog.cpp +++ b/Applications/FileManager/PropertiesDialog.cpp @@ -54,11 +54,10 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo auto tab_widget = main_widget->add(); - auto general_tab = tab_widget->add(); + auto general_tab = tab_widget->add_tab("General"); general_tab->set_layout(make()); general_tab->layout()->set_margins({ 12, 8, 12, 8 }); general_tab->layout()->set_spacing(10); - tab_widget->add_widget("General", general_tab); general_tab->layout()->add_spacer(); diff --git a/Applications/Piano/MainWidget.cpp b/Applications/Piano/MainWidget.cpp index c70747d4c4b..d8eab8d8ad8 100644 --- a/Applications/Piano/MainWidget.cpp +++ b/Applications/Piano/MainWidget.cpp @@ -47,15 +47,13 @@ MainWidget::MainWidget(AudioEngine& audio_engine) m_wave_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); m_wave_widget->set_preferred_size(0, 100); - m_roll_widget = RollWidget::construct(audio_engine); + m_tab_widget = add(); + m_roll_widget = m_tab_widget->add_tab("Piano Roll", audio_engine); + m_roll_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); m_roll_widget->set_preferred_size(0, 300); - m_sampler_widget = SamplerWidget::construct(audio_engine); - - m_tab_widget = add(); - m_tab_widget->add_widget("Piano Roll", m_roll_widget); - m_tab_widget->add_widget("Sampler", m_sampler_widget); + m_tab_widget->add_tab("Sampler", audio_engine); m_keys_and_knobs_container = add(); m_keys_and_knobs_container->set_layout(make()); diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index 12d1803588d..8c00fba9de1 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -70,9 +70,9 @@ static String human_readable_size(u32 size) return String::format("%u GB", size / GB); } -static RefPtr build_file_systems_tab(); -static RefPtr build_pci_devices_tab(); -static RefPtr build_devices_tab(); +static NonnullRefPtr build_file_systems_tab(); +static NonnullRefPtr build_pci_devices_tab(); +static NonnullRefPtr build_devices_tab(); static NonnullRefPtr build_graphs_tab(); int main(int argc, char** argv) @@ -123,8 +123,7 @@ int main(int argc, char** argv) auto tabwidget = keeper->add(); - auto process_container_splitter = GUI::VerticalSplitter::construct(); - tabwidget->add_widget("Processes", process_container_splitter); + auto process_container_splitter = tabwidget->add_tab("Processes"); auto process_table_container = process_container_splitter->add(); @@ -232,17 +231,10 @@ int main(int argc, char** argv) auto process_tab_widget = process_container_splitter->add(); - auto memory_map_widget = ProcessMemoryMapWidget::construct(); - process_tab_widget->add_widget("Memory map", memory_map_widget); - - auto open_files_widget = ProcessFileDescriptorMapWidget::construct(); - process_tab_widget->add_widget("Open files", open_files_widget); - - auto unveiled_paths_widget = ProcessUnveiledPathsWidget::construct(); - process_tab_widget->add_widget("Unveiled paths", unveiled_paths_widget); - - auto stacks_widget = ProcessStacksWidget::construct(); - process_tab_widget->add_widget("Stacks", stacks_widget); + auto memory_map_widget = process_tab_widget->add_tab("Memory map"); + auto open_files_widget = process_tab_widget->add_tab("Open files"); + auto unveiled_paths_widget = process_tab_widget->add_tab("Unveiled paths"); + auto stacks_widget = process_tab_widget->add_tab("Stacks"); process_table_view->on_process_selected = [&](pid_t pid) { open_files_widget->set_pid(pid); @@ -276,7 +268,7 @@ public: } }; -RefPtr build_file_systems_tab() +NonnullRefPtr build_file_systems_tab() { auto fs_widget = GUI::LazyWidget::construct(); @@ -369,7 +361,7 @@ RefPtr build_file_systems_tab() return fs_widget; } -RefPtr build_pci_devices_tab() +NonnullRefPtr build_pci_devices_tab() { auto pci_widget = GUI::LazyWidget::construct(); @@ -427,7 +419,7 @@ RefPtr build_pci_devices_tab() return pci_widget; } -RefPtr build_devices_tab() +NonnullRefPtr build_devices_tab() { auto devices_widget = GUI::LazyWidget::construct(); diff --git a/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index cd6c5893ce1..6fd9f4f8c52 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -445,11 +445,8 @@ int main(int argc, char** argv) update_actions(); }); - auto find_in_files_widget = FindInFilesWidget::construct(); - s_action_tab_widget->add_widget("Find in files", find_in_files_widget); - - auto terminal_wrapper = TerminalWrapper::construct(); - s_action_tab_widget->add_widget("Console", terminal_wrapper); + auto find_in_files_widget = s_action_tab_widget->add_tab("Find in files"); + auto terminal_wrapper = s_action_tab_widget->add_tab("Console"); auto locator = widget->add(); diff --git a/Libraries/LibGUI/TabWidget.cpp b/Libraries/LibGUI/TabWidget.cpp index 6a2d5194211..244d9986a13 100644 --- a/Libraries/LibGUI/TabWidget.cpp +++ b/Libraries/LibGUI/TabWidget.cpp @@ -41,10 +41,10 @@ TabWidget::~TabWidget() { } -void TabWidget::add_widget(const StringView& title, Widget* widget) +void TabWidget::add_widget(const StringView& title, Widget& widget) { - m_tabs.append({ title, widget }); - add_child(*widget); + m_tabs.append({ title, &widget }); + add_child(widget); } void TabWidget::set_active_widget(Widget* widget) diff --git a/Libraries/LibGUI/TabWidget.h b/Libraries/LibGUI/TabWidget.h index 2b0fdcaa158..e711001d1da 100644 --- a/Libraries/LibGUI/TabWidget.h +++ b/Libraries/LibGUI/TabWidget.h @@ -52,7 +52,15 @@ public: int bar_height() const { return 21; } int container_padding() const { return 2; } - void add_widget(const StringView&, Widget*); + void add_widget(const StringView&, Widget&); + + template + inline NonnullRefPtr add_tab(const StringView& title, Args&&... args) + { + auto t = T::construct(forward(args)...); + add_widget(title, *t); + return t; + } protected: TabWidget();