diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp
index dc28ac993..23700fc81 100644
--- a/src/slic3r/GUI/Field.cpp
+++ b/src/slic3r/GUI/Field.cpp
@@ -312,6 +312,8 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
void Field::msw_rescale(bool rescale_sidetext)
{
+ if (!m_Undo_btn)
+ return;
m_Undo_to_sys_btn->msw_rescale();
m_Undo_btn->msw_rescale();
m_blinking_bmp->msw_rescale();
diff --git a/src/slic3r/GUI/OG_CustomCtrl.cpp b/src/slic3r/GUI/OG_CustomCtrl.cpp
index 6f6bc98ef..e80dd47b6 100644
--- a/src/slic3r/GUI/OG_CustomCtrl.cpp
+++ b/src/slic3r/GUI/OG_CustomCtrl.cpp
@@ -21,7 +21,7 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
const wxValidator& val /* = wxDefaultValidator*/,
const wxString& name/* = wxEmptyString*/) :
wxControl(parent, wxID_ANY, pos, size, wxWANTS_CHARS | wxBORDER_NONE),
- m_og(og)
+ opt_group(og)
{
if (!wxOSX)
SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX
@@ -48,9 +48,7 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
void OG_CustomCtrl::init_ctrl_lines()
{
- wxCoord v_pos = 0;
-
- for (const Line& line : m_og->get_lines())
+ for (const Line& line : opt_group->get_lines())
{
if (line.full_width && (
// description line
@@ -65,7 +63,7 @@ void OG_CustomCtrl::init_ctrl_lines()
wxCoord height = 0;
// if we have a single option with no label, no sidetext just add it directly to sizer
- if (option_set.size() == 1 && m_og->label_width == 0 && option_set.front().opt.full_width &&
+ if (option_set.size() == 1 && opt_group->label_width == 0 && option_set.front().opt.full_width &&
option_set.front().opt.label.empty() &&
option_set.front().opt.sidetext.size() == 0 && option_set.front().side_widget == nullptr &&
line.get_extra_widgets().size() == 0)
@@ -73,25 +71,22 @@ void OG_CustomCtrl::init_ctrl_lines()
height = m_bmp_blinking.bmp().GetHeight() + m_v_gap;
ctrl_lines.emplace_back(CtrlLine{ height, this, line, true });
}
- else if (m_og->label_width != 0 && !line.label.IsEmpty())
+ else if (opt_group->label_width != 0 && !line.label.IsEmpty())
{
wxSize label_sz = GetTextExtent(line.label);
- height = label_sz.y * (label_sz.GetWidth() > (m_og->label_width*wxGetApp().em_unit()) ? 2 : 1) + m_v_gap;
+ height = label_sz.y * (label_sz.GetWidth() > (opt_group->label_width*wxGetApp().em_unit()) ? 2 : 1) + m_v_gap;
ctrl_lines.emplace_back(CtrlLine{ height, this, line });
}
else
int i = 0;
- v_pos += height;
}
-
- this->SetMinSize(wxSize(wxDefaultCoord, v_pos));
}
int OG_CustomCtrl::get_height(const Line& line)
{
for (auto ctrl_line : ctrl_lines)
- if (&ctrl_line.m_og_line == &line)
- return ctrl_line.m_height;
+ if (&ctrl_line.og_line == &line)
+ return ctrl_line.height;
return 0;
}
@@ -101,11 +96,11 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
wxCoord v_pos = 0;
wxCoord h_pos = 0;
for (auto ctrl_line : ctrl_lines) {
- if (&ctrl_line.m_og_line == &line)
+ if (&ctrl_line.og_line == &line)
{
h_pos = m_bmp_mode_simple.bmp().GetWidth() + m_h_gap;
- if (line.near_label_widget) {
- wxSize near_label_widget_sz = m_og->get_last_near_label_widget()->GetSize();
+ if (line.near_label_widget_win) {
+ wxSize near_label_widget_sz = line.near_label_widget_win->GetSize();
if (field_in)
h_pos += near_label_widget_sz.GetWidth() + m_h_gap;
else
@@ -113,8 +108,8 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
}
wxString label = line.label;
- if (m_og->label_width != 0 && !label.IsEmpty())
- h_pos += m_og->label_width * wxGetApp().em_unit() + m_h_gap;
+ if (opt_group->label_width != 0 && !label.IsEmpty())
+ h_pos += opt_group->label_width * wxGetApp().em_unit() + m_h_gap;
if (line.widget)
break;
@@ -130,7 +125,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
}
for (auto opt : option_set) {
- Field* field = m_og->get_field(opt.opt_id);
+ Field* field = opt_group->get_field(opt.opt_id);
ConfigOptionDef option = opt.opt;
// add label if any
if (!option.label.empty()) {
@@ -153,15 +148,16 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
break;
// add sidetext if any
- if (!option.sidetext.empty() || m_og->sidetext_width > 0)
- h_pos += m_og->sidetext_width * wxGetApp().em_unit() + m_h_gap;
+ if (!option.sidetext.empty() || opt_group->sidetext_width > 0)
+ h_pos += opt_group->sidetext_width * wxGetApp().em_unit() + m_h_gap;
if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back())
h_pos += lround(0.6 * wxGetApp().em_unit());
}
break;
}
- v_pos += ctrl_line.m_height;
+ if (ctrl_line.is_visible)
+ v_pos += ctrl_line.height;
}
return wxPoint(h_pos, v_pos);
@@ -184,7 +180,7 @@ void OG_CustomCtrl::OnPaint(wxPaintEvent&)
if (!line.is_visible)
continue;
line.render(dc, v_pos);
- v_pos += line.m_height;
+ v_pos += line.height;
}
}
@@ -218,9 +214,44 @@ void OG_CustomCtrl::OnLeftUp(wxMouseEvent& event)
bool OG_CustomCtrl::update_visibility(ConfigOptionMode mode)
{
- return true;
+ wxCoord v_pos = 0;
+
+ size_t invisible_lines = 0;
+ for (CtrlLine& line : ctrl_lines) {
+ line.update_visibility(mode);
+ if (line.is_visible)
+ v_pos += (wxCoord)line.height;
+ else
+ invisible_lines++;
+ }
+
+ this->SetMinSize(wxSize(wxDefaultCoord, v_pos));
+
+ return invisible_lines != ctrl_lines.size();
}
+void OG_CustomCtrl::correct_window_position(wxWindow* win, const Line& line, Field* field/* = nullptr*/)
+{
+ wxPoint pos = get_pos(line, field);
+ int line_height = get_height(line);
+ pos.y += std::max(0, int(0.5 * (line_height - win->GetSize().y)));
+ win->SetPosition(pos);
+};
+
+void OG_CustomCtrl::correct_widgets_position(wxSizer* widget, const Line& line, Field* field/* = nullptr*/) {
+ auto children = widget->GetChildren();
+ wxPoint line_pos = get_pos(line, field);
+ int line_height = get_height(line);
+ for (auto child : children)
+ if (child->IsWindow()) {
+ wxPoint pos = line_pos;
+ wxSize sz = child->GetWindow()->GetSize();
+ pos.y += std::max(0, int(0.5 * (line_height - sz.y)));
+ child->GetWindow()->SetPosition(pos);
+ line_pos.x += sz.x + m_h_gap;
+ }
+};
+
void OG_CustomCtrl::msw_rescale()
{
const wxFont& font = GUI::wxGetApp().normal_font();
@@ -236,33 +267,80 @@ void OG_CustomCtrl::sys_color_changed()
}
+void OG_CustomCtrl::CtrlLine::update_visibility(ConfigOptionMode mode)
+{
+ const std::vector