Added msw_buttons_rescale() - Function for a scaling Dialog's buttons under MSW

This commit is contained in:
YuSanka 2019-04-25 15:06:44 +02:00
parent 3f978f6afe
commit 708037158e
17 changed files with 149 additions and 43 deletions

View File

@ -133,13 +133,15 @@ void AboutDialog::on_dpi_changed(const wxRect &suggested_rect)
const int& em = em_unit();
msw_buttons_rescale(this, em, { wxID_CLOSE });
m_html->SetMinSize(wxSize(-1, 16 * em));
m_html->Refresh();
const wxSize& size = wxSize(65 * em, 30 * em);
SetMinSize(size);
SetSize(size);
Fit();
Refresh();
}

View File

@ -6,6 +6,7 @@
#include "libslic3r/Utils.hpp"
#include "GUI_App.hpp"
#include "wxExtensions.hpp"
namespace Slic3r {
namespace GUI {
@ -144,10 +145,12 @@ void ConfigSnapshotDialog::on_dpi_changed(const wxRect &suggested_rect)
html->Refresh();
const int& em = em_unit();
const wxSize& size = wxSize(45 * em, 40 * em);
msw_buttons_rescale(this, em, { wxID_CLOSE});
const wxSize& size = wxSize(45 * em, 40 * em);
SetMinSize(size);
SetSize(size);
Fit();
Refresh();
}

View File

@ -194,6 +194,9 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, wxSt
title_sizer->Add(sel_all_std, 0, wxRIGHT, BTN_SPACING);
title_sizer->Add(sel_all, 0, wxRIGHT, BTN_SPACING);
title_sizer->Add(sel_none);
// fill button indexes used later for buttons rescaling
m_button_indexes = { sel_all_std->GetId(), sel_all->GetId(), sel_none->GetId() };
}
sizer->Add(title_sizer, 0, wxEXPAND | wxBOTTOM, BTN_SPACING);
@ -1057,8 +1060,8 @@ ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason)
topsizer->AddSpacer(INDEX_MARGIN);
topsizer->Add(p->hscroll, 1, wxEXPAND);
auto *btn_sel_all = new wxButton(this, wxID_ANY, _(L("Select all standard printers")));
p->btnsizer->Add(btn_sel_all);
p->btn_sel_all = new wxButton(this, wxID_ANY, _(L("Select all standard printers")));
p->btnsizer->Add(p->btn_sel_all);
p->btn_prev = new wxButton(this, wxID_ANY, _(L("< &Back")));
p->btn_next = new wxButton(this, wxID_ANY, _(L("&Next >")));
@ -1130,7 +1133,7 @@ ConfigWizard::ConfigWizard(wxWindow *parent, RunReason reason)
p->btn_finish->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) { this->EndModal(wxID_OK); });
p->btn_finish->Hide();
btn_sel_all->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) {
p->btn_sel_all->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) {
p->page_fff->select_all(true, false);
p->page_msla->select_all(true, false);
p->index->go_to(p->page_update);
@ -1179,6 +1182,20 @@ const wxString& ConfigWizard::name(const bool from_menu/* = false*/)
void ConfigWizard::on_dpi_changed(const wxRect &suggested_rect)
{
p->index->msw_rescale();
const int& em = em_unit();
msw_buttons_rescale(this, em, { wxID_APPLY,
wxID_CANCEL,
p->btn_sel_all->GetId(),
p->btn_next->GetId(),
p->btn_prev->GetId() });
for (auto printer_picker: p->page_fff->printer_pickers)
msw_buttons_rescale(this, em, printer_picker->get_button_indexes());
// FIXME VK SetSize(???)
Refresh();
}

View File

@ -69,8 +69,11 @@ struct PrinterPicker: wxPanel
void on_checkbox(const Checkbox *cbox, bool checked);
int get_width() const { return width; }
const std::vector<int>& get_button_indexes() { return m_button_indexes; }
private:
int width;
std::vector<int> m_button_indexes;
};
struct ConfigWizardPage: wxPanel
@ -267,6 +270,7 @@ struct ConfigWizard::priv
wxBoxSizer *btnsizer = nullptr;
ConfigWizardPage *page_current = nullptr;
ConfigWizardIndex *index = nullptr;
wxButton *btn_sel_all = nullptr;
wxButton *btn_prev = nullptr;
wxButton *btn_next = nullptr;
wxButton *btn_finish = nullptr;

View File

