Custom control : Fixed color of the colored label, associated with option, which doesn't have a corresponded field

This commit is contained in:
YuSanka 2020-10-22 13:02:17 +02:00 committed by Oleksandra Yushchenko
parent 7022fb0891
commit 534a2f5d33
5 changed files with 38 additions and 15 deletions

View File

@ -32,7 +32,6 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
m_bmp_mode_expert = ScalableBitmap(this, "mode_expert" , wxOSX ? 10 : 12);
m_bmp_blinking = ScalableBitmap(this, "search_blink");
m_border = lround(0.2 * wxGetApp().em_unit());
m_v_gap = lround(1.0 * wxGetApp().em_unit());
m_h_gap = lround(0.2 * wxGetApp().em_unit());
@ -115,7 +114,7 @@ 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();
h_pos += m_og->label_width * wxGetApp().em_unit() + m_h_gap;
if (line.widget)
break;
@ -140,7 +139,9 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
_CTX(option.label, "Layers") : _(option.label);
label += ":";
h_pos += GetTextExtent(label).x + m_h_gap;
wxPaintDC dc(this);
dc.SetFont(m_font);
h_pos += dc.GetMultiLineTextExtent(label).x + m_h_gap;
}
h_pos += 3 * (m_bmp_blinking.bmp().GetWidth() + m_h_gap);
@ -153,7 +154,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
// add sidetext if any
if (!option.sidetext.empty() || m_og->sidetext_width > 0)
h_pos += m_og->sidetext_width * wxGetApp().em_unit();
h_pos += m_og->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());
@ -255,8 +256,10 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
const std::vector<Option>& option_set = m_og_line.get_options();
wxString label = m_og_line.label;
if (m_ctrl->m_og->label_width != 0 && !label.IsEmpty())
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label+":", (option_set.size() == 1 && field ? field->label_color() : m_og_line.full_Label_color), m_ctrl->m_og->label_width*wxGetApp().em_unit());
if (m_ctrl->m_og->label_width != 0 && !label.IsEmpty()) {
const wxColour* text_clr = (option_set.size() == 1 && field ? field->label_color() : m_og_line.full_Label_color);
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label + ":", text_clr, m_ctrl->m_og->label_width * wxGetApp().em_unit());
}
// If there's a widget, build it and add the result to the sizer.
if (m_og_line.widget != nullptr)
@ -322,9 +325,9 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_mode_bmp(wxDC& dc, wxCoord v_pos)
wxCoord y_draw = v_pos + lround((m_height - bmp.GetHeight()) / 2);
dc.DrawBitmap(bmp, m_ctrl->m_border, y_draw);
dc.DrawBitmap(bmp, 0, y_draw);
return m_ctrl->m_border + bmp.GetWidth() + m_ctrl->m_h_gap;
return bmp.GetWidth() + m_ctrl->m_h_gap;
}
wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC& dc, wxPoint pos, const wxString& text, const wxColour* color, int width)

View File

@ -79,7 +79,6 @@ public:
int get_height(const Line& line);
OptionsGroup* m_og;
int m_border;
int m_v_gap;
int m_h_gap;

View File

@ -53,7 +53,7 @@ public:
wxString label_tooltip {wxString("")};
size_t full_width {0};
wxStaticText** full_Label {nullptr};
wxColor* full_Label_color {nullptr};
wxColour* full_Label_color {nullptr};
widget_t widget {nullptr};
std::function<wxWindow*(wxWindow*)> near_label_widget{ nullptr };

View File

@ -492,6 +492,10 @@ void Tab::update_labels_colour()
label->SetForegroundColour(*color);
label->Refresh(true);
}
if (m_colored_Label_colors.find(opt.first) != m_colored_Label_colors.end())
*m_colored_Label_colors.at(opt.first) = *color;
continue;
}
@ -528,13 +532,17 @@ void Tab::decorate()
wxStaticText* label = nullptr;
Field* field = nullptr;
if (opt.first == "bed_shape" || opt.first == "filament_ramming_parameters" ||
opt.first == "compatible_prints" || opt.first == "compatible_printers")
label = (m_colored_Labels.find(opt.first) == m_colored_Labels.end()) ? nullptr : m_colored_Labels.at(opt.first);
wxColour* colored_label_clr = nullptr;
if (!label)
if (opt.first == "bed_shape" || opt.first == "filament_ramming_parameters" ||
opt.first == "compatible_prints" || opt.first == "compatible_printers") {
label = (m_colored_Labels.find(opt.first) == m_colored_Labels.end()) ? nullptr : m_colored_Labels.at(opt.first);
colored_label_clr = (m_colored_Label_colors.find(opt.first) == m_colored_Label_colors.end()) ? nullptr : m_colored_Label_colors.at(opt.first);
}
if (!label && !colored_label_clr)
field = get_field(opt.first);
if (!label && !field)
if (!label && !colored_label_clr && !field)
continue;
bool is_nonsys_value = false;
@ -571,6 +579,11 @@ void Tab::decorate()
label->Refresh(true);
continue;
}
if (colored_label_clr) {
*colored_label_clr = *color;
continue;
}
field->m_is_nonsys_value = is_nonsys_value;
field->m_is_modified_value = is_modified_value;
@ -3498,6 +3511,10 @@ void Tab::create_line_with_widget(ConfigOptionsGroup* optgroup, const std::strin
m_colored_Labels[opt_key] = nullptr;
line.full_Label = &m_colored_Labels[opt_key];
m_colored_Label_colors[opt_key] = &m_default_text_clr;
line.full_Label_color = m_colored_Label_colors[opt_key];
optgroup->append_line(line);
}

View File

@ -255,6 +255,10 @@ public:
// Used for options which don't have corresponded field
std::map<std::string, wxStaticText*> m_colored_Labels;
// map of option name -> wxColour (color of the colored label, associated with option)
// Used for options which don't have corresponded field
std::map<std::string, wxColour*> m_colored_Label_colors;
// map of option name -> BlinkingBitmap (blinking ikon, associated with option)
// Used for options which don't have corresponded field
std::map<std::string, BlinkingBitmap*> m_blinking_ikons;