Custom control : fixed re-scaling for MSW

This commit is contained in:
YuSanka 2020-10-23 19:17:10 +02:00 committed by Oleksandra Yushchenko
parent 1b3c288b35
commit e93e80166b
6 changed files with 173 additions and 79 deletions

View file

@ -13,6 +13,7 @@
#include <wx/tooltip.h> #include <wx/tooltip.h>
#include <wx/notebook.h> #include <wx/notebook.h>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include "OG_CustomCtrl.hpp"
#ifdef __WXOSX__ #ifdef __WXOSX__
#define wxOSX true #define wxOSX true
@ -99,6 +100,7 @@ void Field::PostInitialize()
// initialize m_unit_value // initialize m_unit_value
m_em_unit = em_unit(m_parent); m_em_unit = em_unit(m_parent);
parent_is_custom_ctrl = dynamic_cast<OG_CustomCtrl*>(m_parent) != nullptr;
BUILD(); BUILD();
@ -312,12 +314,11 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
void Field::msw_rescale(bool rescale_sidetext) void Field::msw_rescale(bool rescale_sidetext)
{ {
if (!m_Undo_btn) if (m_Undo_btn) {
return;
m_Undo_to_sys_btn->msw_rescale(); m_Undo_to_sys_btn->msw_rescale();
m_Undo_btn->msw_rescale(); m_Undo_btn->msw_rescale();
m_blinking_bmp->msw_rescale(); m_blinking_bmp->msw_rescale();
}
// update em_unit value // update em_unit value
m_em_unit = em_unit(m_parent); m_em_unit = em_unit(m_parent);
@ -394,6 +395,8 @@ void TextCtrl::BUILD() {
const long style = m_opt.multiline ? wxTE_MULTILINE : wxTE_PROCESS_ENTER/*0*/; const long style = m_opt.multiline ? wxTE_MULTILINE : wxTE_PROCESS_ENTER/*0*/;
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, style); auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, style);
if (parent_is_custom_ctrl && m_opt.height < 0)
opt_height = (double)temp->GetSize().GetHeight()/m_em_unit;
temp->SetFont(m_opt.is_code ? temp->SetFont(m_opt.is_code ?
Slic3r::GUI::wxGetApp().code_font(): Slic3r::GUI::wxGetApp().code_font():
Slic3r::GUI::wxGetApp().normal_font()); Slic3r::GUI::wxGetApp().normal_font());
@ -561,12 +564,19 @@ void TextCtrl::msw_rescale(bool rescale_sidetext/* = false*/)
{ {
Field::msw_rescale(rescale_sidetext); Field::msw_rescale(rescale_sidetext);
auto size = wxSize(def_width() * m_em_unit, wxDefaultCoord); 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.height >= 0)
size.SetHeight(m_opt.height*m_em_unit);
else if (parent_is_custom_ctrl && opt_height > 0)
size.SetHeight(lround(opt_height*m_em_unit));
if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit);
if (size != wxDefaultSize) if (size != wxDefaultSize)
{ {
wxTextCtrl* field = dynamic_cast<wxTextCtrl*>(window); wxTextCtrl* field = dynamic_cast<wxTextCtrl*>(window);
if (parent_is_custom_ctrl)
field->SetSize(size);
else
field->SetMinSize(size); field->SetMinSize(size);
} }
@ -711,6 +721,9 @@ void SpinCtrl::BUILD() {
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT); if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT);
if (m_opt.height < 0 && parent_is_custom_ctrl)
opt_height = (double)temp->GetSize().GetHeight() / m_em_unit;
// XXX: On OS X the wxSpinCtrl widget is made up of two subwidgets, unfortunatelly // XXX: On OS X the wxSpinCtrl widget is made up of two subwidgets, unfortunatelly
// the kill focus event is not propagated to the encompassing widget, // the kill focus event is not propagated to the encompassing widget,
// so we need to bind it on the inner text widget instead. (Ugh.) // so we need to bind it on the inner text widget instead. (Ugh.)
@ -797,6 +810,9 @@ void SpinCtrl::msw_rescale(bool rescale_sidetext/* = false*/)
Field::msw_rescale(rescale_sidetext); Field::msw_rescale(rescale_sidetext);
wxSpinCtrl* field = dynamic_cast<wxSpinCtrl*>(window); wxSpinCtrl* field = dynamic_cast<wxSpinCtrl*>(window);
if (parent_is_custom_ctrl)
field->SetSize(wxSize(def_width() * m_em_unit, lround(opt_height * m_em_unit)));
else
field->SetMinSize(wxSize(def_width() * m_em_unit, int(1.9f*field->GetFont().GetPixelSize().y))); field->SetMinSize(wxSize(def_width() * m_em_unit, int(1.9f*field->GetFont().GetPixelSize().y)));
} }
@ -1159,11 +1175,12 @@ void Choice::msw_rescale(bool rescale_sidetext/* = false*/)
Field::msw_rescale(); Field::msw_rescale();
choice_ctrl* field = dynamic_cast<choice_ctrl*>(window); choice_ctrl* field = dynamic_cast<choice_ctrl*>(window);
#ifdef __WXOSX__
const wxString selection = field->GetValue();// field->GetString(index); const wxString selection = field->GetValue();// field->GetString(index);
/* To correct scaling (set new controll size) of a wxBitmapCombobox /* To correct scaling (set new controll size) of a wxBitmapCombobox
* we need to refill control with new bitmaps. So, in our case : * we need to refill control with new bitmaps. So, in our case :
* 1. clear conrol * 1. clear control
* 2. add content * 2. add content
* 3. add scaled "empty" bitmap to the at least one item * 3. add scaled "empty" bitmap to the at least one item
*/ */
@ -1189,15 +1206,23 @@ void Choice::msw_rescale(bool rescale_sidetext/* = false*/)
} }
} }
#ifdef __WXOSX__
wxBitmap empty_bmp(1, field->GetFont().GetPixelSize().y + 2); wxBitmap empty_bmp(1, field->GetFont().GetPixelSize().y + 2);
empty_bmp.SetWidth(0); empty_bmp.SetWidth(0);
field->SetItemBitmap(0, empty_bmp); field->SetItemBitmap(0, empty_bmp);
#endif
idx == m_opt.enum_values.size() ? idx == m_opt.enum_values.size() ?
field->SetValue(selection) : field->SetValue(selection) :
field->SetSelection(idx); field->SetSelection(idx);
#else
auto size = wxSize(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);
if (parent_is_custom_ctrl)
field->SetSize(size);
else
field->SetMinSize(size);
#endif
} }
void ColourPicker::BUILD() void ColourPicker::BUILD()
@ -1214,6 +1239,8 @@ void ColourPicker::BUILD()
} }
auto temp = new wxColourPickerCtrl(m_parent, wxID_ANY, clr, wxDefaultPosition, size); auto temp = new wxColourPickerCtrl(m_parent, wxID_ANY, clr, wxDefaultPosition, size);
if (parent_is_custom_ctrl && m_opt.height < 0)
opt_height = (double)temp->GetSize().GetHeight() / m_em_unit;
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT); if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT);
@ -1276,8 +1303,14 @@ void ColourPicker::msw_rescale(bool rescale_sidetext/* = false*/)
wxColourPickerCtrl* field = dynamic_cast<wxColourPickerCtrl*>(window); wxColourPickerCtrl* field = dynamic_cast<wxColourPickerCtrl*>(window);
auto size = wxSize(def_width() * m_em_unit, wxDefaultCoord); 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.height >= 0)
size.SetHeight(m_opt.height * m_em_unit);
else if (parent_is_custom_ctrl && opt_height > 0)
size.SetHeight(lround(opt_height * m_em_unit));
if (m_opt.width >= 0) size.SetWidth(m_opt.width * m_em_unit); if (m_opt.width >= 0) size.SetWidth(m_opt.width * m_em_unit);
if (parent_is_custom_ctrl)
field->SetSize(size);
else
field->SetMinSize(size); field->SetMinSize(size);
if (field->GetColour() == wxTransparentColour) if (field->GetColour() == wxTransparentColour)
@ -1298,6 +1331,9 @@ void PointCtrl::BUILD()
x_textctrl = new wxTextCtrl(m_parent, wxID_ANY, X, wxDefaultPosition, field_size, wxTE_PROCESS_ENTER); x_textctrl = new wxTextCtrl(m_parent, wxID_ANY, X, wxDefaultPosition, field_size, wxTE_PROCESS_ENTER);
y_textctrl = new wxTextCtrl(m_parent, wxID_ANY, Y, wxDefaultPosition, field_size, wxTE_PROCESS_ENTER); y_textctrl = new wxTextCtrl(m_parent, wxID_ANY, Y, wxDefaultPosition, field_size, wxTE_PROCESS_ENTER);
if (parent_is_custom_ctrl && m_opt.height < 0)
opt_height = (double)x_textctrl->GetSize().GetHeight() / m_em_unit;
x_textctrl->SetFont(Slic3r::GUI::wxGetApp().normal_font()); x_textctrl->SetFont(Slic3r::GUI::wxGetApp().normal_font());
x_textctrl->SetBackgroundStyle(wxBG_STYLE_PAINT); x_textctrl->SetBackgroundStyle(wxBG_STYLE_PAINT);
y_textctrl->SetFont(Slic3r::GUI::wxGetApp().normal_font()); y_textctrl->SetFont(Slic3r::GUI::wxGetApp().normal_font());
@ -1315,9 +1351,6 @@ void PointCtrl::BUILD()
temp->Add(static_text_y, 0, wxALIGN_CENTER_VERTICAL, 0); temp->Add(static_text_y, 0, wxALIGN_CENTER_VERTICAL, 0);
temp->Add(y_textctrl); temp->Add(y_textctrl);
// x_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), x_textctrl->GetId());
// y_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), y_textctrl->GetId());
x_textctrl->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent e) { propagate_value(x_textctrl); }), x_textctrl->GetId()); x_textctrl->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent e) { propagate_value(x_textctrl); }), x_textctrl->GetId());
y_textctrl->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent e) { propagate_value(y_textctrl); }), y_textctrl->GetId()); y_textctrl->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent e) { propagate_value(y_textctrl); }), y_textctrl->GetId());
@ -1335,10 +1368,17 @@ void PointCtrl::msw_rescale(bool rescale_sidetext/* = false*/)
{ {
Field::msw_rescale(); Field::msw_rescale();
const wxSize field_size(4 * m_em_unit, -1); wxSize field_size(4 * m_em_unit, -1);
if (parent_is_custom_ctrl) {
field_size.SetHeight(lround(opt_height * m_em_unit));
x_textctrl->SetSize(field_size);
y_textctrl->SetSize(field_size);
}
else {
x_textctrl->SetMinSize(field_size); x_textctrl->SetMinSize(field_size);
y_textctrl->SetMinSize(field_size); y_textctrl->SetMinSize(field_size);
}
} }
bool PointCtrl::value_was_changed(wxTextCtrl* win) bool PointCtrl::value_was_changed(wxTextCtrl* win)

