New keyboard shortcuts dialog -> Fixed items order and use wxNotebook on top

This commit is contained in:
Enrico Turri 2020-02-12 08:49:56 +01:00
parent 742c6b6746
commit b5152e4126
2 changed files with 29 additions and 25 deletions

View file

@ -13,7 +13,7 @@
#define LISTBOOK_LEFT 4 #define LISTBOOK_LEFT 4
#define TOOLBOOK 5 #define TOOLBOOK 5
#define CHOICEBOOK 6 #define CHOICEBOOK 6
#define BOOK_TYPE CHOICEBOOK #define BOOK_TYPE NOTEBOOK_TOP
#if (BOOK_TYPE == NOTEBOOK_TOP) || (BOOK_TYPE == NOTEBOOK_LEFT) #if (BOOK_TYPE == NOTEBOOK_TOP) || (BOOK_TYPE == NOTEBOOK_LEFT)
#include <wx/notebook.h> #include <wx/notebook.h>
@ -75,13 +75,8 @@ main_sizer->Add(book, 1, wxEXPAND | wxALL, 10);
void KBShortcutsDialog::on_dpi_changed(const wxRect& suggested_rect) void KBShortcutsDialog::on_dpi_changed(const wxRect& suggested_rect)
{ {
m_logo_bmp.msw_rescale(); m_logo_bmp.msw_rescale();
m_header_bitmap->SetBitmap(m_logo_bmp.bmp());
for (wxStaticBitmap* bmp : m_head_bitmaps) msw_buttons_rescale(this, em_unit(), { wxID_OK });
bmp->SetBitmap(m_logo_bmp.bmp());
const int em = em_unit();
msw_buttons_rescale(this, em, { wxID_OK });
Layout(); Layout();
Fit(); Fit();
@ -224,9 +219,9 @@ wxPanel* KBShortcutsDialog::create_header(wxWindow* parent, const wxFont& bold_f
// logo // logo
m_logo_bmp = ScalableBitmap(this, "PrusaSlicer_32px.png", 32); m_logo_bmp = ScalableBitmap(this, "PrusaSlicer_32px.png", 32);
m_head_bitmaps.push_back(new wxStaticBitmap(panel, wxID_ANY, m_logo_bmp.bmp())); m_header_bitmap = new wxStaticBitmap(panel, wxID_ANY, m_logo_bmp.bmp());
sizer->Add(m_head_bitmaps.back(), 0, wxEXPAND | wxLEFT | wxRIGHT, 10); sizer->Add(m_header_bitmap, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
// text // text
wxStaticText* text = new wxStaticText(panel, wxID_ANY, _(L("Keyboard shortcuts"))); wxStaticText* text = new wxStaticText(panel, wxID_ANY, _(L("Keyboard shortcuts")));
text->SetFont(header_font); text->SetFont(header_font);
@ -241,7 +236,7 @@ wxPanel* KBShortcutsDialog::create_header(wxWindow* parent, const wxFont& bold_f
wxPanel* KBShortcutsDialog::create_page(wxWindow* parent, const std::pair<wxString, Shortcuts>& shortcuts, const wxFont& font, const wxFont& bold_font) wxPanel* KBShortcutsDialog::create_page(wxWindow* parent, const std::pair<wxString, Shortcuts>& shortcuts, const wxFont& font, const wxFont& bold_font)
{ {
static const int max_items_per_column = 20; static const int max_items_per_column = 20;
int columns_count = 2 * (1 + (int)shortcuts.second.size() / max_items_per_column); int columns_count = 1 + (int)shortcuts.second.size() / max_items_per_column;
wxPanel* page = new wxPanel(parent); wxPanel* page = new wxPanel(parent);
#if (BOOK_TYPE == LISTBOOK_TOP) || (BOOK_TYPE == LISTBOOK_LEFT) #if (BOOK_TYPE == LISTBOOK_TOP) || (BOOK_TYPE == LISTBOOK_LEFT)
@ -251,17 +246,26 @@ wxPanel* KBShortcutsDialog::create_page(wxWindow* parent, const std::pair<wxStri
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
#endif // BOOK_TYPE #endif // BOOK_TYPE
wxFlexGridSizer* grid_sizer = new wxFlexGridSizer(columns_count, 5, 15); wxFlexGridSizer* grid_sizer = new wxFlexGridSizer(2 * columns_count, 5, 15);
for (const auto& [shortcut, description] : shortcuts.second) int items_count = (int)shortcuts.second.size();
for (int i = 0; i < max_items_per_column; ++i)
{ {
auto key = new wxStaticText(page, wxID_ANY, _(shortcut)); for (int j = 0; j < columns_count; ++j)
key->SetFont(bold_font); {
grid_sizer->Add(key, 0, wxALIGN_CENTRE_VERTICAL); int id = j * max_items_per_column + i;
if (id >= items_count)
break;
auto desc = new wxStaticText(page, wxID_ANY, _(description)); const auto& [shortcut, description] = shortcuts.second[id];
desc->SetFont(font); auto key = new wxStaticText(page, wxID_ANY, _(shortcut));
grid_sizer->Add(desc, 0, wxALIGN_CENTRE_VERTICAL); key->SetFont(bold_font);
grid_sizer->Add(key, 0, wxALIGN_CENTRE_VERTICAL);
auto desc = new wxStaticText(page, wxID_ANY, _(description));
desc->SetFont(font);
grid_sizer->Add(desc, 0, wxALIGN_CENTRE_VERTICAL);
}
} }
sizer->Add(grid_sizer, 1, wxEXPAND | wxALL, 10); sizer->Add(grid_sizer, 1, wxEXPAND | wxALL, 10);

View file

@ -14,12 +14,12 @@ namespace GUI {
class KBShortcutsDialog : public DPIDialog class KBShortcutsDialog : public DPIDialog
{ {
typedef std::pair<std::string, std::string> Shortcut; typedef std::pair<std::string, std::string> Shortcut;
typedef std::vector< Shortcut > Shortcuts; typedef std::vector<Shortcut> Shortcuts;
typedef std::vector<std::pair<wxString, Shortcuts>> ShortcutsVec; typedef std::vector<std::pair<wxString, Shortcuts>> ShortcutsVec;
ShortcutsVec m_full_shortcuts; ShortcutsVec m_full_shortcuts;
ScalableBitmap m_logo_bmp; ScalableBitmap m_logo_bmp;
std::vector<wxStaticBitmap*> m_head_bitmaps; wxStaticBitmap* m_header_bitmap;
public: public:
KBShortcutsDialog(); KBShortcutsDialog();