Varios arreglos a tot lo de definir botons dins del service menu i lo de triar mando
This commit is contained in:
@@ -36,33 +36,40 @@ void WindowMessage::render() {
|
||||
SDL_RenderRect(renderer, &rect_);
|
||||
|
||||
float current_y = rect_.y + config_.padding;
|
||||
float available_width = getAvailableTextWidth();
|
||||
|
||||
// Dibujar título si existe
|
||||
if (!title_.empty()) {
|
||||
std::string visible_title = getTruncatedText(title_, available_width);
|
||||
text_renderer_->writeStyle(
|
||||
rect_.x + rect_.w / 2.0f,
|
||||
current_y,
|
||||
title_,
|
||||
visible_title,
|
||||
title_style_);
|
||||
current_y += text_renderer_->getCharacterSize() + config_.title_separator_spacing;
|
||||
|
||||
// Línea separadora debajo del título
|
||||
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g,
|
||||
config_.border_color.b, config_.border_color.a);
|
||||
SDL_RenderLine(renderer,
|
||||
rect_.x + config_.padding,
|
||||
current_y - config_.title_separator_spacing / 2.0f,
|
||||
rect_.x + rect_.w - config_.padding,
|
||||
current_y - config_.title_separator_spacing / 2.0f);
|
||||
// Línea separadora debajo del título (solo si hay título visible)
|
||||
if (!visible_title.empty()) {
|
||||
SDL_SetRenderDrawColor(renderer, config_.border_color.r, config_.border_color.g,
|
||||
config_.border_color.b, config_.border_color.a);
|
||||
SDL_RenderLine(renderer,
|
||||
rect_.x + config_.padding,
|
||||
current_y - config_.title_separator_spacing / 2.0f,
|
||||
rect_.x + rect_.w - config_.padding,
|
||||
current_y - config_.title_separator_spacing / 2.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// Dibujar textos
|
||||
for (const auto& text : texts_) {
|
||||
text_renderer_->writeStyle(
|
||||
rect_.x + rect_.w / 2.0f,
|
||||
current_y,
|
||||
text,
|
||||
text_style_);
|
||||
std::string visible_text = getTruncatedText(text, available_width);
|
||||
if (!visible_text.empty()) {
|
||||
text_renderer_->writeStyle(
|
||||
rect_.x + rect_.w / 2.0f,
|
||||
current_y,
|
||||
visible_text,
|
||||
text_style_);
|
||||
}
|
||||
current_y += text_renderer_->getCharacterSize() + config_.line_spacing;
|
||||
}
|
||||
}
|
||||
@@ -284,4 +291,46 @@ void WindowMessage::updateAnimation(float delta_time) {
|
||||
auto WindowMessage::easeOut(float t) const -> float {
|
||||
// Función de suavizado ease-out cuadrática
|
||||
return 1.0f - (1.0f - t) * (1.0f - t);
|
||||
}
|
||||
|
||||
auto WindowMessage::getAvailableTextWidth() const -> float {
|
||||
// Ancho disponible = ancho total - padding en ambos lados
|
||||
return rect_.w - (config_.padding * 2.0f);
|
||||
}
|
||||
|
||||
auto WindowMessage::getTruncatedText(const std::string& text, float available_width) const -> std::string {
|
||||
if (text.empty()) {
|
||||
return text;
|
||||
}
|
||||
|
||||
// Si el texto completo cabe, devolverlo tal como está
|
||||
int text_width = text_renderer_->length(text, -2);
|
||||
if (text_width <= available_width) {
|
||||
return text;
|
||||
}
|
||||
|
||||
// Si no hay espacio suficiente, devolver string vacío
|
||||
if (available_width < 10.0f) { // Mínimo espacio para al menos un carácter
|
||||
return "";
|
||||
}
|
||||
|
||||
// Buscar cuántos caracteres caben usando búsqueda binaria
|
||||
int left = 0;
|
||||
int right = text.length();
|
||||
int best_length = 0;
|
||||
|
||||
while (left <= right) {
|
||||
int mid = (left + right) / 2;
|
||||
std::string partial = text.substr(0, mid);
|
||||
int partial_width = text_renderer_->length(partial, -2);
|
||||
|
||||
if (partial_width <= available_width) {
|
||||
best_length = mid;
|
||||
left = mid + 1;
|
||||
} else {
|
||||
right = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return text.substr(0, best_length);
|
||||
}
|
||||
Reference in New Issue
Block a user