Custom control : Implemented update items visibility in respect to the mode

This commit is contained in:
YuSanka 2020-10-22 22:38:23 +02:00 committed by Oleksandra Yushchenko
parent 534a2f5d33
commit 1b3c288b35
5 changed files with 210 additions and 151 deletions

View File

@ -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) void Field::msw_rescale(bool rescale_sidetext)
{ {
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();

View File

@ -21,7 +21,7 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
const wxValidator& val /* = wxDefaultValidator*/, const wxValidator& val /* = wxDefaultValidator*/,
const wxString& name/* = wxEmptyString*/) : const wxString& name/* = wxEmptyString*/) :
wxControl(parent, wxID_ANY, pos, size, wxWANTS_CHARS | wxBORDER_NONE), wxControl(parent, wxID_ANY, pos, size, wxWANTS_CHARS | wxBORDER_NONE),
m_og(og) opt_group(og)
{ {
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
@ -48,9 +48,7 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
void OG_CustomCtrl::init_ctrl_lines() void OG_CustomCtrl::init_ctrl_lines()
{ {
wxCoord v_pos = 0; for (const Line& line : opt_group->get_lines())
for (const Line& line : m_og->get_lines())
{ {
if (line.full_width && ( if (line.full_width && (
// description line // description line
@ -65,7 +63,7 @@ void OG_CustomCtrl::init_ctrl_lines()
wxCoord height = 0; 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 && 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.label.empty() &&
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)
@ -73,25 +71,22 @@ void OG_CustomCtrl::init_ctrl_lines()
height = m_bmp_blinking.bmp().GetHeight() + m_v_gap; height = m_bmp_blinking.bmp().GetHeight() + m_v_gap;
ctrl_lines.emplace_back(CtrlLine{ height, this, line, true }); 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); 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 }); ctrl_lines.emplace_back(CtrlLine{ height, this, line });
} }
else else
int i = 0; int i = 0;
v_pos += height;
} }
this->SetMinSize(wxSize(wxDefaultCoord, v_pos));
} }
int OG_CustomCtrl::get_height(const Line& line) int OG_CustomCtrl::get_height(const Line& line)
{ {
for (auto ctrl_line : ctrl_lines) for (auto ctrl_line : ctrl_lines)
if (&ctrl_line.m_og_line == &line) if (&ctrl_line.og_line == &line)
return ctrl_line.m_height; return ctrl_line.height;
return 0; return 0;
} }
@ -101,11 +96,11 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
wxCoord v_pos = 0; wxCoord v_pos = 0;
wxCoord h_pos = 0; wxCoord h_pos = 0;
for (auto ctrl_line : ctrl_lines) { 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; h_pos = m_bmp_mode_simple.bmp().GetWidth() + m_h_gap;
if (line.near_label_widget) { if (line.near_label_widget_win) {
wxSize near_label_widget_sz = m_og->get_last_near_label_widget()->GetSize(); wxSize near_label_widget_sz = line.near_label_widget_win->GetSize();
if (field_in) if (field_in)
h_pos += near_label_widget_sz.GetWidth() + m_h_gap; h_pos += near_label_widget_sz.GetWidth() + m_h_gap;
else else
@ -113,8 +108,8 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
} }
wxString label = line.label; wxString label = line.label;
if (m_og->label_width != 0 && !label.IsEmpty()) if (opt_group->label_width != 0 && !label.IsEmpty())
h_pos += m_og->label_width * wxGetApp().em_unit() + m_h_gap; h_pos += opt_group->label_width * wxGetApp().em_unit() + m_h_gap;
if (line.widget) if (line.widget)
break; break;
@ -130,7 +125,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
} }
for (auto opt : option_set) { 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; ConfigOptionDef option = opt.opt;
// add label if any // add label if any
if (!option.label.empty()) { if (!option.label.empty()) {
@ -153,15 +148,16 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
break; break;
// add sidetext if any // add sidetext if any
if (!option.sidetext.empty() || m_og->sidetext_width > 0) if (!option.sidetext.empty() || opt_group->sidetext_width > 0)
h_pos += m_og->sidetext_width * wxGetApp().em_unit() + m_h_gap; 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()) 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 * wxGetApp().em_unit());
} }
break; break;
} }
v_pos += ctrl_line.m_height; if (ctrl_line.is_visible)
v_pos += ctrl_line.height;
} }
return wxPoint(h_pos, v_pos); return wxPoint(h_pos, v_pos);
@ -184,7 +180,7 @@ void OG_CustomCtrl::OnPaint(wxPaintEvent&)
if (!line.is_visible) if (!line.is_visible)
continue; continue;
line.render(dc, v_pos); 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) 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() void OG_CustomCtrl::msw_rescale()
{ {
const wxFont& font = GUI::wxGetApp().normal_font(); 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<Option>& option_set = og_line.get_options();
const ConfigOptionMode& line_mode = option_set.front().opt.mode;
is_visible = line_mode <= mode;
if (draw_just_act_buttons)
return;
if (og_line.near_label_widget_win) {
og_line.near_label_widget_win->Show(is_visible);
if (is_visible)
ctrl->correct_window_position(og_line.near_label_widget_win, og_line);
}
if (og_line.widget_sizer) {
og_line.widget_sizer->ShowItems(is_visible);
if (is_visible)
ctrl->correct_widgets_position(og_line.widget_sizer, og_line);
}
if (og_line.extra_widget_sizer) {
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) {
Field* field = ctrl->opt_group->get_field(opt.opt_id);
if (!field)
continue;
if (field->getSizer()) {
if (is_visible)
ctrl->correct_widgets_position(field->getSizer(), og_line, field);
auto children = field->getSizer()->GetChildren();
for (auto child : children)
if (child->IsWindow())
child->GetWindow()->Show(is_visible);
}
else if (field->getWindow()) {
if (is_visible)
ctrl->correct_window_position(field->getWindow(), og_line, field);
field->getWindow()->Show(is_visible);
}
}
}
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 = nullptr;
field = m_ctrl->m_og->get_field(m_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), m_ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp()); draw_act_bmps(dc, wxPoint(0, v_pos), ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
return; return;
} }
wxCoord h_pos = draw_mode_bmp(dc, v_pos); wxCoord h_pos = draw_mode_bmp(dc, v_pos);
if (m_og_line.near_label_widget) if (og_line.near_label_widget_win)
h_pos += m_ctrl->m_bmp_blinking.bmp().GetWidth() + m_ctrl->m_h_gap;//m_og_line.near_label_widget->GetSize().x;; h_pos += og_line.near_label_widget_win->GetSize().x + ctrl->m_h_gap;
const std::vector<Option>& option_set = m_og_line.get_options(); const std::vector<Option>& option_set = og_line.get_options();
wxString label = m_og_line.label; wxString label = og_line.label;
if (m_ctrl->m_og->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() : m_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, m_ctrl->m_og->label_width * wxGetApp().em_unit()); h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label + ":", text_clr, ctrl->opt_group->label_width * wxGetApp().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.
if (m_og_line.widget != nullptr) if (og_line.widget != nullptr)
return; return;
// If we're here, we have more than one option or a single option with sidetext // If we're here, we have more than one option or a single option with sidetext
@ -271,15 +349,15 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
// If we have a single option with no sidetext just add it directly to the grid sizer // If we have a single option with no sidetext just add it directly to the grid sizer
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 && m_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), m_ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp()); draw_act_bmps(dc, wxPoint(h_pos, v_pos), ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
return; return;
} }
for (auto opt : option_set) { for (auto opt : option_set) {
field = m_ctrl->m_og->get_field(opt.opt_id); field = ctrl->opt_group->get_field(opt.opt_id);
ConfigOptionDef option = opt.opt; ConfigOptionDef option = opt.opt;
// add label if any // add label if any
if (!option.label.empty()) { if (!option.label.empty()) {
@ -288,20 +366,20 @@ 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, m_ctrl->m_og->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 * wxGetApp().em_unit());
} }
if (field) { if (field) {
h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), m_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), ctrl->m_bmp_blinking.bmp(), 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();
for (auto child : children) for (auto child : children)
if (child->IsWindow()) if (child->IsWindow())
h_pos += child->GetWindow()->GetSize().x + m_ctrl->m_h_gap; h_pos += child->GetWindow()->GetSize().x + ctrl->m_h_gap;
} }
else if (field->getWindow()) else if (field->getWindow())
h_pos += field->getWindow()->GetSize().x + m_ctrl->m_h_gap; h_pos += field->getWindow()->GetSize().x + ctrl->m_h_gap;
} }
// add field // add field
@ -309,8 +387,8 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
break; break;
// add sidetext if any // add sidetext if any
if (!option.sidetext.empty() || m_ctrl->m_og->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, m_ctrl->m_og->sidetext_width * wxGetApp().em_unit()); h_pos = draw_text(dc, wxPoint(h_pos, v_pos), _(option.sidetext), nullptr, ctrl->opt_group->sidetext_width * wxGetApp().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 * wxGetApp().em_unit());
@ -319,15 +397,15 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
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 = m_og_line.get_options()[0].opt.mode; ConfigOptionMode mode = og_line.get_options()[0].opt.mode;
const wxBitmap& bmp = mode == ConfigOptionMode::comSimple ? m_ctrl->m_bmp_mode_simple.bmp() : const wxBitmap& bmp = mode == ConfigOptionMode::comSimple ? ctrl->m_bmp_mode_simple.bmp() :
mode == ConfigOptionMode::comAdvanced ? m_ctrl->m_bmp_mode_advanced.bmp() : m_ctrl->m_bmp_mode_expert.bmp(); mode == ConfigOptionMode::comAdvanced ? ctrl->m_bmp_mode_advanced.bmp() : ctrl->m_bmp_mode_expert.bmp();
wxCoord y_draw = v_pos + lround((m_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);
return bmp.GetWidth() + m_ctrl->m_h_gap; return bmp.GetWidth() + ctrl->m_h_gap;
} }
wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC& dc, wxPoint pos, const wxString& text, const wxColour* color, int width) wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC& dc, wxPoint pos, const wxString& text, const wxColour* color, int width)
@ -361,7 +439,7 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC& dc, wxPoint pos, const wxStr
wxCoord text_width, text_height; wxCoord text_width, text_height;
dc.GetMultiLineTextExtent(out_text, &text_width, &text_height); dc.GetMultiLineTextExtent(out_text, &text_width, &text_height);
pos.y = pos.y + lround((m_height - text_height) / 2); pos.y = pos.y + lround((height - text_height) / 2);
wxColour old_clr = dc.GetTextForeground(); wxColour old_clr = dc.GetTextForeground();
dc.SetTextForeground(color ? *color : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); dc.SetTextForeground(color ? *color : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
@ -371,32 +449,32 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC& dc, wxPoint pos, const wxStr
if (width < 1) if (width < 1)
width = text_width; width = text_width;
return pos.x + width + m_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_blinking, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo)
{ {
wxCoord h_pos = pos.x; wxCoord h_pos = pos.x;
wxCoord pos_y = pos.y + lround((m_height - bmp_blinking.GetHeight()) / 2); wxCoord pos_y = pos.y + lround((height - bmp_blinking.GetHeight()) / 2);
dc.DrawBitmap(bmp_blinking, h_pos, pos_y); dc.DrawBitmap(bmp_blinking, h_pos, pos_y);
int bmp_dim = bmp_blinking.GetWidth(); int bmp_dim = bmp_blinking.GetWidth();
m_rect_blinking = wxRect(h_pos, pos_y, bmp_dim, bmp_dim); m_rect_blinking = wxRect(h_pos, pos_y, bmp_dim, bmp_dim);
h_pos += bmp_dim + m_ctrl->m_h_gap; h_pos += bmp_dim + ctrl->m_h_gap;
dc.DrawBitmap(bmp_undo_to_sys, h_pos, pos_y); dc.DrawBitmap(bmp_undo_to_sys, h_pos, pos_y);
bmp_dim = bmp_undo_to_sys.GetWidth(); bmp_dim = bmp_undo_to_sys.GetWidth();
m_rect_undo_to_sys_icon = wxRect(h_pos, pos_y, bmp_dim, bmp_dim); m_rect_undo_to_sys_icon = wxRect(h_pos, pos_y, bmp_dim, bmp_dim);
h_pos += bmp_dim + m_ctrl->m_h_gap; h_pos += bmp_dim + ctrl->m_h_gap;
dc.DrawBitmap(bmp_undo, h_pos, pos_y); dc.DrawBitmap(bmp_undo, h_pos, pos_y);
bmp_dim = bmp_undo.GetWidth(); bmp_dim = bmp_undo.GetWidth();
m_rect_undo_icon = wxRect(h_pos, pos_y, bmp_dim, bmp_dim); m_rect_undo_icon = wxRect(h_pos, pos_y, bmp_dim, bmp_dim);
h_pos += bmp_dim + m_ctrl->m_h_gap; h_pos += bmp_dim + ctrl->m_h_gap;
return h_pos; return h_pos;
} }