@ -379,8 +379,8 @@ void TextCtrl::change_field_value(wxEvent& event)
void CheckBox::BUILD() {
auto size = wxSize(wxDefaultSize);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit);
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
bool check_value = m_opt.type == coBool ?
m_opt.default_value->getBool() : m_opt.type == coBools ?
@ -413,6 +413,14 @@ boost::any& CheckBox::get_value()
return m_value;
}
void CheckBox::msw_rescale()
{
Field::msw_rescale();
wxCheckBox* field = dynamic_cast<wxCheckBox*>(window);
field->SetMinSize(wxSize(-1, int(1.5f*field->GetFont().GetPixelSize().y +0.5f)));
}
int undef_spin_val = -9999; //! Probably, It's not necessary
void SpinCtrl::BUILD() {
@ -849,9 +857,11 @@ void Choice::msw_rescale()
*/
field->Clear();
wxSize size(wxDefaultSize);
if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit);
size.SetWidth((m_opt.width > 0 ? m_opt.width : m_width) * m_em_unit);
// Set rescaled min height to correct layout
field->SetMinSize(wxSize(-1, int(1.5f*field->GetFont().GetPixelSize().y + 0.5f)));
// Set rescaled size
field->SetSize(size);
size_t idx, counter = idx = 0;

View File

@ -319,6 +319,8 @@ public:
}
boost::any& get_value() override;
void msw_rescale() override;
void enable() override { dynamic_cast<wxCheckBox*>(window)->Enable(); }
void disable() override { dynamic_cast<wxCheckBox*>(window)->Disable(); }
wxWindow* getWindow() override { return window; }

View File

