Skip to content

Commit

Permalink
Alignments of options in settings tabs
Browse files Browse the repository at this point in the history
+ msw_rescale() is overridden for PrinterTab to rescale of all the option Pages and not just a respect to current print technology
+ A Setting of the option.width in PrintConfig is no need anymore
  • Loading branch information
YuSanka committed Feb 12, 2020
1 parent 2e62f03 commit fcd1cf3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 57 deletions.
10 changes: 0 additions & 10 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("If layer print time is estimated below this number of seconds, fan will be enabled "
"and its speed will be calculated by interpolating the minimum and maximum speeds.");
def->sidetext = L("approximate seconds");
def->width = 6;
def->min = 0;
def->max = 1000;
def->mode = comExpert;
Expand Down Expand Up @@ -1104,7 +1103,6 @@ void PrintConfigDef::init_fff_params()
def->mode = comExpert;
def->set_default_value(new ConfigOptionBool(true));

const int machine_limits_opt_width = 7;
{
struct AxisDefault {
std::string name;
Expand Down Expand Up @@ -1136,7 +1134,6 @@ void PrintConfigDef::init_fff_params()
(void)L("Maximum feedrate of the E axis");
def->sidetext = L("mm/s");
def->min = 0;
def->width = machine_limits_opt_width;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats(axis.max_feedrate));
// Add the machine acceleration limits for XYZE axes (M201)
Expand All @@ -1154,7 +1151,6 @@ void PrintConfigDef::init_fff_params()
(void)L("Maximum acceleration of the E axis");
def->sidetext = L("mm/s²");
def->min = 0;
def->width = machine_limits_opt_width;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats(axis.max_acceleration));
// Add the machine jerk limits for XYZE axes (M205)
Expand All @@ -1172,7 +1168,6 @@ void PrintConfigDef::init_fff_params()
(void)L("Maximum jerk of the E axis");
def->sidetext = L("mm/s");
def->min = 0;
def->width = machine_limits_opt_width;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats(axis.max_jerk));
}
Expand All @@ -1185,7 +1180,6 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Minimum feedrate when extruding (M205 S)");
def->sidetext = L("mm/s");
def->min = 0;
def->width = machine_limits_opt_width;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{ 0., 0. });

Expand All @@ -1196,7 +1190,6 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Minimum travel feedrate (M205 T)");
def->sidetext = L("mm/s");
def->min = 0;
def->width = machine_limits_opt_width;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{ 0., 0. });

Expand All @@ -1207,7 +1200,6 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Maximum acceleration when extruding (M204 S)");
def->sidetext = L("mm/s²");
def->min = 0;
def->width = machine_limits_opt_width;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{ 1500., 1250. });

Expand All @@ -1218,7 +1210,6 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Maximum acceleration when retracting (M204 T)");
def->sidetext = L("mm/s²");
def->min = 0;
def->width = machine_limits_opt_width;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{ 1500., 1250. });

Expand Down Expand Up @@ -1715,7 +1706,6 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("If layer print time is estimated below this number of seconds, print moves "
"speed will be scaled down to extend duration to this value.");
def->sidetext = L("approximate seconds");
def->width = 6;
def->min = 0;
def->max = 1000;
def->mode = comExpert;
Expand Down
56 changes: 39 additions & 17 deletions src/slic3r/GUI/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
}
}

void Field::msw_rescale(bool rescale_sidetext)
{
m_Undo_to_sys_btn->msw_rescale();
m_Undo_btn->msw_rescale();

// update em_unit value
m_em_unit = em_unit(m_parent);

// update sidetext if it is needed
if (m_side_text && rescale_sidetext)
{
auto size = wxSize(def_width_thinner() * m_em_unit, -1);
m_side_text->SetSize(size);
m_side_text->SetMinSize(size);
}
}

template<class T>
bool is_defined_input_value(wxWindow* win, const ConfigOptionType& type)
{
Expand All @@ -259,7 +276,7 @@ bool is_defined_input_value(wxWindow* win, const ConfigOptionType& type)
}

void TextCtrl::BUILD() {
auto size = wxSize(wxDefaultSize);
auto size = wxSize(def_width()*m_em_unit, wxDefaultCoord);
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);

Expand Down Expand Up @@ -455,10 +472,10 @@ boost::any& TextCtrl::get_value()
return m_value;
}

void TextCtrl::msw_rescale()
void TextCtrl::msw_rescale(bool rescale_sidetext/* = false*/)
{
Field::msw_rescale();
auto size = wxSize(wxDefaultSize);
Field::msw_rescale(rescale_sidetext);
auto size = wxSize(def_width() * m_em_unit, wxDefaultCoord);
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);

