Implemented em_unit() function for getting of em_unit value from correct parent.
+ Added correct em_unit to Fields
This commit is contained in:
parent
3e9c0c396e
commit
077321b228
4 changed files with 64 additions and 20 deletions
|
@ -65,6 +65,9 @@ void Field::PostInitialize()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initialize m_unit_value
|
||||||
|
m_em_unit = em_unit(m_parent);
|
||||||
|
|
||||||
BUILD();
|
BUILD();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,8 +215,8 @@ bool is_defined_input_value(wxWindow* win, const ConfigOptionType& type)
|
||||||
|
|
||||||
void TextCtrl::BUILD() {
|
void TextCtrl::BUILD() {
|
||||||
auto size = wxSize(wxDefaultSize);
|
auto size = wxSize(wxDefaultSize);
|
||||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit());
|
if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit);
|
||||||
if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit());
|
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
|
||||||
|
|
||||||
wxString text_value = wxString("");
|
wxString text_value = wxString("");
|
||||||
|
|
||||||
|
@ -361,8 +364,8 @@ void TextCtrl::rescale()
|
||||||
{
|
{
|
||||||
Field::rescale();
|
Field::rescale();
|
||||||
auto size = wxSize(wxDefaultSize);
|
auto size = wxSize(wxDefaultSize);
|
||||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit());
|
if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit);
|
||||||
if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit());
|
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
|
||||||
|
|
||||||
if (size != wxDefaultSize)
|
if (size != wxDefaultSize)
|
||||||
{
|
{
|
||||||
|
@ -424,8 +427,8 @@ int undef_spin_val = -9999; //! Probably, It's not necessary
|
||||||
|
|
||||||
void SpinCtrl::BUILD() {
|
void SpinCtrl::BUILD() {
|
||||||
auto size = wxSize(wxDefaultSize);
|
auto size = wxSize(wxDefaultSize);
|
||||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit());
|
if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit);
|
||||||
if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit());
|
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
|
||||||
|
|
||||||
wxString text_value = wxString("");
|
wxString text_value = wxString("");
|
||||||
int default_value = 0;
|
int default_value = 0;
|
||||||
|
@ -529,9 +532,9 @@ void SpinCtrl::rescale()
|
||||||
}
|
}
|
||||||
|
|
||||||
void Choice::BUILD() {
|
void Choice::BUILD() {
|
||||||
wxSize size(m_width * wxGetApp().em_unit(), -1);
|
wxSize size(m_width * m_em_unit, -1);
|
||||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit());
|
if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit);
|
||||||
if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit());
|
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
|
||||||
|
|
||||||
wxBitmapComboBox* temp;
|
wxBitmapComboBox* temp;
|
||||||
if (!m_opt.gui_type.empty() && m_opt.gui_type.compare("select_open") != 0) {
|
if (!m_opt.gui_type.empty() && m_opt.gui_type.compare("select_open") != 0) {
|
||||||
|
@ -856,8 +859,8 @@ void Choice::rescale()
|
||||||
*/
|
*/
|
||||||
field->Clear();
|
field->Clear();
|
||||||
wxSize size(wxDefaultSize);
|
wxSize size(wxDefaultSize);
|
||||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height * wxGetApp().em_unit());
|
if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit);
|
||||||
size.SetWidth((m_opt.width > 0 ? m_opt.width : m_width) * wxGetApp().em_unit());
|
size.SetWidth((m_opt.width > 0 ? m_opt.width : m_width) * m_em_unit);
|
||||||
|
|
||||||
field->SetSize(size);
|
field->SetSize(size);
|
||||||
|
|
||||||
|
@ -885,8 +888,8 @@ void Choice::rescale()
|
||||||
void ColourPicker::BUILD()
|
void ColourPicker::BUILD()
|
||||||
{
|
{
|
||||||
auto size = wxSize(wxDefaultSize);
|
auto size = wxSize(wxDefaultSize);
|
||||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit());
|
if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit);
|
||||||
if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit());
|
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
|
||||||
|
|
||||||
// Validate the color
|
// Validate the color
|
||||||
wxString clr_str(static_cast<const ConfigOptionStrings*>(m_opt.default_value)->get_at(m_opt_idx));
|
wxString clr_str(static_cast<const ConfigOptionStrings*>(m_opt.default_value)->get_at(m_opt_idx));
|
||||||
|
@ -921,7 +924,7 @@ void PointCtrl::BUILD()
|
||||||
{
|
{
|
||||||
auto temp = new wxBoxSizer(wxHORIZONTAL);
|
auto temp = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
|
||||||
const wxSize field_size(4 * wxGetApp().em_unit(), -1);
|
const wxSize field_size(4 * m_em_unit, -1);
|
||||||
|
|
||||||
auto default_pt = static_cast<const ConfigOptionPoints*>(m_opt.default_value)->values.at(0);
|
auto default_pt = static_cast<const ConfigOptionPoints*>(m_opt.default_value)->values.at(0);
|
||||||
double val = default_pt(0);
|
double val = default_pt(0);
|
||||||
|
@ -964,6 +967,16 @@ void PointCtrl::BUILD()
|
||||||
y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
|
y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PointCtrl::rescale()
|
||||||
|
{
|
||||||
|
Field::rescale();
|
||||||
|
|
||||||
|
const wxSize field_size(4 * m_em_unit, -1);
|
||||||
|
|
||||||
|
x_textctrl->SetMinSize(field_size);
|
||||||
|
y_textctrl->SetMinSize(field_size);
|
||||||
|
}
|
||||||
|
|
||||||
void PointCtrl::propagate_value(wxTextCtrl* win)
|
void PointCtrl::propagate_value(wxTextCtrl* win)
|
||||||
{
|
{
|
||||||
if (!win->GetValue().empty())
|
if (!win->GetValue().empty())
|
||||||
|
@ -1009,8 +1022,8 @@ boost::any& PointCtrl::get_value()
|
||||||
void StaticText::BUILD()
|
void StaticText::BUILD()
|
||||||
{
|
{
|
||||||
auto size = wxSize(wxDefaultSize);
|
auto size = wxSize(wxDefaultSize);
|
||||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit());
|
if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit);
|
||||||
if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit());
|
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
|
||||||
|
|
||||||
const wxString legend(static_cast<const ConfigOptionString*>(m_opt.default_value)->value);
|
const wxString legend(static_cast<const ConfigOptionString*>(m_opt.default_value)->value);
|
||||||
auto temp = new wxStaticText(m_parent, wxID_ANY, legend, wxDefaultPosition, size, wxST_ELLIPSIZE_MIDDLE);
|
auto temp = new wxStaticText(m_parent, wxID_ANY, legend, wxDefaultPosition, size, wxST_ELLIPSIZE_MIDDLE);
|
||||||
|
@ -1029,8 +1042,8 @@ void StaticText::rescale()
|
||||||
Field::rescale();
|
Field::rescale();
|
||||||
|
|
||||||
auto size = wxSize(wxDefaultSize);
|
auto size = wxSize(wxDefaultSize);
|
||||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit());
|
if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit);
|
||||||
if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit());
|
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
|
||||||
|
|
||||||
if (size != wxDefaultSize)
|
if (size != wxDefaultSize)
|
||||||
{
|
{
|
||||||
|
|
|
@ -220,6 +220,9 @@ public:
|
||||||
virtual void rescale() {
|
virtual void rescale() {
|
||||||
m_Undo_to_sys_btn->rescale();
|
m_Undo_to_sys_btn->rescale();
|
||||||
m_Undo_btn->rescale();
|
m_Undo_btn->rescale();
|
||||||
|
|
||||||
|
// update em_unit value
|
||||||
|
m_em_unit = em_unit(m_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -241,6 +244,8 @@ protected:
|
||||||
// current value
|
// current value
|
||||||
boost::any m_value;
|
boost::any m_value;
|
||||||
|
|
||||||
|
int m_em_unit;
|
||||||
|
|
||||||
bool bEnterPressed = false;
|
bool bEnterPressed = false;
|
||||||
|
|
||||||
friend class OptionsGroup;
|
friend class OptionsGroup;
|
||||||
|
@ -432,6 +437,8 @@ public:
|
||||||
void set_value(const boost::any& value, bool change_event = false);
|
void set_value(const boost::any& value, bool change_event = false);
|
||||||
boost::any& get_value() override;
|
boost::any& get_value() override;
|
||||||
|
|
||||||
|
void rescale() override;
|
||||||
|
|
||||||
void enable() override {
|
void enable() override {
|
||||||
x_textctrl->Enable();
|
x_textctrl->Enable();
|
||||||
y_textctrl->Enable(); }
|
y_textctrl->Enable(); }
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "GUI_ObjectList.hpp"
|
#include "GUI_ObjectList.hpp"
|
||||||
#include "libslic3r/GCode/PreviewData.hpp"
|
#include "libslic3r/GCode/PreviewData.hpp"
|
||||||
#include "I18N.hpp"
|
#include "I18N.hpp"
|
||||||
|
#include "GUI_Utils.hpp"
|
||||||
|
|
||||||
using Slic3r::GUI::from_u8;
|
using Slic3r::GUI::from_u8;
|
||||||
|
|
||||||
|
@ -420,6 +421,27 @@ void PrusaCollapsiblePaneMSW::Collapse(bool collapse)
|
||||||
}
|
}
|
||||||
#endif //__WXMSW__
|
#endif //__WXMSW__
|
||||||
|
|
||||||
|
/* 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.
|
||||||
|
* This value will be used to correct rescale after moving between
|
||||||
|
* Displays with different HDPI */
|
||||||
|
int em_unit(wxWindow* win)
|
||||||
|
{
|
||||||
|
if (win) {
|
||||||
|
// get TopLevelWindow for some window
|
||||||
|
wxWindow* top_win = win;
|
||||||
|
while (!top_win->IsTopLevel())
|
||||||
|
top_win = top_win->GetParent();
|
||||||
|
|
||||||
|
Slic3r::GUI::DPIDialog* dlg = dynamic_cast<Slic3r::GUI::DPIDialog*>(top_win);
|
||||||
|
if (dlg)
|
||||||
|
// An analog of em_unit value from GUI_App.
|
||||||
|
return 10 * dlg->scale_factor();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Slic3r::GUI::wxGetApp().em_unit();
|
||||||
|
}
|
||||||
|
|
||||||
// If an icon has horizontal orientation (width > height) call this function with is_horizontal = true
|
// If an icon has horizontal orientation (width > height) call this function with is_horizontal = true
|
||||||
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/)
|
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/)
|
||||||
|
@ -436,7 +458,7 @@ wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, con
|
||||||
unsigned int height, width = height = 0;
|
unsigned int height, width = height = 0;
|
||||||
unsigned int& scale_base = is_horizontal ? width : height;
|
unsigned int& scale_base = is_horizontal ? width : height;
|
||||||
|
|
||||||
scale_base = (unsigned int)(Slic3r::GUI::wxGetApp().em_unit() * px_cnt * 0.1f + 0.5f);
|
scale_base = (unsigned int)(em_unit(win) * px_cnt * 0.1f + 0.5f);
|
||||||
|
|
||||||
std::string bmp_name = bmp_name_in;
|
std::string bmp_name = bmp_name_in;
|
||||||
boost::replace_last(bmp_name, ".png", "");
|
boost::replace_last(bmp_name, ".png", "");
|
||||||
|
|
|
@ -31,6 +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,
|
wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, const wxString& description,
|
||||||
std::function<void(wxCommandEvent& event)> cb, wxEvtHandler* event_handler);
|
std::function<void(wxCommandEvent& event)> cb, wxEvtHandler* event_handler);
|
||||||
|
|
||||||
|
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);
|
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name, const int px_cnt = 16, const bool is_horizontal = false);
|
||||||
|
|
||||||
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
||||||
|
|
Loading…
Reference in a new issue