View File

@ -27,7 +27,9 @@ namespace Slic3r { namespace GUI {
// Static text shown among the options. // Static text shown among the options.
class OG_CustomCtrl :public wxControl class OG_CustomCtrl :public wxControl
{ {
wxFont m_font; wxFont m_font;
int m_v_gap;
int m_h_gap;
ScalableBitmap m_bmp_mode_simple; ScalableBitmap m_bmp_mode_simple;
ScalableBitmap m_bmp_mode_advanced; ScalableBitmap m_bmp_mode_advanced;
@ -35,23 +37,23 @@ class OG_CustomCtrl :public wxControl
ScalableBitmap m_bmp_blinking; ScalableBitmap m_bmp_blinking;
struct CtrlLine { struct CtrlLine {
wxCoord m_height { wxDefaultCoord }; wxCoord height { wxDefaultCoord };
OG_CustomCtrl* m_ctrl { nullptr }; OG_CustomCtrl* ctrl { nullptr };
const Line& m_og_line; const Line& og_line;
bool draw_just_act_buttons { false }; bool draw_just_act_buttons { false };
bool is_visible { true }; bool is_visible { true };
wxRect m_rect_blinking;
wxRect m_rect_undo_icon;
wxRect m_rect_undo_to_sys_icon;
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_blinking, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo);
void set_visible(bool show) { is_visible = show; }
wxRect m_rect_blinking;
wxRect m_rect_undo_icon;
wxRect m_rect_undo_to_sys_icon;
}; };
std::vector<CtrlLine> ctrl_lines; std::vector<CtrlLine> ctrl_lines;
@ -72,15 +74,16 @@ public:
void init_ctrl_lines(); void init_ctrl_lines();
bool update_visibility(ConfigOptionMode mode); bool update_visibility(ConfigOptionMode mode);
void correct_window_position(wxWindow* win, const Line& line, Field* field = nullptr);
void correct_widgets_position(wxSizer* widget, const Line& line, Field* field = nullptr);
void msw_rescale(); void msw_rescale();
void sys_color_changed(); void sys_color_changed();
wxPoint get_pos(const Line& line, Field* field = nullptr); wxPoint get_pos(const Line& line, Field* field = nullptr);
int get_height(const Line& line); int get_height(const Line& line);
OptionsGroup* m_og; OptionsGroup* opt_group;
int m_v_gap;
int m_h_gap;
}; };

View File

@ -218,35 +218,12 @@ void OptionsGroup::activate_line(Line& line)
grid_sizer->Add(m_extra_column_item_ptrs.back(), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 3); grid_sizer->Add(m_extra_column_item_ptrs.back(), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 3);
} }
auto correct_window_position = [this](wxWindow* win, const Line& line, Field* field = nullptr) { // Build a label if we have it
wxPoint pos = custom_ctrl->get_pos(line, field);
int line_height = custom_ctrl->get_height(line);
pos.y += std::max(0, int(0.5 * (line_height - win->GetSize().y)));
win->SetPosition(pos);
};
auto correct_widgets_position = [this](wxSizer* widget, const Line& line, Field* field = nullptr) {
auto children = widget->GetChildren();
wxPoint line_pos = custom_ctrl->get_pos(line, field);
int line_height = custom_ctrl->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 + custom_ctrl->m_h_gap;
}
};
// Build a label if we have it
wxStaticText* label=nullptr; wxStaticText* label=nullptr;
if (label_width != 0) { if (label_width != 0) {
if (custom_ctrl) { if (custom_ctrl) {
if (line.near_label_widget) { if (line.near_label_widget)
m_near_label_widget_ptrs.push_back(line.near_label_widget(this->ctrl_parent())); line.near_label_widget_win = line.near_label_widget(this->ctrl_parent());
correct_window_position(m_near_label_widget_ptrs.back(), line);
}
} }
else { else {
if (!line.near_label_widget || !line.label.IsEmpty()) { if (!line.near_label_widget || !line.label.IsEmpty()) {
@ -285,15 +262,14 @@ void OptionsGroup::activate_line(Line& line)
} }
} }
if (line.full_Label != nullptr) if (!custom_ctrl && line.full_Label != nullptr)
*line.full_Label = label; // Initiate the pointer to the control of the full label, if we need this one. *line.full_Label = label; // Initiate the pointer to the control of the full label, if we need this one.
// 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.
if (line.widget != nullptr) { if (line.widget != nullptr) {
auto wgt = line.widget(this->ctrl_parent()); auto wgt = line.widget(this->ctrl_parent());
if (custom_ctrl) if (custom_ctrl)
correct_widgets_position(wgt, line); line.widget_sizer = wgt;
// If widget doesn't have label, don't use border
else else
grid_sizer->Add(wgt, 0, wxEXPAND | wxBOTTOM | wxTOP, (wxOSX || line.label.IsEmpty()) ? 0 : 5); grid_sizer->Add(wgt, 0, wxEXPAND | wxBOTTOM | wxTOP, (wxOSX || line.label.IsEmpty()) ? 0 : 5);
return; return;
@ -311,20 +287,18 @@ void OptionsGroup::activate_line(Line& line)
const auto& option = option_set.front(); const auto& option = option_set.front();
const auto& field = build_field(option, label); const auto& field = build_field(option, label);
if (!custom_ctrl) if (custom_ctrl) {
if (is_window_field(field) && option.opt.full_width)
field->getWindow()->SetSize(wxSize(3 * Field::def_width_wider() * wxGetApp().em_unit(), -1));
}
else {
add_undo_buttons_to_sizer(sizer, field); add_undo_buttons_to_sizer(sizer, field);
if (is_window_field(field)) { if (is_window_field(field))
if (custom_ctrl) {
correct_window_position(field->getWindow(), line, field.get());
if (option.opt.full_width)
field->getWindow()->SetSize(wxSize(3 * Field::def_width_wider() * wxGetApp().em_unit(), -1));
}
else
sizer->Add(field->getWindow(), option.opt.full_width ? 1 : 0, sizer->Add(field->getWindow(), option.opt.full_width ? 1 : 0,
wxBOTTOM | wxTOP | (option.opt.full_width ? wxEXPAND : wxALIGN_CENTER_VERTICAL), (wxOSX || !staticbox) ? 0 : 2); wxBOTTOM | wxTOP | (option.opt.full_width ? wxEXPAND : wxALIGN_CENTER_VERTICAL), (wxOSX || !staticbox) ? 0 : 2);
if (is_sizer_field(field))
sizer->Add(field->getSizer(), 1, option.opt.full_width ? wxEXPAND : wxALIGN_CENTER_VERTICAL, 0);
} }
if (is_sizer_field(field))
sizer->Add(field->getSizer(), 1, option.opt.full_width ? wxEXPAND : wxALIGN_CENTER_VERTICAL, 0);
return; return;
} }
@ -347,62 +321,40 @@ void OptionsGroup::activate_line(Line& line)
// add field // add field
const Option& opt_ref = opt; const Option& opt_ref = opt;
auto& field = build_field(opt_ref, label); auto& field = build_field(opt_ref, label);
if (!custom_ctrl) if (!custom_ctrl) {
add_undo_buttons_to_sizer(sizer_tmp, field); add_undo_buttons_to_sizer(sizer_tmp, field);
if (option_set.size() == 1 && option_set.front().opt.full_width) if (option_set.size() == 1 && option_set.front().opt.full_width)
{ {
if (custom_ctrl) {
if (is_window_field(field))
correct_window_position(field->getWindow(), line, field.get());
else {
correct_widgets_position(field->getSizer(), line, field.get());
}
}
else {
const auto v_sizer = new wxBoxSizer(wxVERTICAL); const auto v_sizer = new wxBoxSizer(wxVERTICAL);
sizer_tmp->Add(v_sizer, 1, wxEXPAND); sizer_tmp->Add(v_sizer, 1, wxEXPAND);
is_sizer_field(field) ? is_sizer_field(field) ?
v_sizer->Add(field->getSizer(), 0, wxEXPAND) : v_sizer->Add(field->getSizer(), 0, wxEXPAND) :
v_sizer->Add(field->getWindow(), 0, wxEXPAND); v_sizer->Add(field->getWindow(), 0, wxEXPAND);
break;
} }
break;//return;
}
if (custom_ctrl) {
if (is_window_field(field))
correct_window_position(field->getWindow(), line, field.get());
else
correct_widgets_position(field->getSizer(), line, field.get());
}
else {
is_sizer_field(field) ? is_sizer_field(field) ?
sizer_tmp->Add(field->getSizer(), 0, wxALIGN_CENTER_VERTICAL, 0) : sizer_tmp->Add(field->getSizer(), 0, wxALIGN_CENTER_VERTICAL, 0) :
sizer_tmp->Add(field->getWindow(), 0, wxALIGN_CENTER_VERTICAL, 0); sizer_tmp->Add(field->getWindow(), 0, wxALIGN_CENTER_VERTICAL, 0);
// add sidetext if any
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), wxALIGN_LEFT);
sidetext->SetBackgroundStyle(wxBG_STYLE_PAINT);
sidetext->SetFont(wxGetApp().normal_font());
sizer_tmp->Add(sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4);
field->set_side_text_ptr(sidetext);
}
// add side widget if any
if (opt.side_widget != nullptr) {
sizer_tmp->Add(opt.side_widget(this->ctrl_parent())/*!.target<wxWindow>()*/, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 1); //! requires verification
}
if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back())
sizer_tmp->AddSpacer(6);
} }
// add sidetext if any
if (!custom_ctrl)
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), wxALIGN_LEFT);
sidetext->SetBackgroundStyle(wxBG_STYLE_PAINT);
sidetext->SetFont(wxGetApp().normal_font());
sizer_tmp->Add(sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4);
field->set_side_text_ptr(sidetext);
}
// add side widget if any
if (opt.side_widget != nullptr) {
sizer_tmp->Add(opt.side_widget(this->ctrl_parent())/*!.target<wxWindow>()*/, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 1); //! requires verification
}
if (custom_ctrl)
continue;
if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back())
{
sizer_tmp->AddSpacer(6);
}
} }
// add extra sizers if any // add extra sizers if any
@ -419,7 +371,7 @@ void OptionsGroup::activate_line(Line& line)
auto extra_wgt = extra_widget(this->ctrl_parent()); auto extra_wgt = extra_widget(this->ctrl_parent());
if (custom_ctrl) if (custom_ctrl)
correct_widgets_position(extra_wgt, line); line.extra_widget_sizer = extra_wgt;
else else
sizer->Add(extra_wgt, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4); //! requires verification sizer->Add(extra_wgt, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4); //! requires verification
} }
@ -484,10 +436,24 @@ void OptionsGroup::clear()
m_grid_sizer = nullptr; m_grid_sizer = nullptr;
sizer = nullptr; sizer = nullptr;
for (Line& line : m_lines) for (Line& line : m_lines) {
if(line.full_Label) if(line.full_Label)
*line.full_Label = nullptr; *line.full_Label = nullptr;
if (line.near_label_widget_win)
line.near_label_widget_win = nullptr;
if (line.widget_sizer) {
line.widget_sizer->Clear(true);
line.widget_sizer = nullptr;
}
if (line.extra_widget_sizer) {
line.extra_widget_sizer->Clear(true);
line.extra_widget_sizer = nullptr;
}
}
if (custom_ctrl) { if (custom_ctrl) {
for (auto const &item : m_fields) { for (auto const &item : m_fields) {
wxWindow* win = item.second.get()->getWindow(); wxWindow* win = item.second.get()->getWindow();
@ -670,6 +636,13 @@ bool ConfigOptionsGroup::update_visibility(ConfigOptionMode mode)
{ {
if (m_options_mode.empty() || !m_grid_sizer) if (m_options_mode.empty() || !m_grid_sizer)
return true; return true;
if (custom_ctrl) {
bool show = custom_ctrl->update_visibility(mode);
this->Show(show);
return show;
}
int opt_mode_size = m_options_mode.size(); int opt_mode_size = m_options_mode.size();
if (m_grid_sizer->GetEffectiveRowsCount() != opt_mode_size && if (m_grid_sizer->GetEffectiveRowsCount() != opt_mode_size &&
opt_mode_size == 1) opt_mode_size == 1)

View File

@ -56,6 +56,9 @@ public:
wxColour* full_Label_color {nullptr}; wxColour* full_Label_color {nullptr};
widget_t widget {nullptr}; widget_t widget {nullptr};
std::function<wxWindow*(wxWindow*)> near_label_widget{ nullptr }; std::function<wxWindow*(wxWindow*)> near_label_widget{ nullptr };
wxWindow* near_label_widget_win {nullptr};
wxSizer* widget_sizer {nullptr};
wxSizer* extra_widget_sizer {nullptr};
void append_option(const Option& option) { void append_option(const Option& option) {
m_options.push_back(option); m_options.push_back(option);