Expand Down Expand Up @@ -555,7 +572,7 @@ boost::any& CheckBox::get_value()
return m_value;
}

void CheckBox::msw_rescale()
void CheckBox::msw_rescale(bool rescale_sidetext/* = false*/)
{
Field::msw_rescale();

Expand All @@ -565,7 +582,7 @@ void CheckBox::msw_rescale()


void SpinCtrl::BUILD() {
auto size = wxSize(wxDefaultSize);
auto size = wxSize(def_width() * m_em_unit, wxDefaultCoord);
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);

Expand Down Expand Up @@ -690,16 +707,16 @@ void SpinCtrl::propagate_value()
suppress_propagation = false;
}

void SpinCtrl::msw_rescale()
void SpinCtrl::msw_rescale(bool rescale_sidetext/* = false*/)
{
Field::msw_rescale();
Field::msw_rescale(rescale_sidetext);

wxSpinCtrl* field = dynamic_cast<wxSpinCtrl*>(window);
field->SetMinSize(wxSize(-1, int(1.9f*field->GetFont().GetPixelSize().y)));
field->SetMinSize(wxSize(def_width() * m_em_unit, int(1.9f*field->GetFont().GetPixelSize().y)));
}

void Choice::BUILD() {
wxSize size(m_width * m_em_unit, -1);
wxSize size(def_width_wider() * m_em_unit, wxDefaultCoord);
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);

Expand Down Expand Up @@ -1018,7 +1035,7 @@ boost::any& Choice::get_value()
return m_value;
}

void Choice::msw_rescale()
void Choice::msw_rescale(bool rescale_sidetext/* = false*/)
{
Field::msw_rescale();

Expand All @@ -1034,7 +1051,7 @@ void Choice::msw_rescale()
*/
field->Clear();
wxSize size(wxDefaultSize);
size.SetWidth((m_opt.width > 0 ? m_opt.width : m_width) * m_em_unit);
size.SetWidth((m_opt.width > 0 ? m_opt.width : def_width_wider()) * m_em_unit);

// Set rescaled min height to correct layout
field->SetMinSize(wxSize(-1, int(1.5f*field->GetFont().GetPixelSize().y + 0.5f)));
Expand Down Expand Up @@ -1065,7 +1082,7 @@ void Choice::msw_rescale()

void ColourPicker::BUILD()
{
auto size = wxSize(wxDefaultSize);
auto size = wxSize(def_width() * m_em_unit, wxDefaultCoord);
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);

Expand Down Expand Up @@ -1133,11 +1150,16 @@ boost::any& ColourPicker::get_value()
return m_value;
}

void ColourPicker::msw_rescale()
void ColourPicker::msw_rescale(bool rescale_sidetext/* = false*/)
{
Field::msw_rescale();

wxColourPickerCtrl* field = dynamic_cast<wxColourPickerCtrl*>(window);
wxColourPickerCtrl* field = dynamic_cast<wxColourPickerCtrl*>(window);
auto size = wxSize(def_width() * m_em_unit, wxDefaultCoord);
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);
field->SetMinSize(size);

if (field->GetColour() == wxTransparentColour)
set_undef_value(field);
}
Expand Down Expand Up @@ -1189,7 +1211,7 @@ void PointCtrl::BUILD()
y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
}

void PointCtrl::msw_rescale()
void PointCtrl::msw_rescale(bool rescale_sidetext/* = false*/)
{
Field::msw_rescale();

Expand Down Expand Up @@ -1259,7 +1281,7 @@ void StaticText::BUILD()
temp->SetToolTip(get_tooltip_text(legend));
}

