diff --git a/source/ui/help_overlay.cpp b/source/ui/help_overlay.cpp index 7ad22cd..732f6e5 100644 --- a/source/ui/help_overlay.cpp +++ b/source/ui/help_overlay.cpp @@ -16,6 +16,8 @@ HelpOverlay::HelpOverlay() box_height_(0), box_x_(0), box_y_(0), + column1_width_(0), + column2_width_(0), cached_texture_(nullptr), last_category_color_({0, 0, 0, 255}), last_content_color_({0, 0, 0, 255}), @@ -112,8 +114,9 @@ void HelpOverlay::reinitializeFontSize(int new_font_size) { // Reinicializar text renderer con nuevo tamaño text_renderer_->reinitialize(new_font_size); - // Recalcular dimensiones del box (el texto ahora tiene distinto tamaño) - calculateBoxDimensions(); + // NOTA: NO recalcular dimensiones aquí porque physical_width_ y physical_height_ + // pueden tener valores antiguos. updatePhysicalWindowSize() se llamará después + // con las dimensiones correctas y recalculará todo apropiadamente. // Marcar textura para regeneración completa texture_needs_rebuild_ = true; @@ -141,15 +144,22 @@ void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) { continue; } - // Separador vacío o encabezado - if (binding.description[0] == '\0') { + // Separador vacío (no tiene key ni description) + if (binding.key[0] == '\0') { continue; } - // Calcular ancho de esta línea: key + espacio + description - int key_width = text_renderer_->getTextWidthPhysical(binding.key); - int desc_width = text_renderer_->getTextWidthPhysical(binding.description); - int line_width = key_width + 10 + desc_width; // 10px de separación + int line_width = 0; + + if (binding.description[0] == '\0') { + // Es un encabezado (solo tiene key, sin description) + line_width = text_renderer_->getTextWidthPhysical(binding.key); + } else { + // Es una línea normal con key + description + int key_width = text_renderer_->getTextWidthPhysical(binding.key); + int desc_width = text_renderer_->getTextWidthPhysical(binding.description); + line_width = key_width + 10 + desc_width; // 10px de separación + } // Actualizar máximo de columna correspondiente if (current_column == 0) { @@ -159,6 +169,10 @@ void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) { } } + // Almacenar anchos de columnas en miembros para uso posterior + column1_width_ = max_col1_width; + column2_width_ = max_col2_width; + // Ancho total: 2 columnas + 3 paddings (izq, medio, der) max_width = max_col1_width + max_col2_width + padding * 3; @@ -178,12 +192,8 @@ void HelpOverlay::calculateBoxDimensions() { int text_width, text_height; calculateTextDimensions(text_width, text_height); - // Ancho mínimo: 90% de dimensión menor (como antes, para compatibilidad) - int min_dimension = std::min(physical_width_, physical_height_); - int min_width = static_cast(min_dimension * 0.9f); - - // Usar el mayor entre ancho calculado y ancho mínimo - box_width_ = std::max(text_width, min_width); + // Usar directamente el ancho y altura calculados según el contenido + box_width_ = text_width; // Altura: 90% de altura física o altura calculada, el que sea menor int max_height = static_cast(physical_height_ * 0.9f); @@ -279,10 +289,9 @@ void HelpOverlay::rebuildCachedTexture() { last_content_color_ = content_color; last_bg_color_ = {static_cast(notif_bg_r), static_cast(notif_bg_g), static_cast(notif_bg_b), 255}; - // Configuración de espaciado (misma que renderHelpText()) + // Configuración de espaciado int line_height = text_renderer_->getTextHeight(); int padding = 25; - int column_width = (box_width_ - padding * 3) / 2; int current_x = padding; // Coordenadas relativas a la textura (0,0) int current_y = padding; @@ -301,7 +310,7 @@ void HelpOverlay::rebuildCachedTexture() { if (strcmp(binding.key, "[new_col]") == 0 && binding.description[0] == '\0') { if (current_column == 0) { current_column = 1; - current_x = padding + column_width + padding; + current_x = padding + column1_width_ + padding; // Usar ancho real de columna 1 current_y = content_start_y; } continue; @@ -321,7 +330,7 @@ void HelpOverlay::rebuildCachedTexture() { if (current_y > box_height_ - padding && current_column == 0) { current_column = 1; - current_x = padding + column_width + padding; + current_x = padding + column1_width_ + padding; // Usar ancho real de columna 1 current_y = content_start_y; } } diff --git a/source/ui/help_overlay.h b/source/ui/help_overlay.h index 269ff9f..ad0fd8c 100644 --- a/source/ui/help_overlay.h +++ b/source/ui/help_overlay.h @@ -65,6 +65,10 @@ class HelpOverlay { int box_x_; int box_y_; + // Anchos individuales de cada columna (para evitar solapamiento) + int column1_width_; + int column2_width_; + // Sistema de caché para optimización de rendimiento SDL_Texture* cached_texture_; // Textura cacheada del overlay completo SDL_Color last_category_color_; // Último color de categorías renderizado