From 3757295b959854d3809789a7518cf2cb8337cab4 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Mon, 26 Aug 2024 20:21:59 +0800 Subject: [PATCH] A bunch of tab fixes (#6551) * Make sure the speed tab is properly hidden when toggle off advance mode * Clear each page before clearing the parent, otherwise the child pages will be destroyed twice * Fix crash if current selected tab is positioned after the removed tab * Fix issue that sometimes the printer config first page is not displayed * Fix issue that the wrong tab item get bold if the number of tabs changed --- src/slic3r/GUI/OG_CustomCtrl.cpp | 13 ++++++++----- src/slic3r/GUI/PresetComboBoxes.cpp | 4 +++- src/slic3r/GUI/Tab.cpp | 11 ++--------- src/slic3r/GUI/Widgets/TabCtrl.cpp | 12 ++++++++++-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/OG_CustomCtrl.cpp b/src/slic3r/GUI/OG_CustomCtrl.cpp index dadde84ebcf..bfeb550d3de 100644 --- a/src/slic3r/GUI/OG_CustomCtrl.cpp +++ b/src/slic3r/GUI/OG_CustomCtrl.cpp @@ -492,13 +492,16 @@ bool OG_CustomCtrl::update_visibility(ConfigOptionMode mode) wxCoord h_pos2 = get_title_width() * m_em_unit; wxCoord v_pos = 0; - size_t invisible_lines = 0; + bool has_visible_lines = false; for (CtrlLine& line : ctrl_lines) { line.update_visibility(mode); - if (line.is_visible) + if (line.is_visible) { v_pos += (wxCoord)line.height; - else - invisible_lines++; + + if (!line.is_separator()) { // Ignore separators + has_visible_lines = true; + } + } } // BBS: multi-line title SetFont(Label::Head_16); @@ -513,7 +516,7 @@ bool OG_CustomCtrl::update_visibility(ConfigOptionMode mode) this->SetMinSize(wxSize(h_pos, v_pos)); - return invisible_lines != ctrl_lines.size(); + return has_visible_lines; } // BBS: call by Tab/Page diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index e634c4fe1a3..2f5aed9f08e 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -799,8 +799,10 @@ bool PlaterPresetComboBox::switch_to_tab() //BBS Select NoteBook Tab params if (tab->GetParent() == wxGetApp().params_panel()) wxGetApp().mainframe->select_tab(MainFrame::tp3DEditor); - else + else { wxGetApp().params_dialog()->Popup(); + tab->OnActivate(); + } tab->restore_last_select_item(); const Preset* selected_filament_preset = nullptr; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index fc37a0ea6be..077a095993c 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -468,14 +468,7 @@ void Tab::create_preset_tab() // so that the cursor jumps to the last item. // BBS: bold selection m_tabctrl->Bind(wxEVT_TAB_SEL_CHANGING, [this](wxCommandEvent& event) { - if (m_disable_tree_sel_changed_event) - return; const auto sel_item = m_tabctrl->GetSelection(); - //OutputDebugStringA("wxEVT_TAB_SEL_CHANGING "); - //OutputDebugStringA(m_title.c_str()); - //const auto selection = sel_item >= 0 ? m_tabctrl->GetItemText(sel_item) : ""; - //OutputDebugString(selection); - //OutputDebugStringA("\n"); m_tabctrl->SetItemBold(sel_item, false); }); m_tabctrl->Bind(wxEVT_TAB_SEL_CHANGED, [this](wxCommandEvent& event) { @@ -5282,10 +5275,10 @@ bool Tab::update_current_page_in_background(int& item) // clear pages from the controlls // BBS: fix after new layout, clear page in backgroud - if (m_parent->is_active_and_shown_tab((wxPanel*)this)) - m_parent->clear_page(); for (auto p : m_pages) p->clear(); + if (m_parent->is_active_and_shown_tab((wxPanel*)this)) + m_parent->clear_page(); update_undo_buttons(); diff --git a/src/slic3r/GUI/Widgets/TabCtrl.cpp b/src/slic3r/GUI/Widgets/TabCtrl.cpp index 1cfb8c55346..f766df864b2 100644 --- a/src/slic3r/GUI/Widgets/TabCtrl.cpp +++ b/src/slic3r/GUI/Widgets/TabCtrl.cpp @@ -120,6 +120,11 @@ bool TabCtrl::DeleteItem(int item) if (item < 0 || item >= btns.size()) { return false; } + const bool selection_changed = sel >= item; + + if (selection_changed) { + sendTabCtrlEvent(true); + } Button* btn = btns[item]; btn->Destroy(); @@ -127,9 +132,12 @@ bool TabCtrl::DeleteItem(int item) sizer->Remove(item * 2); if (btns.size() > 1) sizer->GetItem(sizer->GetItemCount() - 1)->SetMinSize({0, 0}); + + if (selection_changed) { + sel--; // `relayout()` uses `sel` so we need to update this before calling `relayout()` + } relayout(); - if (sel >= item) { - sel--; + if (selection_changed) { sendTabCtrlEvent(); }