Skip to content

Commit

Permalink
fixes linux
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Aug 1, 2024
1 parent fa06a25 commit 0faf1e5
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions src/slic3r/GUI/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,8 @@ bool TextCtrl::value_was_changed()
case coPoints:
if (m_opt_idx < 0) {
return boost::any_cast<std::vector<Vec2d>>(m_value) != boost::any_cast<std::vector<Vec2d>>(val);
} else if (boost::any_cast<std::vector<Vec2d>>(m_value).size() > m_opt_idx
&& boost::any_cast<std::vector<Vec2d>>(val).size() > m_opt_idx) {
} else if (int(boost::any_cast<std::vector<Vec2d>>(m_value).size()) > m_opt_idx
&& int(boost::any_cast<std::vector<Vec2d>>(val).size()) > m_opt_idx) {
return boost::any_cast<std::vector<Vec2d>>(m_value)[m_opt_idx] != boost::any_cast<std::vector<Vec2d>>(val)[m_opt_idx];
}
case coPoint:
Expand Down Expand Up @@ -1363,7 +1363,7 @@ void CheckBox::Rescale(wxWindow* win)
}
#ifdef __WXGTK2__
if (wxToggleButton* chk = dynamic_cast<wxToggleButton*>(win))
chk->Rescale();
chk->Update();
#endif
}

Expand Down Expand Up @@ -1402,12 +1402,14 @@ void CheckBox::BUILD() {
#ifdef __WXGTK2__
//gtk2 can't resize checkboxes, so we are using togglable buttons instead
window->Bind(wxEVT_TOGGLEBUTTON, ([this](wxCommandEvent e) {
m_is_na_val = false;
if (static_cast<wxToggleButton*>(window)->GetValue())
static_cast<wxToggleButton*>(window)->SetLabel("X");
else
static_cast<wxToggleButton*>(window)->SetLabel("");
on_change_field();
if (wxToggleButton* chk = dynamic_cast<wxToggleButton*>(window)) {
m_is_na_val = false;
if (chk->GetValue())
chk->SetLabel("X");
else
chk->SetLabel("");
on_change_field();
}
}), window->GetId());
#else
window->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent e) {
Expand Down Expand Up @@ -1870,18 +1872,19 @@ void Choice::set_selection()
field->SetSelection(*opt);
else
field->SetValue(text_value);
}
}
}

void Choice::set_text_value(const std::string &value, bool change_event) //! Redundant?
{
m_disable_change_event = !change_event;
choice_ctrl* field = dynamic_cast<choice_ctrl*>(window);
if (auto opt = m_opt.enum_def->value_to_index(value); opt.has_value())
if (auto opt = m_opt.enum_def->value_to_index(value); opt.has_value()) {
// This enum has a value field of the same content as text_value. Select it.
field->SetSelection(*opt);
else
} else {
field->SetValue(value);
}
m_disable_change_event = false;
}

Expand Down Expand Up @@ -2011,19 +2014,20 @@ boost::any& Choice::get_value()
else if (m_opt.gui_type == ConfigOptionDef::GUIType::f_enum_open || m_opt.gui_type == ConfigOptionDef::GUIType::i_enum_open) {
// Open enum: The combo box item index returned by the field
const int ret_enum = field->GetSelection();
if (m_opt.enum_def->has_values() && (m_opt.type == coString || m_opt.type == coStrings) && ret_enum >=0 && ret_enum < m_opt.enum_def->values().size()) {
if (m_opt.enum_def->has_values() && (m_opt.type == coString || m_opt.type == coStrings) && ret_enum >=0 && ret_enum < int(m_opt.enum_def->values().size())) {
m_value = m_opt.enum_def->value(ret_enum);
} else if (ret_enum < 0 || !m_opt.enum_def->has_values() || m_opt.type == coStrings ||
(into_u8(ret_str) != m_opt.enum_def->value(ret_enum) && ret_str != _(m_opt.enum_def->label(ret_enum))))
(into_u8(ret_str) != m_opt.enum_def->value(ret_enum) && ret_str != _(m_opt.enum_def->label(ret_enum)))) {
// modifies ret_string!
get_value_by_opt_type(ret_str);
else if (m_opt.type == coFloatOrPercent) {
} else if (m_opt.type == coFloatOrPercent) {
m_value = FloatOrPercent{string_to_double_decimal_point(m_opt.enum_def->value(ret_enum)),
(m_opt.enum_def->value(ret_enum).find('%') != std::string::npos)};
} else if (m_opt.type == coInt)
} else if (m_opt.type == coInt) {
m_value = atoi(m_opt.enum_def->value(ret_enum).c_str());
else
} else {
m_value = string_to_double_decimal_point(m_opt.enum_def->value(ret_enum));
}
}
else
// modifies ret_string!
Expand Down Expand Up @@ -2095,16 +2099,15 @@ void ColourPicker::BUILD()
// Validate the color
wxColour clr = wxTransparentColour;
if (m_opt.type == coStrings)
clr = wxColour{wxString{ m_opt.get_default_value<ConfigOptionStrings>()->get_at(m_opt_idx) }};
clr = wxColour{wxString{m_opt.get_default_value<ConfigOptionStrings>()->get_at(m_opt_idx)}};
if (m_opt.type == coString)
clr = wxColour{ wxString{ m_opt.get_default_value<ConfigOptionString>()->value } };
clr = wxColour{wxString{m_opt.get_default_value<ConfigOptionString>()->value}};
if (m_opt.type == coInts)
clr = wxColour{ (unsigned long)m_opt.get_default_value<ConfigOptionInts>()->get_at(m_opt_idx) };
clr = wxColour{(unsigned long) m_opt.get_default_value<ConfigOptionInts>()->get_at(m_opt_idx)};
if (m_opt.type == coInt)
clr = wxColour{ (unsigned long)m_opt.get_default_value<ConfigOptionInt>()->value };
if (!clr.IsOk()) {
clr = wxTransparentColour;
}
clr = wxColour{(unsigned long) m_opt.get_default_value<ConfigOptionInt>()->value};
if (!clr.IsOk())
clr = wxTransparentColour;

auto temp = new wxColourPickerCtrl(m_parent, wxID_ANY, clr, wxDefaultPosition, size);
if (parent_is_custom_ctrl && m_opt.height < 0)
Expand Down Expand Up @@ -2320,11 +2323,13 @@ void PointCtrl::BUILD()
const wxSize field_size(4 * m_em_unit, -1);

Vec2d default_pt;
if (m_opt.type == coPoint)
if (m_opt.type == coPoint) {
default_pt = m_opt.get_default_value<ConfigOptionPoint>()->value;
else // coPoints
} else { // coPoints
assert(m_opt.type == coPoints);
default_pt = m_opt.get_default_value<ConfigOptionPoints>()->get_at(0);
double val = default_pt(0);
}
double val = default_pt.x();
wxString X = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None);
val = default_pt(1);
wxString Y = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None);
Expand Down

0 comments on commit 0faf1e5

Please sign in to comment.