mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 03:12:04 +08:00
Follow-up to 299b01d
Add select_close GUIType and process it + Field::Choice: Fix a check of m_opt.enum_def existence + Fixed OSX build
This commit is contained in:
parent
f2fbfef332
commit
917c9ad47b
@ -1812,6 +1812,8 @@ public:
|
|||||||
legend,
|
legend,
|
||||||
// Vector value, but edited as a single string.
|
// Vector value, but edited as a single string.
|
||||||
one_string,
|
one_string,
|
||||||
|
// Close parameter, string value could be one of the list values.
|
||||||
|
select_close,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Identifier of this option. It is stored here so that it is accessible through the by_serialization_key_ordinal map.
|
// Identifier of this option. It is stored here so that it is accessible through the by_serialization_key_ordinal map.
|
||||||
|
@ -334,7 +334,7 @@ void PrintConfigDef::init_common_params()
|
|||||||
def = this->add("printhost_port", coString);
|
def = this->add("printhost_port", coString);
|
||||||
def->label = L("Printer");
|
def->label = L("Printer");
|
||||||
def->tooltip = L("Name of the printer");
|
def->tooltip = L("Name of the printer");
|
||||||
// def->gui_type = ConfigOptionDef::GUIType::select_open;
|
def->gui_type = ConfigOptionDef::GUIType::select_close;
|
||||||
def->mode = comAdvanced;
|
def->mode = comAdvanced;
|
||||||
def->cli = ConfigOptionDef::nocli;
|
def->cli = ConfigOptionDef::nocli;
|
||||||
def->set_default_value(new ConfigOptionString(""));
|
def->set_default_value(new ConfigOptionString(""));
|
||||||
|
@ -991,7 +991,9 @@ void Choice::BUILD() {
|
|||||||
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);
|
||||||
|
|
||||||
choice_ctrl* temp;
|
choice_ctrl* temp;
|
||||||
if (m_opt.gui_type != ConfigOptionDef::GUIType::undefined && m_opt.gui_type != ConfigOptionDef::GUIType::select_open) {
|
if (m_opt.gui_type != ConfigOptionDef::GUIType::undefined
|
||||||
|
&& m_opt.gui_type != ConfigOptionDef::GUIType::select_open
|
||||||
|
&& m_opt.gui_type != ConfigOptionDef::GUIType::select_close) {
|
||||||
m_is_editable = true;
|
m_is_editable = true;
|
||||||
temp = new choice_ctrl(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size, 0, nullptr, wxTE_PROCESS_ENTER);
|
temp = new choice_ctrl(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size, 0, nullptr, wxTE_PROCESS_ENTER);
|
||||||
}
|
}
|
||||||
@ -1021,11 +1023,13 @@ void Choice::BUILD() {
|
|||||||
// recast as a wxWindow to fit the calling convention
|
// recast as a wxWindow to fit the calling convention
|
||||||
window = dynamic_cast<wxWindow*>(temp);
|
window = dynamic_cast<wxWindow*>(temp);
|
||||||
|
|
||||||
if (auto &labels = m_opt.enum_def->labels(); ! labels.empty()) {
|
if (m_opt.enum_def) {
|
||||||
bool localized = m_opt.enum_def->has_labels();
|
if (auto& labels = m_opt.enum_def->labels(); !labels.empty()) {
|
||||||
for (const std::string &el : labels)
|
bool localized = m_opt.enum_def->has_labels();
|
||||||
temp->Append(localized ? _(wxString::FromUTF8(el)) : wxString::FromUTF8(el));
|
for (const std::string& el : labels)
|
||||||
set_selection();
|
temp->Append(localized ? _(from_u8(el)) : from_u8(el));
|
||||||
|
set_selection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
temp->Bind(wxEVT_MOUSEWHEEL, [this](wxMouseEvent& e) {
|
temp->Bind(wxEVT_MOUSEWHEEL, [this](wxMouseEvent& e) {
|
||||||
@ -1171,9 +1175,17 @@ void Choice::set_value(const boost::any& value, bool change_event)
|
|||||||
wxString text_value = m_opt.type == coInt ?
|
wxString text_value = m_opt.type == coInt ?
|
||||||
wxString::Format(_T("%i"), int(boost::any_cast<int>(value))) :
|
wxString::Format(_T("%i"), int(boost::any_cast<int>(value))) :
|
||||||
boost::any_cast<wxString>(value);
|
boost::any_cast<wxString>(value);
|
||||||
if (auto idx = m_opt.enum_def->label_to_index(into_u8(text_value)); idx.has_value()) {
|
int sel_idx = -1;
|
||||||
field->SetSelection(idx.value());
|
if (m_opt.enum_def) {
|
||||||
} else {
|
if (auto idx = m_opt.enum_def->label_to_index(into_u8(text_value)); idx.has_value())
|
||||||
|
sel_idx = idx.value();
|
||||||
|
else if (idx = m_opt.enum_def->value_to_index(into_u8(text_value)); idx.has_value())
|
||||||
|
sel_idx = idx.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sel_idx >= 0 )
|
||||||
|
field->SetSelection(sel_idx);
|
||||||
|
else {
|
||||||
// For editable Combobox under OSX is needed to set selection to -1 explicitly,
|
// For editable Combobox under OSX is needed to set selection to -1 explicitly,
|
||||||
// otherwise selection doesn't be changed
|
// otherwise selection doesn't be changed
|
||||||
field->SetSelection(-1);
|
field->SetSelection(-1);
|
||||||
@ -1305,22 +1317,19 @@ void Choice::msw_rescale()
|
|||||||
// Set rescaled size
|
// Set rescaled size
|
||||||
field->SetSize(size);
|
field->SetSize(size);
|
||||||
|
|
||||||
size_t idx = 0;
|
if (m_opt.enum_def) {
|
||||||
if (m_opt.enum_def && ! m_opt.enum_def->labels().empty()) {
|
if (auto& labels = m_opt.enum_def->labels(); !labels.empty()) {
|
||||||
size_t counter = 0;
|
const bool localized = m_opt.enum_def->has_labels();
|
||||||
bool localized = m_opt.enum_def->has_labels();
|
for (const std::string& el : labels)
|
||||||
for (const std::string &el : m_opt.enum_def->labels()) {
|
field->Append(localized ? _(from_u8(el)) : from_u8(el));
|
||||||
wxString text = localized ? _(el) : from_u8(el);
|
|
||||||
field->Append(text);
|
if (auto opt = m_opt.enum_def->label_to_index(into_u8(selection)); opt.has_value())
|
||||||
if (text == selection)
|
// This enum has a value field of the same content as text_value. Select it.
|
||||||
idx = counter;
|
field->SetSelection(opt.value());
|
||||||
++ counter;
|
else
|
||||||
|
field->SetValue(selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idx == m_opt.enum_values.size() ?
|
|
||||||
field->SetValue(selection) :
|
|
||||||
field->SetSelection(idx);
|
|
||||||
#else
|
#else
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
field->Rescale();
|
field->Rescale();
|
||||||
|
@ -32,16 +32,15 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co
|
|||||||
// Check the gui_type field first, fall through
|
// Check the gui_type field first, fall through
|
||||||
// is the normal type.
|
// is the normal type.
|
||||||
switch (opt.gui_type) {
|
switch (opt.gui_type) {
|
||||||
|
case ConfigOptionDef::GUIType::select_close:
|
||||||
case ConfigOptionDef::GUIType::select_open:
|
case ConfigOptionDef::GUIType::select_open:
|
||||||
|
case ConfigOptionDef::GUIType::f_enum_open:
|
||||||
|
case ConfigOptionDef::GUIType::i_enum_open:
|
||||||
m_fields.emplace(id, Choice::Create<Choice>(this->ctrl_parent(), opt, id));
|
m_fields.emplace(id, Choice::Create<Choice>(this->ctrl_parent(), opt, id));
|
||||||
break;
|
break;
|
||||||
case ConfigOptionDef::GUIType::color:
|
case ConfigOptionDef::GUIType::color:
|
||||||
m_fields.emplace(id, ColourPicker::Create<ColourPicker>(this->ctrl_parent(), opt, id));
|
m_fields.emplace(id, ColourPicker::Create<ColourPicker>(this->ctrl_parent(), opt, id));
|
||||||
break;
|
break;
|
||||||
case ConfigOptionDef::GUIType::f_enum_open:
|
|
||||||
case ConfigOptionDef::GUIType::i_enum_open:
|
|
||||||
m_fields.emplace(id, Choice::Create<Choice>(this->ctrl_parent(), opt, id));
|
|
||||||
break;
|
|
||||||
case ConfigOptionDef::GUIType::slider:
|
case ConfigOptionDef::GUIType::slider:
|
||||||
m_fields.emplace(id, SliderCtrl::Create<SliderCtrl>(this->ctrl_parent(), opt, id));
|
m_fields.emplace(id, SliderCtrl::Create<SliderCtrl>(this->ctrl_parent(), opt, id));
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user