From 87b8388f3b0393859a991848985d982175b0df1c Mon Sep 17 00:00:00 2001 From: "wenjie.guo" Date: Wed, 25 Oct 2023 18:21:50 +0800 Subject: [PATCH] FIX: limit the max width of DropDown jira: STUDIO-4503 limit the max width of DropDown for filament when user preset text is too long. Signed-off-by: wenjie.guo Change-Id: I6778fce131fb3bee38acb116fea9cbbf9baeddb7 (cherry picked from commit d5da07988e28d6c506e315dbe1ab24954c2a8a55) --- src/slic3r/GUI/PresetComboBoxes.cpp | 2 +- src/slic3r/GUI/Widgets/DropDown.cpp | 8 +++++++- src/slic3r/GUI/Widgets/DropDown.hpp | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index c2a7a3d1c..fd6678d18 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -632,7 +632,7 @@ bool PresetComboBox::selection_is_changed_according_to_physical_printers() PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset_type) : PresetComboBox(parent, preset_type, wxSize(25 * wxGetApp().em_unit(), 30 * wxGetApp().em_unit() / 10)) { - GetDropDown().SetUseContentWidth(true); + GetDropDown().SetUseContentWidth(true,true); if (m_type == Preset::TYPE_FILAMENT) { diff --git a/src/slic3r/GUI/Widgets/DropDown.cpp b/src/slic3r/GUI/Widgets/DropDown.cpp index c5f47062f..1996bd4e4 100644 --- a/src/slic3r/GUI/Widgets/DropDown.cpp +++ b/src/slic3r/GUI/Widgets/DropDown.cpp @@ -141,11 +141,12 @@ void DropDown::SetSelectorBackgroundColor(StateColor const &color) paintNow(); } -void DropDown::SetUseContentWidth(bool use) +void DropDown::SetUseContentWidth(bool use, bool limit_max_content_width) { if (use_content_width == use) return; use_content_width = use; + this->limit_max_content_width = limit_max_content_width; need_sync = true; messureSize(); } @@ -350,6 +351,11 @@ void DropDown::messureSize() szContent.x = x; } rowSize = szContent; + if (limit_max_content_width) { + wxSize parent_size = GetParent()->GetSize(); + if (rowSize.x > parent_size.x * 2) + rowSize.x = 2 * parent_size.x; + } szContent.y *= std::min((size_t)15, texts.size()); szContent.y += texts.size() > 15 ? rowSize.y / 2 : 0; wxWindow::SetSize(szContent); diff --git a/src/slic3r/GUI/Widgets/DropDown.hpp b/src/slic3r/GUI/Widgets/DropDown.hpp index e2a6cb493..4ff909c84 100644 --- a/src/slic3r/GUI/Widgets/DropDown.hpp +++ b/src/slic3r/GUI/Widgets/DropDown.hpp @@ -22,6 +22,7 @@ class DropDown : public PopupWindow double radius = 0; bool use_content_width = false; + bool limit_max_content_width = false; bool align_icon = false; bool text_off = false; @@ -74,7 +75,7 @@ public: void SetSelectorBackgroundColor(StateColor const &color); - void SetUseContentWidth(bool use); + void SetUseContentWidth(bool use, bool limit_max_content_width = false); void SetAlignIcon(bool align);