diff options
author | YuSanka <yusanka@gmail.com> | 2021-09-13 11:29:41 +0300 |
---|---|---|
committer | YuSanka <yusanka@gmail.com> | 2021-09-13 11:30:09 +0300 |
commit | 5a95794913a053611c5887ee7460d2da8ed75ac5 (patch) | |
tree | 6d668aa799309d685c057388229ecf7594348d94 /src/slic3r | |
parent | ae7d6db1d961f85b8e2788d707cef03de7e28fdb (diff) |
OSX specific: Improvements for wxMultiChoiceDialog: Height of a ChoiceListBox will respect to items count
This improvement fixed #6926 - Checkbox columns in modal windows are stretched (macOS)
Diffstat (limited to 'src/slic3r')
-rw-r--r-- | src/slic3r/GUI/GUI_Factories.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/slic3r/GUI/GUI_Factories.cpp b/src/slic3r/GUI/GUI_Factories.cpp index 92ba427b5..4fec12d14 100644 --- a/src/slic3r/GUI/GUI_Factories.cpp +++ b/src/slic3r/GUI/GUI_Factories.cpp @@ -16,6 +16,10 @@ #include <boost/algorithm/string.hpp> #include "slic3r/Utils/FixModelByWin10.hpp" +#ifdef __APPLE__ +#include "wx/dcclient.h" +#include "slic3r/Utils/MacDarkMode.hpp" +#endif namespace Slic3r { @@ -211,7 +215,6 @@ static int GetSelectedChoices( wxArrayInt& selections, const wxString& caption, const wxArrayString& choices) { -#ifdef _WIN32 wxMultiChoiceDialog dialog(nullptr, message, caption, choices); wxGetApp().UpdateDlgDarkUI(&dialog); @@ -219,6 +222,39 @@ static int GetSelectedChoices( wxArrayInt& selections, // deselects the first item which is selected by default dialog.SetSelections(selections); +#ifdef __APPLE__ + // Improvements for ChoiceListBox: Height of control will restect to items count + for (auto child : dialog.GetChildren()) + if (dynamic_cast<wxListBox*>(child) && !choices.IsEmpty()) { + wxClientDC dc(child); + + int height = dc.GetTextExtent(choices[0]).y; + int width = 0; + for (const auto& string : choices) + width = std::max(width, dc.GetTextExtent(string).x); + + // calculate best size of ListBox + height += 3 * mac_max_scaling_factor(); // extend height by margins + width += 3 * height; // extend width by checkbox width and margins + + // don't make the listbox too tall (limit height to around 10 items) + // but don't make it too small neither + int list_height = wxMax(height * wxMin(wxMax(choices.Count(), 3), 10), 70); + wxSize sz_best = wxSize(width, list_height); + + wxSize sz = child->GetSize(); + child->SetMinSize(sz_best); + + // extend Dialog size, if calculated best size of ListBox is bigger then its size + wxSize dlg_sz = dialog.GetSize(); + if (int delta_x = sz_best.x - sz.x; delta_x > 0) dlg_sz.x += delta_x; + if (int delta_y = sz_best.y - sz.y; delta_y > 0) dlg_sz.y += delta_y; + dialog.SetSize(dlg_sz); + + break; + } +#endif + if (dialog.ShowModal() != wxID_OK) { // NB: intentionally do not clear the selections array here, the caller @@ -229,9 +265,6 @@ static int GetSelectedChoices( wxArrayInt& selections, selections = dialog.GetSelections(); return static_cast<int>(selections.GetCount()); -#else - return wxGetSelectedChoices(selections, message, caption, choices); -#endif } static wxMenu* create_settings_popupmenu(wxMenu* parent_menu, const bool is_object_settings, wxDataViewItem item/*, ModelConfig& config*/) |