diff --git a/source/service_menu.cpp b/source/service_menu.cpp index 9baf5b7..63f7b6c 100644 --- a/source/service_menu.cpp +++ b/source/service_menu.cpp @@ -523,34 +523,34 @@ void ServiceMenu::precalculateMenuWidths() // Para cada grupo for (int group = 0; group < 5; ++group) { SettingsGroup sg = static_cast(group); - int max_width = MIN_WIDTH_; + int max_option_width = 0; + int max_value_width = 0; for (const auto &option : options_) { if (option.group != sg) continue; - int option_width = element_text_->lenght(option.caption); - int value_width = 0; - // Calcular el valor más ancho posible para esta opción + // Opción más larga + max_option_width = std::max(max_option_width, element_text_->lenght(option.caption, -2)); + // Valor más largo de todos los posibles valores de todas las opciones switch (option.type) { case ValueType::BOOL: - value_width = std::max(element_text_->lenght(lang::getText("[SERVICE_MENU] ON")), - element_text_->lenght(lang::getText("[SERVICE_MENU] OFF"))); + max_value_width = std::max({max_value_width, + element_text_->lenght(lang::getText("[SERVICE_MENU] ON"), -2), + element_text_->lenght(lang::getText("[SERVICE_MENU] OFF"), -2)}); break; case ValueType::INT: - // Considera el valor máximo y mínimo como strings - value_width = std::max( - element_text_->lenght(std::to_string(option.min_value)), - element_text_->lenght(std::to_string(option.max_value))); + max_value_width = std::max({max_value_width, + element_text_->lenght(std::to_string(option.min_value), -2), + element_text_->lenght(std::to_string(option.max_value), -2)}); break; case ValueType::LIST: for (const auto &val : option.value_list) - value_width = std::max(value_width, element_text_->lenght(val)); + max_value_width = std::max(max_value_width, element_text_->lenght(val, -2)); break; default: - value_width = 0; + break; } - int total_width = option_width + MIN_GAP_OPTION_VALUE_ + value_width; - max_width = std::max(max_width, total_width); } - group_menu_widths_[group] = max_width; + size_t total_width = max_option_width + MIN_GAP_OPTION_VALUE_ + max_value_width + OPTIONS_HORIZONTAL_PADDING_*2; + group_menu_widths_[group] = std::max(MIN_WIDTH_, total_width); } } diff --git a/source/service_menu.h b/source/service_menu.h index 886b558..b108509 100644 --- a/source/service_menu.h +++ b/source/service_menu.h @@ -46,7 +46,7 @@ private: static constexpr const char *MENU_SOUND_ = "clock.wav"; // Sonido al navegar por el menú static constexpr size_t OPTIONS_HORIZONTAL_PADDING_ = 20; // Relleno horizontal de las opciones static constexpr size_t MIN_WIDTH_ = 240; // Anchura mínima del menu - static constexpr size_t MIN_GAP_OPTION_VALUE_ = 20; // Espacio mínimo entre una opción y su valor + static constexpr size_t MIN_GAP_OPTION_VALUE_ = 30; // Espacio mínimo entre una opción y su valor // --- Enumeraciones internas --- enum class Aspect @@ -244,9 +244,8 @@ private: void updateResizeAnimation(); // --- Métodos internos: Cálculo de anchos --- -void precalculateMenuWidths(); -int getMenuWidthForGroup(SettingsGroup group) const; - + void precalculateMenuWidths(); + int getMenuWidthForGroup(SettingsGroup group) const; // --- Patrón Singleton --- ServiceMenu(); // Constructor privado