diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 671d5674b6..5e68e9de30 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -469,7 +469,6 @@ struct Sidebar::priv ScalableButton * m_bpButton_ams_filament; ScalableButton * m_bpButton_set_filament; int m_menu_filament_id = -1; - int filament_area_height; wxScrolledWindow* m_panel_filament_content; wxScrolledWindow* m_scrolledWindow_filament_content; wxStaticLine* m_staticline2; @@ -2106,14 +2105,10 @@ Sidebar::Sidebar(Plater *parent) bSizer39->AddSpacer(FromDIP(SidebarProps::TitlebarMargin())); // add filament content - // ORCA use a height with user preference - int filament_count_user = std::stoi(wxGetApp().app_config->get("filaments_area_preferred_count")); - p->filament_area_height = std::ceil(filament_count_user * 0.5) * (30 + SidebarProps::ElementSpacing()) - SidebarProps::ElementSpacing(); - p->m_panel_filament_content = new wxScrolledWindow( p->scrolled, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); p->m_panel_filament_content->SetScrollbars(0, 100, 1, 2); p->m_panel_filament_content->SetScrollRate(0, 5); - p->m_panel_filament_content->SetMaxSize(wxSize{-1, FromDIP(p->filament_area_height)}); // ORCA + //p->m_panel_filament_content->SetMaxSize(wxSize{-1, FromDIP(174)}); p->m_panel_filament_content->SetBackgroundColour(wxColour(255, 255, 255)); //wxBoxSizer* bSizer_filament_content; @@ -2135,10 +2130,9 @@ Sidebar::Sidebar(Plater *parent) sizer_filaments2->Add(p->sizer_filaments, 0, wxEXPAND, 0); p->m_panel_filament_content->SetSizer(sizer_filaments2); p->m_panel_filament_content->Layout(); - auto min_size = sizer_filaments2->GetMinSize(); - if (min_size.y > p->m_panel_filament_content->GetMaxHeight()) - min_size.y = p->m_panel_filament_content->GetMaxHeight(); - p->m_panel_filament_content->SetMinSize(min_size); + + update_filaments_area_height(); // ORCA + scrolled_sizer->Add(p->m_panel_filament_content, 0, wxEXPAND | wxTOP | wxBOTTOM, FromDIP(SidebarProps::ContentMarginV())); // ORCA use vertical margin on parent otherwise it shows scrollbar even on 1 filament } @@ -2776,6 +2770,23 @@ void Sidebar::change_top_border_for_mode_sizer(bool increase_border) #endif } +void Sidebar::update_filaments_area_height() +// ORCA +{ + // ORCA use a height with user preference + auto left_sizer = p->sizer_filaments->GetItem((size_t) 0)->GetSizer(); + auto combo_sizer = left_sizer->GetItem((size_t) 0)->GetSizer(); + int preferred_rows = std::ceil(0.5 * std::stoi(wxGetApp().app_config->get("filaments_area_preferred_count"))); + auto height_with_borders = combo_sizer->GetSize().GetHeight(); // gets height from sizer instead static numbers + p->m_panel_filament_content->SetMaxSize(wxSize{-1, preferred_rows * height_with_borders}); + + // fixes wxScrolledWindow not shrinks its height to content size + auto min_size = p->m_panel_filament_content->GetSizer()->GetMinSize(); + if (min_size.y > p->m_panel_filament_content->GetMaxHeight()) + min_size.y = p->m_panel_filament_content->GetMaxHeight(); + p->m_panel_filament_content->SetMinSize({-1, min_size.y}); +} + void Sidebar::msw_rescale() { SetMinSize(wxSize(42 * wxGetApp().em_unit(), -1)); @@ -2846,6 +2857,9 @@ void Sidebar::msw_rescale() for (PlaterPresetComboBox* combo : p->combos_filament) combo->msw_rescale(); + p->m_panel_filament_content->Layout(); + update_filaments_area_height(); // ORCA resize after combos scaled + // BBS //p->frequently_changed_parameters->msw_rescale(); //obj_list()->msw_rescale(); @@ -3024,10 +3038,7 @@ void Sidebar::on_filament_count_change(size_t num_filaments) } } - auto min_size = p->m_panel_filament_content->GetSizer()->GetMinSize(); - if (min_size.y > p->m_panel_filament_content->GetMaxHeight()) - min_size.y = p->m_panel_filament_content->GetMaxHeight(); - p->m_panel_filament_content->SetMinSize(min_size); + update_filaments_area_height(); // ORCA Layout(); p->m_panel_filament_title->Refresh(); @@ -3087,10 +3098,7 @@ void Sidebar::on_filaments_delete(size_t filament_id) p->combos_filament[idx]->update(); } - auto min_size = p->m_panel_filament_content->GetSizer()->GetMinSize(); - if (min_size.y > p->m_panel_filament_content->GetMaxHeight()) - min_size.y = p->m_panel_filament_content->GetMaxHeight(); - p->m_panel_filament_content->SetMinSize(min_size); + update_filaments_area_height(); // ORCA Layout(); p->m_panel_filament_title->Refresh(); @@ -3524,11 +3532,8 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) for (auto& c : p->combos_filament) c->update(); // Expand filament list - p->m_panel_filament_content->SetMaxSize({-1, FromDIP(p->filament_area_height)}); // ORCA - auto min_size = p->m_panel_filament_content->GetSizer()->GetMinSize(); - if (min_size.y > p->m_panel_filament_content->GetMaxHeight()) - min_size.y = p->m_panel_filament_content->GetMaxHeight(); - p->m_panel_filament_content->SetMinSize({-1, min_size.y}); + update_filaments_area_height(); // ORCA + // BBS:Synchronized consumables information // auto calculation of flushing volumes for (int i = 0; i < p->combos_filament.size(); ++i) { diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 89b9f560c4..3708e52b42 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -172,6 +172,7 @@ public: void set_bed_type_accord_combox(BedType bed_type); bool reset_bed_type_combox_choices(bool is_sidebar_init = false); void change_top_border_for_mode_sizer(bool increase_border); + void update_filaments_area_height(); void msw_rescale(); void sys_color_changed(); void search(); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 5c47e629c7..1a52f886ca 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -589,6 +589,14 @@ wxBoxSizer *PreferencesDialog::create_item_spinctrl(wxString title, wxString tit e.Skip(); }); + input->Bind(wxEVT_SPINCTRL, [this, param, input, onchange](wxCommandEvent& e) { + auto value = input->GetValue(); + app_config->set(param, std::to_string(value)); + app_config->save(); + if (onchange != nullptr) onchange(value); + e.Skip(); + }); + input->Bind(wxEVT_KILL_FOCUS, [this, param, input, onchange](wxFocusEvent &e) { auto value = input->GetValue(); app_config->set(param, std::to_string(value)); @@ -1395,7 +1403,13 @@ void PreferencesDialog::create_items() "group_filament_presets", {_L("All"), _L("None"), _L("By type"), _L("By vendor")}, [](wxString value) {wxGetApp().plater()->sidebar().update_presets(Preset::TYPE_FILAMENT);}); g_sizer->Add(item_filament_preset_grouping); - auto item_filament_area_height = create_item_spinctrl(_L("Optimize filaments area height for..."), _L("(Requires restart)"), _L("filaments"), _L("Optimizes filament area maximum height by chosen filament count."), "filaments_area_preferred_count", 8, 99); + // prevent burst calling on keyboard / spin events + m_filament_height_timer.Bind(wxEVT_TIMER, [this](wxTimerEvent&) { + wxGetApp().plater()->sidebar().update_filaments_area_height(); + UpdateSidebarLayout(); + }); + auto item_filament_area_height = create_item_spinctrl(_L("Optimize filaments area height for..."), "", _L("filaments"), _L("Optimizes filament area maximum height by chosen filament count."), + "filaments_area_preferred_count", 8, 99, [this](int value) {m_filament_height_timer.StartOnce(500);}); g_sizer->Add(item_filament_area_height); //// GENERAL > Features @@ -1947,4 +1961,22 @@ wxBoxSizer* PreferencesDialog::create_debug_page() return bSizer; } +void PreferencesDialog::UpdateSidebarLayout() +{ + Plater* plater = wxGetApp().plater(); + if (!plater) return; + + Sidebar& sidebar = plater->sidebar(); + + sidebar.Freeze(); + + sidebar.Layout(); + //plater->Layout(); + //wxGetApp().mainframe->Layout(); + + sidebar.Thaw(); + + plater->PostSizeEvent(); +} + }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index a097dccee2..73e61938d6 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -63,6 +63,7 @@ public: ~PreferencesDialog(); wxString m_backup_interval_time; + wxTimer m_filament_height_timer; void create(); @@ -109,6 +110,8 @@ public: void create_shortcuts_page(); wxBoxSizer* create_debug_page(); + void UpdateSidebarLayout(); + // BBS void create_select_domain_widget();