fix: Help Overlay - corregir solapamiento de columnas y layout

Tres correcciones importantes para el Help Overlay:

1. Solapamiento de columnas corregido:
   - Añadidos column1_width_ y column2_width_ para anchos reales
   - calculateTextDimensions() ahora incluye encabezados en cálculo
   - rebuildCachedTexture() usa anchos reales de columnas
   - Columna 2 empieza en padding + column1_width_ + padding
   - Elimina cálculo erróneo column_width = (box_width_ - padding*3)/2

2. Layout en alta resolución corregido:
   - Eliminado ancho mínimo forzado del 90% de dimensión menor
   - box_width_ ahora usa directamente text_width (justo lo necesario)
   - Antes: 1920x1080 → min 972px aunque contenido necesite 600px
   - Ahora: box ajustado al contenido sin espacio vacío extra

3. Fullscreen/resize corregido:
   - reinitializeFontSize() ya NO llama a calculateBoxDimensions()
   - Evita recalcular con physical_width_ y physical_height_ antiguos
   - Confía en updatePhysicalWindowSize() que se llama después
   - Antes: textura cacheada creada con dimensiones incorrectas
   - Ahora: textura siempre creada con dimensiones correctas

Resultado:
- Columnas no se montan entre sí
- Box ajustado al contenido sin espacio vacío derecha
- Cambios fullscreen/ventana funcionan correctamente
- Overlay se recalcula apropiadamente en todos los casos

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-16 21:22:12 +02:00
parent 250b1a640d
commit 7c0a60f140
2 changed files with 31 additions and 18 deletions

View File

@@ -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<int>(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<int>(physical_height_ * 0.9f);
@@ -279,10 +289,9 @@ void HelpOverlay::rebuildCachedTexture() {
last_content_color_ = content_color;
last_bg_color_ = {static_cast<Uint8>(notif_bg_r), static_cast<Uint8>(notif_bg_g), static_cast<Uint8>(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;
}
}

View File

@@ -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