Changed layout of the "Machine limits" settings tab

This commit is contained in:
YuSanka 2020-11-18 12:08:09 +01:00
parent faff112ea8
commit a9f6e6da9d
4 changed files with 36 additions and 24 deletions

View file

@ -90,7 +90,7 @@ void OG_CustomCtrl::init_ctrl_lines()
height = m_bmp_blinking_sz.GetHeight() + m_v_gap;
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() || option_set.front().opt.gui_type == "legend") )
{
wxSize label_sz = GetTextExtent(line.label);
height = label_sz.y * (label_sz.GetWidth() > int(opt_group->label_width * m_em_unit) ? 2 : 1) + m_v_gap;
@ -135,7 +135,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
}
wxString label = line.label;
if (opt_group->label_width != 0 && !label.IsEmpty())
if (opt_group->label_width != 0)
h_pos += opt_group->label_width * m_em_unit + m_h_gap;
int blinking_button_width = m_bmp_blinking_sz.GetWidth() + m_h_gap;
@ -177,10 +177,13 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
GetTextExtent(label, &label_w, &label_h, 0, 0, &m_font);
h_pos += label_w + 1 + m_h_gap;
}
h_pos += 3 * blinking_button_width;
h_pos += (opt.opt.gui_type == "legend" ? 1 : 3) * blinking_button_width;
if (field == field_in)
break;
break;
if (opt.opt.gui_type == "legend")
h_pos += 2 * blinking_button_width;
h_pos += field->getWindow()->GetSize().x;
if (option_set.size() == 1 && option_set.front().opt.full_width)
@ -556,7 +559,8 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_mode_bmp(wxDC& dc, wxCoord v_pos)
wxBitmap bmp = create_scaled_bitmap(bmp_name, ctrl, wxOSX ? 10 : 12);
wxCoord y_draw = v_pos + lround((height - get_bitmap_size(bmp).GetHeight()) / 2);
dc.DrawBitmap(bmp, 0, y_draw);
if (og_line.get_options().front().opt.gui_type != "legend")
dc.DrawBitmap(bmp, 0, y_draw);
return get_bitmap_size(bmp).GetWidth() + ctrl->m_h_gap;
}

View file

