diff --git a/source/ui/help_overlay.cpp b/source/ui/help_overlay.cpp index 732f6e5..920d475 100644 --- a/source/ui/help_overlay.cpp +++ b/source/ui/help_overlay.cpp @@ -122,6 +122,23 @@ void HelpOverlay::reinitializeFontSize(int new_font_size) { texture_needs_rebuild_ = true; } +void HelpOverlay::updateAll(int font_size, int physical_width, int physical_height) { + // Actualizar dimensiones físicas PRIMERO + physical_width_ = physical_width; + physical_height_ = physical_height; + + // Reinicializar text renderer con nuevo tamaño (si cambió) + if (text_renderer_) { + text_renderer_->reinitialize(font_size); + } + + // Recalcular dimensiones del box con nuevo font y nuevas dimensiones + calculateBoxDimensions(); + + // Marcar textura para regeneración completa + texture_needs_rebuild_ = true; +} + void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) { if (!text_renderer_) { max_width = 0; @@ -176,15 +193,36 @@ void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) { // Ancho total: 2 columnas + 3 paddings (izq, medio, der) max_width = max_col1_width + max_col2_width + padding * 3; - // Altura: contar líneas y calcular - int num_lines = 0; + // Altura: contar líneas REALES en cada columna + int col1_lines = 0; + int col2_lines = 0; + current_column = 0; + for (const auto& binding : key_bindings_) { - if (strcmp(binding.key, "[new_col]") != 0) { - num_lines++; + // Cambio de columna + if (strcmp(binding.key, "[new_col]") == 0) { + current_column = 1; + continue; + } + + // Separador vacío no cuenta como línea + if (binding.key[0] == '\0') { + continue; + } + + // Contar línea (ya sea encabezado o contenido) + if (current_column == 0) { + col1_lines++; + } else { + col2_lines++; } } - // Altura: título + espacio + líneas de contenido - total_height = line_height * 2 + (num_lines / 2 + 2) * line_height + padding * 2; + + // Usar la columna más larga para calcular altura + int max_column_lines = std::max(col1_lines, col2_lines); + + // Altura: título (2 líneas) + contenido + padding superior e inferior + total_height = line_height * 2 + max_column_lines * line_height + padding * 2; } void HelpOverlay::calculateBoxDimensions() { diff --git a/source/ui/help_overlay.h b/source/ui/help_overlay.h index ad0fd8c..d6eaaba 100644 --- a/source/ui/help_overlay.h +++ b/source/ui/help_overlay.h @@ -41,6 +41,14 @@ class HelpOverlay { */ void reinitializeFontSize(int new_font_size); + /** + * @brief Actualiza font size Y dimensiones físicas de forma atómica + * @param font_size Tamaño de fuente actual + * @param physical_width Nueva anchura física + * @param physical_height Nueva altura física + */ + void updateAll(int font_size, int physical_width, int physical_height); + /** * @brief Toggle visibilidad del overlay */ diff --git a/source/ui/ui_manager.cpp b/source/ui/ui_manager.cpp index d09b84e..2ca1ae4 100644 --- a/source/ui/ui_manager.cpp +++ b/source/ui/ui_manager.cpp @@ -175,18 +175,15 @@ void UIManager::updatePhysicalWindowSize(int width, int height) { if (text_renderer_notifier_) { text_renderer_notifier_->reinitialize(current_font_size_); } - - // Reinicializar help overlay con nuevo tamaño de fuente - if (help_overlay_) { - help_overlay_->reinitializeFontSize(current_font_size_); - } } - // Actualizar componentes de UI con nuevas dimensiones - notifier_->updateWindowSize(width, height); + // Actualizar help overlay con font size actual Y nuevas dimensiones (atómicamente) if (help_overlay_) { - help_overlay_->updatePhysicalWindowSize(width, height); + help_overlay_->updateAll(current_font_size_, width, height); } + + // Actualizar otros componentes de UI con nuevas dimensiones + notifier_->updateWindowSize(width, height); } void UIManager::setTextObsolete(const std::string& text, int pos, int current_screen_width) {