@ -18,6 +18,7 @@
#include "MsgDialog.hpp"
#include "../Utils/HexFile.hpp"
#include "../Utils/Serial.hpp"
#include "wxExtensions.hpp"
// wx includes need to come after asio because of the WinSock.h problem
#include "FirmwareDialog.hpp"
@ -118,6 +119,10 @@ struct FirmwareDialog::priv
wxTimer timer_pulse;
int min_width;
int min_height;
int min_height_expanded;
// Async modal dialog during flashing
std::mutex mutex;
int modal_response;
@ -735,18 +740,10 @@ FirmwareDialog::FirmwareDialog(wxWindow *parent) :
GUI::DPIDialog(parent, wxID_ANY, _(L("Firmware flasher")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
p(new priv(this))
{
enum {
DIALOG_MARGIN = 15,
SPACING = 10,
MIN_WIDTH = 50,
MIN_HEIGHT = 18,
MIN_HEIGHT_EXPANDED = 40,
};
const int em = GUI::wxGetApp().em_unit();
int min_width = MIN_WIDTH * em;
int min_height = MIN_HEIGHT * em;
int min_height_expanded = MIN_HEIGHT_EXPANDED * em;
p->min_width = MIN_WIDTH * em;
p->min_height = MIN_HEIGHT * em;
p->min_height_expanded = MIN_HEIGHT_EXPANDED * em;
/* get current font from application,
* because of wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) function
@ -825,10 +822,10 @@ FirmwareDialog::FirmwareDialog(wxWindow *parent) :
auto *topsizer = new wxBoxSizer(wxVERTICAL);
topsizer->Add(panel, 1, wxEXPAND | wxALL, DIALOG_MARGIN);
SetMinSize(wxSize(min_width, min_height));
SetMinSize(wxSize(p->min_width, p->min_height));
SetSizerAndFit(topsizer);
const auto size = GetSize();
SetSize(std::max(size.GetWidth(), static_cast<int>(min_width)), std::max(size.GetHeight(), static_cast<int>(min_height)));
SetSize(std::max(size.GetWidth(), static_cast<int>(p->min_width)), std::max(size.GetHeight(), static_cast<int>(p->min_height)));
Layout();
SetEscapeId(wxID_CLOSE); // To close the dialog using "Esc" button
@ -844,11 +841,11 @@ FirmwareDialog::FirmwareDialog(wxWindow *parent) :
p->spoiler->Bind(wxEVT_COLLAPSIBLEPANE_CHANGED, [=](wxCollapsiblePaneEvent &evt) {
if (evt.GetCollapsed()) {
this->SetMinSize(wxSize(min_width, min_height));
this->SetMinSize(wxSize(p->min_width, p->min_height));
const auto new_height = this->GetSize().GetHeight() - this->p->txt_stdout->GetSize().GetHeight();
this->SetSize(this->GetSize().GetWidth(), new_height);
} else {
this->SetMinSize(wxSize(min_width, min_height_expanded));
this->SetMinSize(wxSize(p->min_width, p->min_height_expanded));
}
this->Layout();
@ -903,5 +900,25 @@ void FirmwareDialog::run(wxWindow *parent)
dialog.ShowModal();
}
void FirmwareDialog::on_dpi_changed(const wxRect &suggested_rect)
{
const int& em = em_unit();
msw_buttons_rescale(this, em, { p->btn_close->GetId(),
p->btn_rescan->GetId(),
p->btn_flash->GetId(),
p->hex_picker->GetPickerCtrl()->GetId()
});
p->min_width = MIN_WIDTH * em;
p->min_height = MIN_HEIGHT * em;
p->min_height_expanded = MIN_HEIGHT_EXPANDED * em;
const int min_height = p->spoiler->IsExpanded() ? p->min_height_expanded : p->min_height;
SetMinSize(wxSize(p->min_width, min_height));
Fit();
Refresh();
}
}

View File

@ -12,6 +12,14 @@ namespace Slic3r {
class FirmwareDialog: public GUI::DPIDialog
{
enum {
DIALOG_MARGIN = 15,
SPACING = 10,
MIN_WIDTH = 50,
MIN_HEIGHT = /*18*/25,
MIN_HEIGHT_EXPANDED = 40,
};
public:
FirmwareDialog(wxWindow *parent);
FirmwareDialog(FirmwareDialog &&) = delete;
@ -23,7 +31,7 @@ public:
static void run(wxWindow *parent);
protected:
void on_dpi_changed(const wxRect &suggested_rect) override{;}
void on_dpi_changed(const wxRect &suggested_rect) override;
private:
struct priv;
std::unique_ptr<priv> p;

View File

@ -196,11 +196,14 @@ void KBShortcutsDialog::on_dpi_changed(const wxRect &suggested_rect)
for (wxStaticBitmap* bmp : m_head_bitmaps)
bmp->SetBitmap(m_logo_bmp.bmp());
const int& em = em_unit();
const int em = em_unit();
msw_buttons_rescale(this, em, { wxID_OK });
const wxSize& size = wxSize(85 * em, 75 * em);
SetMinSize(size);
SetSize(size);
Fit();
Refresh();
}

View File

@ -516,17 +516,19 @@ void ConfigOptionsGroup::msw_rescale()
{
auto label = dynamic_cast<wxStaticText*>(label_item->GetWindow());
if (label != nullptr) {
label->SetMinSize(wxSize(label_width*em, -1));
const int label_height = int(1.5f*label->GetFont().GetPixelSize().y + 0.5f);
label->SetMinSize(wxSize(label_width*em, /*-1*/label_height));
}
}
else if (label_item->IsSizer()) // case when we nave near_label_widget
else if (label_item->IsSizer()) // case when we have near_label_widget
{
const wxSizerItem* l_item = label_item->GetSizer()->GetItem(1);
if (l_item->IsWindow())
{
auto label = dynamic_cast<wxStaticText*>(l_item->GetWindow());
if (label != nullptr) {
label->SetMinSize(wxSize(label_width*em, -1));
const int label_height = int(1.5f*label->GetFont().GetPixelSize().y + 0.5f);
label->SetMinSize(wxSize(label_width*em, /*-1*/label_height));
}
}
}

View File

@ -8,7 +8,7 @@ namespace GUI {
PreferencesDialog::PreferencesDialog(wxWindow* parent) :
DPIDialog(parent, wxID_ANY, _(L("Preferences")), wxDefaultPosition,
wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
{
build();
}
@ -146,11 +146,14 @@ void PreferencesDialog::on_dpi_changed(const wxRect &suggested_rect)
{
m_optgroup->msw_rescale();
const int& em = em_unit();
const wxSize& size = wxSize(50 * em, 29 * em);
const int em = em_unit();
msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL });
const wxSize& size = wxSize(47 * em, 28 * em);
SetMinSize(size);
SetSize(size);
Fit();
Refresh();
}

View File

@ -19,6 +19,7 @@
#include "MsgDialog.hpp"
#include "I18N.hpp"
#include "../Utils/PrintHost.hpp"
#include "wxExtensions.hpp"
namespace fs = boost::filesystem;
@ -136,8 +137,6 @@ PrintHostQueueDialog::PrintHostQueueDialog(wxWindow *parent)
, on_error_evt(this, EVT_PRINTHOST_ERROR, &PrintHostQueueDialog::on_error, this)
, on_cancel_evt(this, EVT_PRINTHOST_CANCEL, &PrintHostQueueDialog::on_cancel, this)
{
enum { HEIGHT = 60, WIDTH = 30, SPACING = 5 };
const auto em = GetTextExtent("m").x;
SetSize(wxSize(HEIGHT * em, WIDTH * em));
@ -202,6 +201,18 @@ void PrintHostQueueDialog::append_job(const PrintHostJob &job)
job_list->AppendItem(fields, static_cast<wxUIntPtr>(ST_NEW));
}
void PrintHostQueueDialog::on_dpi_changed(const wxRect &suggested_rect)
{
const int& em = em_unit();
msw_buttons_rescale(this, em, { wxID_DELETE, wxID_CANCEL, btn_error->GetId() });
SetMinSize(wxSize(HEIGHT * em, WIDTH * em));
Fit();
Refresh();
}
PrintHostQueueDialog::JobState PrintHostQueueDialog::get_state(int idx)
{
wxCHECK_MSG(idx >= 0 && idx < job_list->GetItemCount(), ST_ERROR, "Out of bounds access to job list");

View File

@ -64,7 +64,7 @@ public:
void append_job(const PrintHostJob &job);
protected:
void on_dpi_changed(const wxRect &suggested_rect) override { Refresh(); }
void on_dpi_changed(const wxRect &suggested_rect) override;
private:
enum Column {
@ -85,6 +85,8 @@ private:
ST_COMPLETED,
};
enum { HEIGHT = 60, WIDTH = 30, SPACING = 5 };
wxButton *btn_cancel;
wxButton *btn_error;
wxDataViewListCtrl *job_list;

View File

@ -117,9 +117,10 @@ SysInfoDialog::SysInfoDialog()
}
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK);
auto btn_copy_to_clipboard = new wxButton(this, wxID_ANY, "Copy to Clipboard", wxDefaultPosition, wxDefaultSize);
buttons->Insert(0, btn_copy_to_clipboard, 0, wxLEFT, 5);
btn_copy_to_clipboard->Bind(wxEVT_BUTTON, &SysInfoDialog::onCopyToClipboard, this);
m_btn_copy_to_clipboard = new wxButton(this, wxID_ANY, "Copy to Clipboard", wxDefaultPosition, wxDefaultSize);
buttons->Insert(0, m_btn_copy_to_clipboard, 0, wxLEFT, 5);
m_btn_copy_to_clipboard->Bind(wxEVT_BUTTON, &SysInfoDialog::onCopyToClipboard, this);
this->SetEscapeId(wxID_OK);
this->Bind(wxEVT_BUTTON, &SysInfoDialog::onCloseDialog, this, wxID_OK);
@ -146,6 +147,8 @@ void SysInfoDialog::on_dpi_changed(const wxRect &suggested_rect)
const int& em = em_unit();
msw_buttons_rescale(this, em, { wxID_OK, m_btn_copy_to_clipboard->GetId() });
m_opengl_info_html->SetMinSize(wxSize(-1, 16 * em));
m_opengl_info_html->SetFonts(font.GetFaceName(), font.GetFaceName(), font_size);
m_opengl_info_html->Refresh();
@ -153,7 +156,7 @@ void SysInfoDialog::on_dpi_changed(const wxRect &suggested_rect)
const wxSize& size = wxSize(65 * em, 55 * em);
SetMinSize(size);
SetSize(size);
Fit();
Refresh();
}

