window_message: animació d'entrada i eixida de la finestra
This commit is contained in:
@@ -37,6 +37,9 @@ class WindowMessage {
|
||||
// Margen de seguridad para texto
|
||||
float text_safety_margin; // Margen extra para evitar texto cortado
|
||||
|
||||
// Animaciones
|
||||
float animation_duration; // Duración en segundos para todas las animaciones
|
||||
|
||||
// Constructor con valores por defecto
|
||||
Config()
|
||||
: bg_color{40, 40, 60, 220}
|
||||
@@ -51,6 +54,7 @@ class WindowMessage {
|
||||
, max_width_ratio{0.8f}
|
||||
, max_height_ratio{0.8f}
|
||||
, text_safety_margin{20.0f}
|
||||
, animation_duration{0.3f}
|
||||
{}
|
||||
};
|
||||
|
||||
@@ -68,6 +72,8 @@ class WindowMessage {
|
||||
void show();
|
||||
void hide();
|
||||
[[nodiscard]] auto isVisible() const -> bool { return visible_; }
|
||||
[[nodiscard]] auto isFullyVisible() const -> bool { return visible_ && !show_hide_animation_.active; }
|
||||
[[nodiscard]] auto isAnimating() const -> bool { return resize_animation_.active || show_hide_animation_.active; }
|
||||
|
||||
// Configuración de contenido
|
||||
void setTitle(const std::string& title);
|
||||
@@ -128,7 +134,6 @@ class WindowMessage {
|
||||
bool active = false;
|
||||
float start_width, start_height;
|
||||
float target_width, target_height;
|
||||
float duration = 0.3f; // segundos
|
||||
float elapsed = 0.0f;
|
||||
|
||||
void start(float from_w, float from_h, float to_w, float to_h) {
|
||||
@@ -145,15 +150,53 @@ class WindowMessage {
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto isFinished() const -> bool {
|
||||
[[nodiscard]] auto isFinished(float duration) const -> bool {
|
||||
return elapsed >= duration;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto getProgress() const -> float {
|
||||
[[nodiscard]] auto getProgress(float duration) const -> float {
|
||||
return std::min(elapsed / duration, 1.0f);
|
||||
}
|
||||
} resize_animation_;
|
||||
|
||||
// Animación de mostrar/ocultar
|
||||
struct ShowHideAnimation {
|
||||
enum class Type { NONE, SHOWING, HIDING };
|
||||
|
||||
Type type = Type::NONE;
|
||||
bool active = false;
|
||||
float target_width, target_height; // Tamaño final al mostrar
|
||||
float elapsed = 0.0f;
|
||||
|
||||
void startShow(float to_w, float to_h) {
|
||||
type = Type::SHOWING;
|
||||
target_width = to_w;
|
||||
target_height = to_h;
|
||||
elapsed = 0.0f;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void startHide() {
|
||||
type = Type::HIDING;
|
||||
elapsed = 0.0f;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
type = Type::NONE;
|
||||
active = false;
|
||||
elapsed = 0.0f;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto isFinished(float duration) const -> bool {
|
||||
return elapsed >= duration;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto getProgress(float duration) const -> float {
|
||||
return std::min(elapsed / duration, 1.0f);
|
||||
}
|
||||
} show_hide_animation_;
|
||||
|
||||
// Estilos
|
||||
Text::Style title_style_;
|
||||
Text::Style text_style_;
|
||||
@@ -165,6 +208,8 @@ class WindowMessage {
|
||||
void ensureTextFits(); // Verifica y ajusta para que todo el texto sea visible
|
||||
void triggerAutoResize(); // Inicia redimensionado automático si está habilitado
|
||||
void updateAnimation(float delta_time); // Actualiza la animación de redimensionado
|
||||
void updateShowHideAnimation(float delta_time); // Actualiza la animación de mostrar/ocultar
|
||||
void updateResizeAnimation(float delta_time); // Actualiza la animación de redimensionado
|
||||
|
||||
// Función de suavizado (ease-out)
|
||||
[[nodiscard]] auto easeOut(float t) const -> float;
|
||||
@@ -172,6 +217,7 @@ class WindowMessage {
|
||||
// Métodos para manejo de texto durante animación
|
||||
[[nodiscard]] auto getTruncatedText(const std::string& text, float available_width) const -> std::string;
|
||||
[[nodiscard]] auto getAvailableTextWidth() const -> float;
|
||||
[[nodiscard]] auto shouldShowContent() const -> bool; // Si mostrar el contenido (texto, líneas, etc.)
|
||||
|
||||
[[nodiscard]] auto calculateContentHeight() const -> float;
|
||||
[[nodiscard]] auto calculateContentWidth() const -> float;
|
||||
|
||||
Reference in New Issue
Block a user