Rebuild the Brim Type Combobox Only When Its Entries Change

toggle_options() now runs on every value change and mode switch; rebuild the
brim_type choices only when the leading-edge entry has to be added or removed.
This commit is contained in:
Hanif Koh
2026-09-11 15:57:58 +08:00
parent f2a11928f6
commit 4a7311bf01

View File

@@ -3230,16 +3230,17 @@ void TabPrint::toggle_options()
const auto current = m_config->opt_enum<BrimType>("brim_type"); const auto current = m_config->opt_enum<BrimType>("brim_type");
auto &opt = const_cast<ConfigOptionDef &>(field->m_opt); auto &opt = const_cast<ConfigOptionDef &>(field->m_opt);
auto cb = dynamic_cast<ComboBox *>(choice->window); auto cb = dynamic_cast<ComboBox *>(choice->window);
if (cb != nullptr) { // Keep the entry if it is already selected, so switching to a non-belt
// printer cannot leave the control showing a value it does not offer.
const bool offer_leading_edge = is_belt_printer || current == btLeadingEdgeOnly;
const bool offered = std::find(opt.enum_values.begin(), opt.enum_values.end(), "leading_edge_only") != opt.enum_values.end();
if (cb != nullptr && offer_leading_edge != offered) {
auto n = cb->GetValue(); auto n = cb->GetValue();
opt.enum_values.clear(); opt.enum_values.clear();
opt.enum_labels.clear(); opt.enum_labels.clear();
cb->Clear(); cb->Clear();
for (size_t i = 0; i < def->enum_values.size(); ++ i) { for (size_t i = 0; i < def->enum_values.size(); ++ i) {
// Keep the entry if it is already selected, so switching to a non-belt if (def->enum_values[i] == "leading_edge_only" && ! offer_leading_edge)
// printer cannot leave the control showing a value it does not offer.
if (def->enum_values[i] == "leading_edge_only" && ! is_belt_printer
&& current != btLeadingEdgeOnly)
continue; continue;
opt.enum_values.push_back(def->enum_values[i]); opt.enum_values.push_back(def->enum_values[i]);
opt.enum_labels.push_back(def->enum_labels[i]); opt.enum_labels.push_back(def->enum_labels[i]);