1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:08:12 +00:00

LibGUI: Allow TabWidget to remove all tabs except one

This commit is contained in:
TheFightingCatfish 2021-08-06 10:01:32 +08:00 committed by Andreas Kling
parent ca2c81251a
commit 8a0d465fbc
2 changed files with 17 additions and 0 deletions

View file

@ -64,6 +64,22 @@ void TabWidget::remove_widget(Widget& widget)
on_tab_count_change(m_tabs.size());
}
void TabWidget::remove_all_tabs_except(Widget& widget)
{
VERIFY(widget.parent() == this);
set_active_widget(&widget);
m_tabs.remove_all_matching([this, &widget](auto& entry) {
bool is_other = &widget != entry.widget;
if (is_other)
remove_child(*entry.widget);
return is_other;
});
VERIFY(m_tabs.size() == 1);
update_focus_policy();
if (on_tab_count_change)
on_tab_count_change(1);
}
void TabWidget::update_focus_policy()
{
FocusPolicy policy;