From fe7204379d6080b38f281d843ec2f3c607b09a83 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 14 Jul 2021 16:45:15 +0200 Subject: [PATCH] GalleryDialog: Fixed sort of the filenames inside the list. + OSX Specific: * Fixed scale of the lock on the system file icons * Fixed buttons alignment for AboutDialog and SysInfoDialog --- src/slic3r/GUI/AboutDialog.cpp | 4 ++-- src/slic3r/GUI/GalleryDialog.cpp | 28 +++++++++++++++++++--------- src/slic3r/GUI/SysInfoDialog.cpp | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/AboutDialog.cpp b/src/slic3r/GUI/AboutDialog.cpp index b9417c8a24..fdbc1a6d3d 100644 --- a/src/slic3r/GUI/AboutDialog.cpp +++ b/src/slic3r/GUI/AboutDialog.cpp @@ -299,12 +299,12 @@ AboutDialog::AboutDialog() m_copy_rights_btn_id = NewControlId(); auto copy_rights_btn = new wxButton(this, m_copy_rights_btn_id, _L("Portions copyright")+dots); - buttons->Insert(0, copy_rights_btn, 0, wxLEFT, 5); + buttons->Insert(0, copy_rights_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5); copy_rights_btn->Bind(wxEVT_BUTTON, &AboutDialog::onCopyrightBtn, this); m_copy_version_btn_id = NewControlId(); auto copy_version_btn = new wxButton(this, m_copy_version_btn_id, _L("Copy Version Info")); - buttons->Insert(1, copy_version_btn, 0, wxLEFT, 5); + buttons->Insert(1, copy_version_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5); copy_version_btn->Bind(wxEVT_BUTTON, &AboutDialog::onCopyToClipboard, this); wxGetApp().UpdateDlgDarkUI(this, true); diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp index 6f1be8ddcf..078aa82d68 100644 --- a/src/slic3r/GUI/GalleryDialog.cpp +++ b/src/slic3r/GUI/GalleryDialog.cpp @@ -74,7 +74,7 @@ GalleryDialog::GalleryDialog(wxWindow* parent) : wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _L("Select shape from the gallery") + ":"); m_list_ctrl = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(55 * wxGetApp().em_unit(), 35 * wxGetApp().em_unit()), - wxLC_ICON | wxLC_NO_HEADER | wxLC_ALIGN_TOP | wxSIMPLE_BORDER); + wxLC_ICON | wxSIMPLE_BORDER); m_list_ctrl->Bind(wxEVT_LIST_ITEM_SELECTED, &GalleryDialog::select, this); m_list_ctrl->Bind(wxEVT_LIST_ITEM_DESELECTED, &GalleryDialog::deselect, this); m_list_ctrl->Bind(wxEVT_LIST_ITEM_ACTIVATED, [this](wxListEvent& event) { @@ -82,10 +82,12 @@ GalleryDialog::GalleryDialog(wxWindow* parent) : select(event); this->EndModal(wxID_OK); }); +#ifdef _WIN32 this->Bind(wxEVT_SIZE, [this](wxSizeEvent& event) { event.Skip(); m_list_ctrl->Arrange(); }); +#endif wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); wxButton* ok_btn = static_cast(FindWindowById(wxID_OK, this)); @@ -98,7 +100,7 @@ GalleryDialog::GalleryDialog(wxWindow* parent) : wxButton* btn = new wxButton(this, ID, title); btn->SetToolTip(tooltip); btn->Bind(wxEVT_UPDATE_UI, [enable_fn](wxUpdateUIEvent& evt) { evt.Enable(enable_fn()); }); - buttons->Insert(pos, btn, 0, wxRIGHT, BORDER_W); + buttons->Insert(pos, btn, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, BORDER_W); this->Bind(wxEVT_BUTTON, method, this, ID); }; @@ -153,13 +155,16 @@ void GalleryDialog::on_dpi_changed(const wxRect& suggested_rect) static void add_lock(wxImage& image) { + int lock_sz = 22; +#ifdef __APPLE__ + lock_sz /= mac_max_scaling_factor(); +#endif wxBitmap bmp = create_scaled_bitmap("lock", nullptr, 22); wxImage lock_image = bmp.ConvertToImage(); if (!lock_image.IsOk() || lock_image.GetWidth() == 0 || lock_image.GetHeight() == 0) return; - int icon_sz = 16; auto lock_px_data = (uint8_t*)lock_image.GetData(); auto lock_a_data = (uint8_t*)lock_image.GetAlpha(); int lock_width = lock_image.GetWidth(); @@ -293,12 +298,17 @@ void GalleryDialog::load_label_icon_list() fs::path dir = get_dir(sys_dir); dir_path = get_dir_path(sys_dir); + std::vector sorted_names; for (auto& dir_entry : fs::directory_iterator(dir)) - if (TriangleMesh mesh; is_stl_file(dir_entry) && mesh.ReadSTLFile(dir_entry.path().string().c_str())) { - std::string name = dir_entry.path().stem().string(); - Item item = Item{ name, sys_dir }; - items.push_back(item); - } + if (TriangleMesh mesh; is_stl_file(dir_entry) && mesh.ReadSTLFile(dir_entry.path().string().c_str())) + sorted_names.push_back(dir_entry.path().stem().string()); + + // sort the filename case insensitive + std::sort(sorted_names.begin(), sorted_names.end(), [](const std::string& a, const std::string& b) + { return boost::algorithm::to_lower_copy(a) < boost::algorithm::to_lower_copy(b); }); + + for (const std::string& name : sorted_names) + items.push_back(Item{ name, sys_dir }); }; wxBusyCursor busy; @@ -343,7 +353,7 @@ void GalleryDialog::load_label_icon_list() for (int i = 0; i < img_cnt; i++) { m_list_ctrl->InsertItem(i, from_u8(list_items[i].name), i); if (list_items[i].is_system) - m_list_ctrl->SetItemFont(i, m_list_ctrl->GetItemFont(i).Bold()); + m_list_ctrl->SetItemFont(i, wxGetApp().bold_font()); } } diff --git a/src/slic3r/GUI/SysInfoDialog.cpp b/src/slic3r/GUI/SysInfoDialog.cpp index 03faf935d0..2b835a96b6 100644 --- a/src/slic3r/GUI/SysInfoDialog.cpp +++ b/src/slic3r/GUI/SysInfoDialog.cpp @@ -163,7 +163,7 @@ SysInfoDialog::SysInfoDialog() wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK); m_btn_copy_to_clipboard = new wxButton(this, wxID_ANY, _L("Copy to Clipboard"), wxDefaultPosition, wxDefaultSize); - buttons->Insert(0, m_btn_copy_to_clipboard, 0, wxLEFT, 5); + buttons->Insert(0, m_btn_copy_to_clipboard, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5); m_btn_copy_to_clipboard->Bind(wxEVT_BUTTON, &SysInfoDialog::onCopyToClipboard, this); this->SetEscapeId(wxID_OK);