View file

@ -119,6 +119,9 @@ public:
const t_config_option_key m_opt_id;//! {""}; const t_config_option_key m_opt_id;//! {""};
int m_opt_idx = 0; int m_opt_idx = 0;
double opt_height{ 0.0 };
bool parent_is_custom_ctrl{ false };
/// Sets a value for this control. /// Sets a value for this control.
/// subclasses should overload with a specific version /// subclasses should overload with a specific version
/// Postcondition: Method does not fire the on_change event. /// Postcondition: Method does not fire the on_change event.

View file

@ -26,14 +26,13 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
if (!wxOSX) if (!wxOSX)
SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX
// init bitmaps m_font = wxGetApp().normal_font();
m_bmp_mode_simple = ScalableBitmap(this, "mode_simple" , wxOSX ? 10 : 12); m_em_unit = em_unit(m_parent);
m_bmp_mode_advanced = ScalableBitmap(this, "mode_advanced", wxOSX ? 10 : 12); m_v_gap = lround(1.0 * m_em_unit);
m_bmp_mode_expert = ScalableBitmap(this, "mode_expert" , wxOSX ? 10 : 12); m_h_gap = lround(0.2 * m_em_unit);
m_bmp_blinking = ScalableBitmap(this, "search_blink");
m_v_gap = lround(1.0 * wxGetApp().em_unit()); m_bmp_mode_sz = create_scaled_bitmap("mode_simple", this, wxOSX ? 10 : 12).GetSize();
m_h_gap = lround(0.2 * wxGetApp().em_unit()); m_bmp_blinking_sz = create_scaled_bitmap("search_blink", this).GetSize();
init_ctrl_lines();// from og.lines() init_ctrl_lines();// from og.lines()
@ -41,9 +40,6 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
this->Bind(wxEVT_MOTION, &OG_CustomCtrl::OnMotion, this); this->Bind(wxEVT_MOTION, &OG_CustomCtrl::OnMotion, this);
this->Bind(wxEVT_LEFT_DOWN, &OG_CustomCtrl::OnLeftDown, this); this->Bind(wxEVT_LEFT_DOWN, &OG_CustomCtrl::OnLeftDown, this);
this->Bind(wxEVT_LEFT_UP, &OG_CustomCtrl::OnLeftUp, this); this->Bind(wxEVT_LEFT_UP, &OG_CustomCtrl::OnLeftUp, this);
const wxFont& font = wxGetApp().normal_font();
m_font = wxOSX ? font.Smaller() : font;
} }
void OG_CustomCtrl::init_ctrl_lines() void OG_CustomCtrl::init_ctrl_lines()
@ -58,9 +54,8 @@ void OG_CustomCtrl::init_ctrl_lines()
) )
continue; continue;
auto option_set = line.get_options(); const std::vector<Option>& option_set = line.get_options();
wxCoord height;
wxCoord height = 0;
// if we have a single option with no label, no sidetext just add it directly to sizer // if we have a single option with no label, no sidetext just add it directly to sizer
if (option_set.size() == 1 && opt_group->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 &&
@ -68,13 +63,13 @@ void OG_CustomCtrl::init_ctrl_lines()
option_set.front().opt.sidetext.size() == 0 && option_set.front().side_widget == nullptr && option_set.front().opt.sidetext.size() == 0 && option_set.front().side_widget == nullptr &&
line.get_extra_widgets().size() == 0) line.get_extra_widgets().size() == 0)
{ {
height = m_bmp_blinking.bmp().GetHeight() + m_v_gap; height = m_bmp_blinking_sz.GetHeight() + m_v_gap;
ctrl_lines.emplace_back(CtrlLine{ height, this, line, true }); ctrl_lines.emplace_back(CtrlLine{ height, this, line, true });
} }
else if (opt_group->label_width != 0 && !line.label.IsEmpty()) else if (opt_group->label_width != 0 && !line.label.IsEmpty())
{ {
wxSize label_sz = GetTextExtent(line.label); wxSize label_sz = GetTextExtent(line.label);
height = label_sz.y * (label_sz.GetWidth() > (opt_group->label_width*wxGetApp().em_unit()) ? 2 : 1) + m_v_gap; height = label_sz.y * (label_sz.GetWidth() > int(opt_group->label_width * m_em_unit) ? 2 : 1) + m_v_gap;
ctrl_lines.emplace_back(CtrlLine{ height, this, line }); ctrl_lines.emplace_back(CtrlLine{ height, this, line });
} }
else else
@ -98,7 +93,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
for (auto ctrl_line : ctrl_lines) { for (auto ctrl_line : ctrl_lines) {
if (&ctrl_line.og_line == &line) if (&ctrl_line.og_line == &line)
{ {
h_pos = m_bmp_mode_simple.bmp().GetWidth() + m_h_gap; h_pos = m_bmp_mode_sz.GetWidth() + m_h_gap;
if (line.near_label_widget_win) { if (line.near_label_widget_win) {
wxSize near_label_widget_sz = line.near_label_widget_win->GetSize(); wxSize near_label_widget_sz = line.near_label_widget_win->GetSize();
if (field_in) if (field_in)
@ -109,18 +104,20 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
wxString label = line.label; wxString label = line.label;
if (opt_group->label_width != 0 && !label.IsEmpty()) if (opt_group->label_width != 0 && !label.IsEmpty())
h_pos += opt_group->label_width * wxGetApp().em_unit() + m_h_gap; h_pos += opt_group->label_width * m_em_unit + m_h_gap;
if (line.widget) if (line.widget)
break; break;
int action_buttons_width = 3 * (m_bmp_blinking_sz.GetWidth() + m_h_gap);
// If we have a single option with no sidetext // If we have a single option with no sidetext
const std::vector<Option>& option_set = line.get_options(); const std::vector<Option>& option_set = line.get_options();
if (option_set.size() == 1 && option_set.front().opt.sidetext.size() == 0 && if (option_set.size() == 1 && option_set.front().opt.sidetext.size() == 0 &&
option_set.front().opt.label.empty() && option_set.front().opt.label.empty() &&
option_set.front().side_widget == nullptr && line.get_extra_widgets().size() == 0) option_set.front().side_widget == nullptr && line.get_extra_widgets().size() == 0)
{ {
h_pos += 3 * (m_bmp_blinking.bmp().GetWidth() + m_h_gap); h_pos += action_buttons_width;
break; break;
} }
@ -138,7 +135,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
dc.SetFont(m_font); dc.SetFont(m_font);
h_pos += dc.GetMultiLineTextExtent(label).x + m_h_gap; h_pos += dc.GetMultiLineTextExtent(label).x + m_h_gap;
} }
h_pos += 3 * (m_bmp_blinking.bmp().GetWidth() + m_h_gap); h_pos += action_buttons_width;
if (field == field_in) if (field == field_in)
break; break;
@ -149,10 +146,10 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
// add sidetext if any // add sidetext if any
if (!option.sidetext.empty() || opt_group->sidetext_width > 0) if (!option.sidetext.empty() || opt_group->sidetext_width > 0)
h_pos += opt_group->sidetext_width * wxGetApp().em_unit() + m_h_gap; h_pos += opt_group->sidetext_width * m_em_unit + m_h_gap;
if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back()) if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back())
h_pos += lround(0.6 * wxGetApp().em_unit()); h_pos += lround(0.6 * m_em_unit);
} }
break; break;
} }
@ -254,17 +251,72 @@ void OG_CustomCtrl::correct_widgets_position(wxSizer* widget, const Line& line,
void OG_CustomCtrl::msw_rescale() void OG_CustomCtrl::msw_rescale()
{ {
const wxFont& font = GUI::wxGetApp().normal_font(); m_font = wxGetApp().normal_font();
m_font = wxOSX ? font.Smaller() : font; m_em_unit = em_unit(m_parent);
m_v_gap = lround(1.0 * m_em_unit);
m_h_gap = lround(0.2 * m_em_unit);
m_bmp_mode_sz = create_scaled_bitmap("mode_simple", this, wxOSX ? 10 : 12).GetSize();
m_bmp_blinking_sz = create_scaled_bitmap("search_blink", this).GetSize();
wxCoord v_pos = 0;
for (CtrlLine& line : ctrl_lines) {
line.msw_rescale();
if (line.is_visible)
v_pos += (wxCoord)line.height;
}
this->SetMinSize(wxSize(wxDefaultCoord, v_pos));
wxSize new_sz = GUI::wxGetApp().em_unit() * this->GetSize();
SetMinSize(new_sz);
GetParent()->Layout(); GetParent()->Layout();
} }
void OG_CustomCtrl::sys_color_changed() void OG_CustomCtrl::sys_color_changed()
{ {
msw_rescale();
}
void OG_CustomCtrl::CtrlLine::correct_items_positions()
{
if (draw_just_act_buttons || !is_visible)
return;
if (og_line.near_label_widget_win)
ctrl->correct_window_position(og_line.near_label_widget_win, og_line);
if (og_line.widget_sizer)
ctrl->correct_widgets_position(og_line.widget_sizer, og_line);
if (og_line.extra_widget_sizer)
ctrl->correct_widgets_position(og_line.extra_widget_sizer, og_line);
const std::vector<Option>& option_set = og_line.get_options();
for (auto opt : option_set) {
Field* field = ctrl->opt_group->get_field(opt.opt_id);
if (!field)
continue;
if (field->getSizer())
ctrl->correct_widgets_position(field->getSizer(), og_line, field);
else if (field->getWindow())
ctrl->correct_window_position(field->getWindow(), og_line, field);
}
}
void OG_CustomCtrl::CtrlLine::msw_rescale()
{
// if we have a single option with no label, no sidetext
if (draw_just_act_buttons)
height = create_scaled_bitmap("empty").GetHeight();
if (ctrl->opt_group->label_width != 0 && !og_line.label.IsEmpty()) {
wxSize label_sz = ctrl->GetTextExtent(og_line.label);
height = label_sz.y * (label_sz.GetWidth() > int(ctrl->opt_group->label_width * ctrl->m_em_unit) ? 2 : 1) + ctrl->m_v_gap;
}
if (og_line.get_options().front().opt.full_width) {
Field* field = ctrl->opt_group->get_field(og_line.get_options().front().opt_id);
if (field->getWindow())
field->getWindow()->SetSize(wxSize(3 * Field::def_width_wider() * ctrl->m_em_unit, -1));
}
correct_items_positions();
} }
void OG_CustomCtrl::CtrlLine::update_visibility(ConfigOptionMode mode) void OG_CustomCtrl::CtrlLine::update_visibility(ConfigOptionMode mode)
@ -277,21 +329,12 @@ void OG_CustomCtrl::CtrlLine::update_visibility(ConfigOptionMode mode)
if (draw_just_act_buttons) if (draw_just_act_buttons)
return; return;
if (og_line.near_label_widget_win) { if (og_line.near_label_widget_win)
og_line.near_label_widget_win->Show(is_visible); og_line.near_label_widget_win->Show(is_visible);
if (is_visible) if (og_line.widget_sizer)
ctrl->correct_window_position(og_line.near_label_widget_win, og_line);
}
if (og_line.widget_sizer) {
og_line.widget_sizer->ShowItems(is_visible); og_line.widget_sizer->ShowItems(is_visible);
if (is_visible) if (og_line.extra_widget_sizer)
ctrl->correct_widgets_position(og_line.widget_sizer, og_line);
}
if (og_line.extra_widget_sizer) {
og_line.extra_widget_sizer->ShowItems(is_visible); og_line.extra_widget_sizer->ShowItems(is_visible);
if (is_visible)
ctrl->correct_widgets_position(og_line.extra_widget_sizer, og_line);
}
for (auto opt : option_set) { for (auto opt : option_set) {
Field* field = ctrl->opt_group->get_field(opt.opt_id); Field* field = ctrl->opt_group->get_field(opt.opt_id);
@ -299,30 +342,25 @@ void OG_CustomCtrl::CtrlLine::update_visibility(ConfigOptionMode mode)
continue; continue;
if (field->getSizer()) { if (field->getSizer()) {
if (is_visible)
ctrl->correct_widgets_position(field->getSizer(), og_line, field);
auto children = field->getSizer()->GetChildren(); auto children = field->getSizer()->GetChildren();
for (auto child : children) for (auto child : children)
if (child->IsWindow()) if (child->IsWindow())
child->GetWindow()->Show(is_visible); child->GetWindow()->Show(is_visible);
} }
else if (field->getWindow()) { else if (field->getWindow())
if (is_visible)
ctrl->correct_window_position(field->getWindow(), og_line, field);
field->getWindow()->Show(is_visible); field->getWindow()->Show(is_visible);
} }
}
correct_items_positions();
} }
void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos) void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
{ {
Field* field = nullptr; Field* field = ctrl->opt_group->get_field(og_line.get_options().front().opt_id);
field = ctrl->opt_group->get_field(og_line.get_options().front().opt_id);
if (draw_just_act_buttons) { if (draw_just_act_buttons) {
if (field) if (field)
draw_act_bmps(dc, wxPoint(0, v_pos), ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp()); draw_act_bmps(dc, wxPoint(0, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
return; return;
} }
@ -336,7 +374,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
wxString label = og_line.label; wxString label = og_line.label;
if (ctrl->opt_group->label_width != 0 && !label.IsEmpty()) { if (ctrl->opt_group->label_width != 0 && !label.IsEmpty()) {
const wxColour* text_clr = (option_set.size() == 1 && field ? field->label_color() : og_line.full_Label_color); const wxColour* text_clr = (option_set.size() == 1 && field ? field->label_color() : og_line.full_Label_color);
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label + ":", text_clr, ctrl->opt_group->label_width * wxGetApp().em_unit()); h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label + ":", text_clr, ctrl->opt_group->label_width * ctrl->m_em_unit);
} }
// If there's a widget, build it and add the result to the sizer. // If there's a widget, build it and add the result to the sizer.
@ -352,7 +390,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
option_set.front().side_widget == nullptr && og_line.get_extra_widgets().size() == 0) option_set.front().side_widget == nullptr && og_line.get_extra_widgets().size() == 0)
{ {
if (field) if (field)
draw_act_bmps(dc, wxPoint(h_pos, v_pos), ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp()); draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
return; return;
} }
@ -366,11 +404,11 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
_CTX(option.label, "Layers") : _(option.label); _CTX(option.label, "Layers") : _(option.label);
label += ":"; label += ":";
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label, field ? field->label_color() : nullptr, ctrl->opt_group->sublabel_width * wxGetApp().em_unit()); h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label, field ? field->label_color() : nullptr, ctrl->opt_group->sublabel_width * ctrl->m_em_unit);
} }
if (field) { if (field) {
h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp()); h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
if (field->getSizer()) if (field->getSizer())
{ {
auto children = field->getSizer()->GetChildren(); auto children = field->getSizer()->GetChildren();
@ -388,19 +426,19 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
// add sidetext if any // add sidetext if any
if (!option.sidetext.empty() || ctrl->opt_group->sidetext_width > 0) if (!option.sidetext.empty() || ctrl->opt_group->sidetext_width > 0)
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), _(option.sidetext), nullptr, ctrl->opt_group->sidetext_width * wxGetApp().em_unit()); h_pos = draw_text(dc, wxPoint(h_pos, v_pos), _(option.sidetext), nullptr, ctrl->opt_group->sidetext_width * ctrl->m_em_unit);
if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back()) if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back())
h_pos += lround(0.6 * wxGetApp().em_unit()); h_pos += lround(0.6 * ctrl->m_em_unit);
} }
} }
wxCoord OG_CustomCtrl::CtrlLine::draw_mode_bmp(wxDC& dc, wxCoord v_pos) wxCoord OG_CustomCtrl::CtrlLine::draw_mode_bmp(wxDC& dc, wxCoord v_pos)
{ {
ConfigOptionMode mode = og_line.get_options()[0].opt.mode; ConfigOptionMode mode = og_line.get_options()[0].opt.mode;
const wxBitmap& bmp = mode == ConfigOptionMode::comSimple ? ctrl->m_bmp_mode_simple.bmp() : const std::string& bmp_name = mode == ConfigOptionMode::comSimple ? "mode_simple" :
mode == ConfigOptionMode::comAdvanced ? ctrl->m_bmp_mode_advanced.bmp() : ctrl->m_bmp_mode_expert.bmp(); mode == ConfigOptionMode::comAdvanced ? "mode_advanced" : "mode_expert";
wxBitmap bmp = create_scaled_bitmap(bmp_name, ctrl, wxOSX ? 10 : 12);
wxCoord y_draw = v_pos + lround((height - bmp.GetHeight()) / 2); wxCoord y_draw = v_pos + lround((height - bmp.GetHeight()) / 2);
dc.DrawBitmap(bmp, 0, y_draw); dc.DrawBitmap(bmp, 0, y_draw);
@ -452,8 +490,9 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC& dc, wxPoint pos, const wxStr
return pos.x + width + ctrl->m_h_gap; return pos.x + width + ctrl->m_h_gap;
} }
wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_blinking, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo) wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo)
{ {
wxBitmap bmp_blinking = create_scaled_bitmap("search_blink", ctrl);
wxCoord h_pos = pos.x; wxCoord h_pos = pos.x;
wxCoord pos_y = pos.y + lround((height - bmp_blinking.GetHeight()) / 2); wxCoord pos_y = pos.y + lround((height - bmp_blinking.GetHeight()) / 2);

View file

@ -30,11 +30,10 @@ class OG_CustomCtrl :public wxControl
wxFont m_font; wxFont m_font;
int m_v_gap; int m_v_gap;
int m_h_gap; int m_h_gap;
int m_em_unit;
ScalableBitmap m_bmp_mode_simple; wxSize m_bmp_mode_sz;
ScalableBitmap m_bmp_mode_advanced; wxSize m_bmp_blinking_sz;
ScalableBitmap m_bmp_mode_expert;
ScalableBitmap m_bmp_blinking;
struct CtrlLine { struct CtrlLine {
wxCoord height { wxDefaultCoord }; wxCoord height { wxDefaultCoord };
@ -48,12 +47,16 @@ class OG_CustomCtrl :public wxControl
wxRect m_rect_undo_icon; wxRect m_rect_undo_icon;
wxRect m_rect_undo_to_sys_icon; wxRect m_rect_undo_to_sys_icon;
~CtrlLine() { ctrl = nullptr; }
void correct_items_positions();
void msw_rescale();
void update_visibility(ConfigOptionMode mode); void update_visibility(ConfigOptionMode mode);
void render(wxDC& dc, wxCoord v_pos); void render(wxDC& dc, wxCoord v_pos);
wxCoord draw_mode_bmp(wxDC& dc, wxCoord v_pos); wxCoord draw_mode_bmp(wxDC& dc, wxCoord v_pos);
wxCoord draw_text (wxDC& dc, wxPoint pos, const wxString& text, const wxColour* color, int width); wxCoord draw_text (wxDC& dc, wxPoint pos, const wxString& text, const wxColour* color, int width);
wxCoord draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_blinking, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo); wxCoord draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo);
}; };
std::vector<CtrlLine> ctrl_lines; std::vector<CtrlLine> ctrl_lines;

