From 1c354ea2ab8e4bdde03366d34e7056c35146d855 Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Sun, 1 Sep 2024 23:23:26 +0200 Subject: [PATCH] Set wswitch 'index' variable private --- src/gui/MItem_crash.cpp | 2 +- src/gui/MItem_experimental_tools.cpp | 8 ++++---- src/gui/MItem_hardware.hpp | 12 ++++++------ src/gui/MItem_mmu.cpp | 4 ++-- src/gui/MItem_network.cpp | 8 ++++---- src/gui/MItem_tools.cpp | 8 ++++---- src/gui/screen_menu_footer_settings.cpp | 2 +- src/gui/screen_menu_fw_update.cpp | 6 +++--- src/gui/screen_menu_metrics.cpp | 6 +++--- src/guiapi/include/WindowMenuSwitch.hpp | 1 + 10 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/gui/MItem_crash.cpp b/src/gui/MItem_crash.cpp index ab8c0468ce..eeed85579e 100644 --- a/src/gui/MItem_crash.cpp +++ b/src/gui/MItem_crash.cpp @@ -84,7 +84,7 @@ constexpr size_t MI_CRASH_SENSITIVITY_XY::get_item_id_from_sensitivity(int32_t s } void MI_CRASH_SENSITIVITY_XY::OnChange([[maybe_unused]] size_t old_index) { - int32_t sensitivity = ITEMS[index].value; + int32_t sensitivity = ITEMS[this->GetIndex()].value; xy_long_t se = crash_s.get_sensitivity(); se.x = sensitivity; se.y = sensitivity; diff --git a/src/gui/MItem_experimental_tools.cpp b/src/gui/MItem_experimental_tools.cpp index f0a055dd8e..8d5509baf3 100644 --- a/src/gui/MItem_experimental_tools.cpp +++ b/src/gui/MItem_experimental_tools.cpp @@ -111,7 +111,7 @@ MI_DIRECTION_X::MI_DIRECTION_X() : WiSwitchDirection(has_wrong_x(), NOTRAN(label)) {} void MI_DIRECTION_X::Store() { - index == 1 ? set_wrong_direction_x() : set_PRUSA_direction_x(); + GetIndex() == 1 ? set_wrong_direction_x() : set_PRUSA_direction_x(); } /*****************************************************************************/ @@ -120,7 +120,7 @@ MI_DIRECTION_Y::MI_DIRECTION_Y() : WiSwitchDirection(has_wrong_y(), NOTRAN(label)) {} void MI_DIRECTION_Y::Store() { - index == 1 ? set_wrong_direction_y() : set_PRUSA_direction_y(); + GetIndex() == 1 ? set_wrong_direction_y() : set_PRUSA_direction_y(); } /*****************************************************************************/ @@ -129,7 +129,7 @@ MI_DIRECTION_Z::MI_DIRECTION_Z() : WiSwitchDirection(has_wrong_z(), NOTRAN(label)) {} void MI_DIRECTION_Z::Store() { - index == 1 ? set_wrong_direction_z() : set_PRUSA_direction_z(); + GetIndex() == 1 ? set_wrong_direction_z() : set_PRUSA_direction_z(); } /*****************************************************************************/ @@ -138,7 +138,7 @@ MI_DIRECTION_E::MI_DIRECTION_E() : WiSwitchDirection(has_wrong_e(), NOTRAN(label)) {} void MI_DIRECTION_E::Store() { - index == 1 ? set_wrong_direction_e() : set_PRUSA_direction_e(); + GetIndex() == 1 ? set_wrong_direction_e() : set_PRUSA_direction_e(); } /*****************************************************************************/ diff --git a/src/gui/MItem_hardware.hpp b/src/gui/MItem_hardware.hpp index 4dc36439d1..9c159c9b88 100644 --- a/src/gui/MItem_hardware.hpp +++ b/src/gui/MItem_hardware.hpp @@ -53,22 +53,22 @@ class MI_HARDWARE_CHECK_t : public WI_SWITCH_t<3> { void OnChange([[maybe_unused]] size_t old_index) override { switch (HWCheck) { case HWCheckType::nozzle: - config_store().hw_check_nozzle.set(static_cast(index)); + config_store().hw_check_nozzle.set(static_cast(GetIndex())); break; case HWCheckType::model: - config_store().hw_check_model.set(static_cast(index)); + config_store().hw_check_model.set(static_cast(GetIndex())); break; case HWCheckType::firmware: - config_store().hw_check_firmware.set(static_cast(index)); + config_store().hw_check_firmware.set(static_cast(GetIndex())); break; case HWCheckType::gcode: - config_store().hw_check_gcode.set(static_cast(index)); + config_store().hw_check_gcode.set(static_cast(GetIndex())); break; case HWCheckType::gcode_compatibility: - config_store().hw_check_compatibility.set(static_cast(index)); + config_store().hw_check_compatibility.set(static_cast(GetIndex())); break; case HWCheckType::fan_compatibility: - config_store().hw_check_fan_compatibility.set(static_cast(index)); + config_store().hw_check_fan_compatibility.set(static_cast(GetIndex())); break; default: assert(false); diff --git a/src/gui/MItem_mmu.cpp b/src/gui/MItem_mmu.cpp index 73e1568afb..3a977e6feb 100644 --- a/src/gui/MItem_mmu.cpp +++ b/src/gui/MItem_mmu.cpp @@ -272,7 +272,7 @@ MI_MMU_NEXTRUDER_REWORK::MI_MMU_NEXTRUDER_REWORK() : WI_SWITCH_t(config_store().is_mmu_rework.get(), _(label), nullptr, is_enabled_t::yes, is_hidden_t::no, _(val_0), _(val_1)) {} void MI_MMU_NEXTRUDER_REWORK::OnChange([[maybe_unused]] size_t old_index) { - if (!flip_mmu_rework(index == 0)) { + if (!flip_mmu_rework(GetIndex() == 0)) { SetIndex(old_index); // revert the index change of the toggle in case the user aborted the dialog return; } @@ -280,7 +280,7 @@ void MI_MMU_NEXTRUDER_REWORK::OnChange([[maybe_unused]] size_t old_index) { // Enabling MMU rework hides the FS_Autoload option from the menu - BFW-4290 // However the request was that the autoload "stays active" // So we have to make sure that it's on when you activate the rework - if (index) { + if (GetIndex()) { marlin_client::set_fs_autoload(true); config_store().fs_autoload_enabled.set(true); } diff --git a/src/gui/MItem_network.cpp b/src/gui/MItem_network.cpp index 5a77bb52b9..df55f056c4 100644 --- a/src/gui/MItem_network.cpp +++ b/src/gui/MItem_network.cpp @@ -122,7 +122,7 @@ MI_NET_INTERFACE_t::MI_NET_INTERFACE_t() } void MI_NET_INTERFACE_t::OnChange([[maybe_unused]] size_t old_index) { - netdev_set_active_id(this->index); + netdev_set_active_id(this->GetIndex()); } MI_HOSTNAME::MI_HOSTNAME() @@ -176,12 +176,12 @@ MI_NET_IP::MI_NET_IP(NetDeviceID device_id) : WI_SWITCH_t(0, string_view_utf8::MakeCPUFLASH(label), nullptr, is_enabled_t::yes, is_hidden_t::no, string_view_utf8::MakeCPUFLASH(str_DHCP), string_view_utf8::MakeCPUFLASH(str_static)) , device_id(device_id) // { - index = netdev_get_ip_obtained_type(this->device_id()); + this->SetIndex(netdev_get_ip_obtained_type(this->device_id())); } void MI_NET_IP::OnChange([[maybe_unused]] size_t old_index) { const auto dev_id = device_id(); - if (index == NETDEV_STATIC) { + if (this->GetIndex() == NETDEV_STATIC) { netdev_set_static(dev_id); } else { netdev_set_dhcp(dev_id); @@ -190,7 +190,7 @@ void MI_NET_IP::OnChange([[maybe_unused]] size_t old_index) { MI_NET_IP_VER_t::MI_NET_IP_VER_t() : WI_SWITCH_t(0, _(label), nullptr, is_enabled_t::no, is_hidden_t::no, string_view_utf8::MakeCPUFLASH(str_v4), string_view_utf8::MakeCPUFLASH(str_v6)) { - this->index = 0; + this->SetIndex(0); } IMI_IP4_ADDR::IMI_IP4_ADDR(const char *label, NetDeviceID device_id, AddrType addr) diff --git a/src/gui/MItem_tools.cpp b/src/gui/MItem_tools.cpp index aefaf1dc6c..f8e75b90c6 100644 --- a/src/gui/MItem_tools.cpp +++ b/src/gui/MItem_tools.cpp @@ -396,7 +396,7 @@ MI_SOUND_MODE::MI_SOUND_MODE() } void MI_SOUND_MODE::OnChange(size_t /*old_index*/) { - Sound_SetMode(static_cast(index)); + Sound_SetMode(static_cast(GetIndex())); } /*****************************************************************************/ @@ -465,7 +465,7 @@ MI_TIMEZONE_MIN::MI_TIMEZONE_MIN() : WI_SWITCH_t<3>(static_cast(config_store().timezone_minutes.get()), _(label), nullptr, is_enabled_t::yes, is_hidden_t::no, _(str_0min), _(str_30min), _(str_45min)) {} void MI_TIMEZONE_MIN::OnChange([[maybe_unused]] size_t old_index) { - config_store().timezone_minutes.set(static_cast(index)); + config_store().timezone_minutes.set(static_cast(GetIndex())); } /*****************************************************************************/ @@ -474,7 +474,7 @@ MI_TIMEZONE_SUMMER::MI_TIMEZONE_SUMMER() : WI_ICON_SWITCH_OFF_ON_t(static_cast(config_store().timezone_summer.get()), _(label), nullptr, is_enabled_t::yes, is_hidden_t::no) {} void MI_TIMEZONE_SUMMER::OnChange([[maybe_unused]] size_t old_index) { - config_store().timezone_summer.set(static_cast(index)); + config_store().timezone_summer.set(static_cast(GetIndex())); } /*****************************************************************************/ @@ -483,7 +483,7 @@ MI_TIME_FORMAT::MI_TIME_FORMAT() : WI_SWITCH_t<2>(static_cast(config_store().time_format.get()), _(label), nullptr, is_enabled_t::yes, is_hidden_t::no, _(str_12h), _(str_24h)) {} void MI_TIME_FORMAT::OnChange([[maybe_unused]] size_t old_index) { - config_store().time_format.set(static_cast(index)); + config_store().time_format.set(static_cast(GetIndex())); } /*****************************************************************************/ diff --git a/src/gui/screen_menu_footer_settings.cpp b/src/gui/screen_menu_footer_settings.cpp index c1d51e249f..3a874d2a46 100644 --- a/src/gui/screen_menu_footer_settings.cpp +++ b/src/gui/screen_menu_footer_settings.cpp @@ -81,7 +81,7 @@ MI_LEFT_ALIGN_TEMP::MI_LEFT_ALIGN_TEMP() string_view_utf8::MakeCPUFLASH((const uint8_t *)str_2)) {} void MI_LEFT_ALIGN_TEMP::OnChange(size_t /*old_index*/) { - FooterItemHeater::SetDrawType(footer::ItemDrawType(index)); + FooterItemHeater::SetDrawType(footer::ItemDrawType(GetIndex())); } MI_SHOW_ZERO_TEMP_TARGET::MI_SHOW_ZERO_TEMP_TARGET() diff --git a/src/gui/screen_menu_fw_update.cpp b/src/gui/screen_menu_fw_update.cpp index e4530506b9..ccbc99827b 100644 --- a/src/gui/screen_menu_fw_update.cpp +++ b/src/gui/screen_menu_fw_update.cpp @@ -54,13 +54,13 @@ MI_UPDATE::MI_UPDATE() } void MI_UPDATE::OnChange(size_t /*old_index*/) { - if (index == 1) { + if (GetIndex() == 1) { data_exchange::fw_update_on_restart_enable(); sys_fw_update_disable(); - } else if (index == 2) { + } else if (GetIndex() == 2) { data_exchange::fw_update_on_restart_disable(); sys_fw_update_enable(); - } else if (index == 0) { + } else if (GetIndex() == 0) { data_exchange::fw_update_on_restart_disable(); sys_fw_update_disable(); } diff --git a/src/gui/screen_menu_metrics.cpp b/src/gui/screen_menu_metrics.cpp index 9321734274..e99cb16616 100644 --- a/src/gui/screen_menu_metrics.cpp +++ b/src/gui/screen_menu_metrics.cpp @@ -98,15 +98,15 @@ MI_METRICS_ALLOW::MI_METRICS_ALLOW() , warning_not_shown(config_store().metrics_allow.get() == MetricsAllow::None) {} void MI_METRICS_ALLOW::OnChange(size_t old_index) { - if (old_index == ftrstd::to_underlying(MetricsAllow::None) && index != ftrstd::to_underlying(MetricsAllow::None)) { // Enable + if (old_index == ftrstd::to_underlying(MetricsAllow::None) && GetIndex() != ftrstd::to_underlying(MetricsAllow::None)) { // Enable if (warning_not_shown && MsgBoxWarning(_(txt_confirm), Responses_YesNo, 1) != Response::Yes) { - index = ftrstd::to_underlying(MetricsAllow::None); // User changed his mind + SetIndex(ftrstd::to_underlying(MetricsAllow::None)); // User changed his mind } else { warning_not_shown = false; } } - config_store().metrics_allow.set(MetricsAllow(index)); + config_store().metrics_allow.set(MetricsAllow(GetIndex())); check_disable(); } diff --git a/src/guiapi/include/WindowMenuSwitch.hpp b/src/guiapi/include/WindowMenuSwitch.hpp index 5eb52559b8..47f5e41372 100644 --- a/src/guiapi/include/WindowMenuSwitch.hpp +++ b/src/guiapi/include/WindowMenuSwitch.hpp @@ -78,4 +78,5 @@ class WI_SWITCH_t : public IWiSwitch { private: std::array items_; + size_t index; };