@ -106,11 +106,20 @@ OptionsGroup::OptionsGroup( wxWindow* _parent, const wxString& title,
bool is_tab_opt /* = false */,
column_t extra_clmn /* = nullptr */) :
m_parent(_parent), title(title),
m_show_modified_btns(is_tab_opt),
m_use_custom_ctrl(is_tab_opt),
staticbox(title!=""), extra_column(extra_clmn)
{
}
bool OptionsGroup::is_legend_line()
{
if (m_lines.size() == 1) {
const std::vector<Option>& option_set = m_lines.front().get_options();
return !option_set.empty() && option_set.front().opt.gui_type == "legend";
}
return false;
}
void OptionsGroup::show_field(const t_config_option_key& opt_key, bool show/* = true*/)
{
Field* field = get_field(opt_key);
@ -196,16 +205,20 @@ void OptionsGroup::activate_line(Line& line)
}
}
if (!custom_ctrl && m_show_modified_btns) {
custom_ctrl = new OG_CustomCtrl((wxWindow*)this->stb, this);
sizer->Add(custom_ctrl, 0, wxEXPAND | wxALL, wxOSX || !staticbox ? 0 : 5);
}
auto option_set = line.get_options();
bool is_legend_line = option_set.front().opt.gui_type == "legend";
if (!custom_ctrl && m_use_custom_ctrl) {
custom_ctrl = new OG_CustomCtrl(is_legend_line ? this->parent() : (wxWindow*)this->stb, this);
if (is_legend_line)
sizer->Add(custom_ctrl, 0, wxEXPAND | wxLEFT, wxOSX ? 0 : 10);
else
sizer->Add(custom_ctrl, 0, wxEXPAND | wxALL, wxOSX || !staticbox ? 0 : 5);
}
// Set sidetext width for a better alignment of options in line
// "m_show_modified_btns==true" means that options groups are in tabs
if (option_set.size() > 1 && m_show_modified_btns) {
if (option_set.size() > 1 && m_use_custom_ctrl) {
sidetext_width = Field::def_width_thinner();
}
@ -231,7 +244,7 @@ void OptionsGroup::activate_line(Line& line)
m_use_custom_ctrl_as_parent = true;
// if we have an extra column, build it
if (extra_column && !m_show_modified_btns)
if (extra_column)
{
m_extra_column_item_ptrs.push_back(extra_column(this->ctrl_parent(), line));
grid_sizer->Add(m_extra_column_item_ptrs.back(), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 3);
@ -511,7 +524,7 @@ Option ConfigOptionsGroup::get_option(const std::string& opt_key, int opt_index
std::pair<std::string, int> pair(opt_key, opt_index);
m_opt_map.emplace(opt_id, pair);
if (m_show_modified_btns) // fill group and category values just fro options from Settings Tab
if (m_use_custom_ctrl) // fill group and category values just for options from Settings Tab
wxGetApp().sidebar().get_searcher().add_key(opt_id, title, this->config_category());
return Option(*m_config->def()->get(opt_key), opt_id);

View file

@ -129,7 +129,7 @@ public:
#endif /* __WXGTK__ */
wxWindow* ctrl_parent() const {
return this->stb ? (this->custom_ctrl && m_use_custom_ctrl_as_parent ? (wxWindow*)this->custom_ctrl : (wxWindow*)this->stb) : this->parent();
return this->custom_ctrl && m_use_custom_ctrl_as_parent ? (wxWindow*)this->custom_ctrl : (this->stb ? (wxWindow*)this->stb : this->parent());
}
void append_line(const Line& line);
@ -173,10 +173,6 @@ public:
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
void set_grid_vgap(int gap) { m_grid_sizer->SetVGap(gap); }
void set_show_modified_btns_val(bool show) {
m_show_modified_btns = show;
}
void clear_fields_except_of(const std::vector<std::string> left_fields);
void hide_labels() { label_width = 0; }
@ -187,6 +183,7 @@ public:
wxGridSizer* get_grid_sizer() { return m_grid_sizer; }
const std::vector<Line>& get_lines() { return m_lines; }
bool is_legend_line();
protected:
std::map<t_config_option_key, Option> m_options;
@ -203,7 +200,7 @@ protected:
bool m_disabled {false};
wxGridSizer* m_grid_sizer {nullptr};
// "true" if option is created in preset tabs
bool m_show_modified_btns{ false };
bool m_use_custom_ctrl{ false };
// "true" if control should be created on custom_ctrl
bool m_use_custom_ctrl_as_parent { false };

View file

@ -2372,13 +2372,11 @@ PageShp TabPrinter::build_kinematics_page()
if (m_use_silent_mode) {
// Legend for OptionsGroups
auto optgroup = page->new_optgroup("");
optgroup->set_show_modified_btns_val(false);
optgroup->label_width = 23;// 230;
auto line = Line{ "", "" };
ConfigOptionDef def;
def.type = coString;
def.width = 15;
def.width = Field::def_width();
def.gui_type = "legend";
def.mode = comAdvanced;
def.tooltip = L("Values in this column are for Normal mode");
@ -3783,7 +3781,7 @@ void Page::activate(ConfigOptionMode mode, std::function<void()> throw_if_cancel
for (auto group : m_optgroups) {
if (!group->activate(throw_if_canceled))
continue;
m_vsizer->Add(group->sizer, 0, wxEXPAND | wxALL, 10);
m_vsizer->Add(group->sizer, 0, wxEXPAND | (group->is_legend_line() ? (wxLEFT|wxTOP) : wxALL), 10);
group->update_visibility(mode);
group->reload_config();
throw_if_canceled();