View file

@ -686,6 +686,9 @@ void ConfigOptionsGroup::msw_rescale()
for (const auto& field : m_fields) for (const auto& field : m_fields)
field.second->msw_rescale(sidetext_width>0); field.second->msw_rescale(sidetext_width>0);
if (custom_ctrl)
custom_ctrl->msw_rescale();
const int em = em_unit(parent()); const int em = em_unit(parent());
// rescale width of label column // rescale width of label column

View file

@ -677,6 +677,9 @@ void TabPrinter::msw_rescale()
for (auto page : pages) for (auto page : pages)
page->msw_rescale(); page->msw_rescale();
if (m_reset_to_filament_color)
m_reset_to_filament_color->msw_rescale();
Layout(); Layout();
} }
@ -951,6 +954,9 @@ void Tab::msw_rescale()
for (ScalableBitmap& bmp : m_mode_bitmap_cache) for (ScalableBitmap& bmp : m_mode_bitmap_cache)
bmp.msw_rescale(); bmp.msw_rescale();
if (m_detach_preset_btn)
m_detach_preset_btn->msw_rescale();
// rescale icons for tree_ctrl // rescale icons for tree_ctrl
for (ScalableBitmap& bmp : m_scaled_icons_list) for (ScalableBitmap& bmp : m_scaled_icons_list)
bmp.msw_rescale(); bmp.msw_rescale();