void StaticText::msw_rescale()
void StaticText::msw_rescale(bool rescale_sidetext/* = false*/)
{
Field::msw_rescale();

Expand Down
28 changes: 13 additions & 15 deletions src/slic3r/GUI/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,16 @@ class Field {
m_side_text = side_text;
}

virtual void msw_rescale() {
m_Undo_to_sys_btn->msw_rescale();
m_Undo_btn->msw_rescale();

// update em_unit value
m_em_unit = em_unit(m_parent);
}
virtual void msw_rescale(bool rescale_sidetext = false);

bool get_enter_pressed() const { return bEnterPressed; }
void set_enter_pressed(bool pressed) { bEnterPressed = pressed; }

// Values of width to "systematic" alignments of fields
static int def_width() { return 7; }
static int def_width_wider() { return 14; }
static int def_width_thinner() { return 4; }

protected:
RevertButton* m_Undo_btn = nullptr;
// Bitmap and Tooltip text for m_Undo_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one.
Expand Down Expand Up @@ -297,7 +296,7 @@ class TextCtrl : public Field {

boost::any& get_value() override;

void msw_rescale() override;
void msw_rescale(bool rescale_sidetext = false) override;

virtual void enable();
virtual void disable();
Expand Down Expand Up @@ -325,7 +324,7 @@ class CheckBox : public Field {
void set_na_value() override;
boost::any& get_value() override;

void msw_rescale() override;
void msw_rescale(bool rescale_sidetext = false) override;

void enable() override { dynamic_cast<wxCheckBox*>(window)->Enable(); }
void disable() override { dynamic_cast<wxCheckBox*>(window)->Disable(); }
Expand Down Expand Up @@ -368,7 +367,7 @@ class SpinCtrl : public Field {
return m_value = value;
}

void msw_rescale() override;
void msw_rescale(bool rescale_sidetext = false) override;

void enable() override { dynamic_cast<wxSpinCtrl*>(window)->Enable(); }
void disable() override { dynamic_cast<wxSpinCtrl*>(window)->Disable(); }
Expand All @@ -377,7 +376,6 @@ class SpinCtrl : public Field {

class Choice : public Field {
using Field::Field;
int m_width{ 15 };
public:
Choice(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {}
Choice(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {}
Expand All @@ -397,7 +395,7 @@ class Choice : public Field {
void set_values(const std::vector<std::string> &values);
boost::any& get_value() override;

void msw_rescale() override;
void msw_rescale(bool rescale_sidetext = false) override;

void enable() override { dynamic_cast<wxBitmapComboBox*>(window)->Enable(); };
void disable() override{ dynamic_cast<wxBitmapComboBox*>(window)->Disable(); };
Expand All @@ -423,7 +421,7 @@ class ColourPicker : public Field {
}
void set_value(const boost::any& value, bool change_event = false) override;
boost::any& get_value() override;
void msw_rescale() override;
void msw_rescale(bool rescale_sidetext = false) override;

void enable() override { dynamic_cast<wxColourPickerCtrl*>(window)->Enable(); };
void disable() override{ dynamic_cast<wxColourPickerCtrl*>(window)->Disable(); };
Expand All @@ -448,7 +446,7 @@ class PointCtrl : public Field {
void set_value(const boost::any& value, bool change_event = false);
boost::any& get_value() override;

void msw_rescale() override;
void msw_rescale(bool rescale_sidetext = false) override;

void enable() override {
x_textctrl->Enable();
Expand Down Expand Up @@ -482,7 +480,7 @@ class StaticText : public Field {

boost::any& get_value()override { return m_value; }

void msw_rescale() override;
void msw_rescale(bool rescale_sidetext = false) override;

void enable() override { dynamic_cast<wxStaticText*>(window)->Enable(); };
void disable() override{ dynamic_cast<wxStaticText*>(window)->Disable(); };
Expand Down
10 changes: 7 additions & 3 deletions src/slic3r/GUI/OptionsGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n
for (auto opt : option_set)
m_options.emplace(opt.opt_id, opt);

// Set sidetext width for a better alignment of options in line
if (option_set.size() > 1)
sidetext_width = Field::def_width_thinner();

// add mode value for current line to m_options_mode
if (!option_set.empty())
m_options_mode.push_back(option_set[0].opt.mode);
Expand Down Expand Up @@ -274,9 +278,9 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n
sizer_tmp->Add(field->getWindow(), 0, wxALIGN_CENTER_VERTICAL, 0);

// add sidetext if any
if (option.sidetext != "") {
if (!option.sidetext.empty() || sidetext_width > 0) {
auto sidetext = new wxStaticText( this->ctrl_parent(), wxID_ANY, _(option.sidetext), wxDefaultPosition,
wxSize(sidetext_width != -1 ? sidetext_width*wxGetApp().em_unit() : -1, -1) /*wxDefaultSize*/, wxALIGN_LEFT);
wxSize(sidetext_width != -1 ? sidetext_width*wxGetApp().em_unit() : -1, -1), wxALIGN_LEFT);
sidetext->SetBackgroundStyle(wxBG_STYLE_PAINT);
sidetext->SetFont(wxGetApp().normal_font());
sizer_tmp->Add(sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4);
Expand Down Expand Up @@ -498,7 +502,7 @@ void ConfigOptionsGroup::msw_rescale()

// update undo buttons : rescale bitmaps
for (const auto& field : m_fields)
field.second->msw_rescale();
field.second->msw_rescale(sidetext_width>0);

const int em = em_unit(parent());

Expand Down
Loading

0 comments on commit fcd1cf3

Please sign in to comment.