View File

@ -17,6 +17,8 @@ class SysInfoDialog : public DPIDialog
wxHtmlWindow* m_opengl_info_html;
wxHtmlWindow* m_html;
wxButton* m_btn_copy_to_clipboard;
public:
SysInfoDialog();

View File

@ -267,6 +267,22 @@ void wxDataViewTreeCtrlComboPopup::OnDataViewTreeCtrlSelection(wxCommandEvent& e
cmb->SetText(selected);
}
/* Function for rescale of buttons in Dialog under MSW if dpi is changed.
* btn_ids - vector of buttons identifiers
*/
void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<int>& btn_ids)
{
const wxSize& btn_size = wxSize(-1, int(2.5f * em_unit + 0.5f));
for (int btn_id : btn_ids) {
// There is a case [FirmwareDialog], when we have wxControl instead of wxButton
// so let casting everything to the wxControl
wxControl* btn = static_cast<wxControl*>(dlg->FindWindowById(btn_id, dlg));
if (btn)
btn->SetMinSize(btn_size);
}
}
/* Function for getting of em_unit value from correct parent.
* In most of cases it is m_em_unit value from GUI_App,
* but for DPIDialogs it's its own value.

View File

@ -31,7 +31,8 @@ wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxStrin
wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, const wxString& description,
std::function<void(wxCommandEvent& event)> cb, wxEvtHandler* event_handler);
int em_unit(wxWindow* win);
void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector<int>& btn_ids);
int em_unit(wxWindow* win);
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name, const int px_cnt = 16, const bool is_horizontal = false);