74 lines
2.6 KiB
C++
74 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h> // Para SDL_FRect, Uint32
|
|
|
|
#include <array>
|
|
#include <cstddef> // Para size_t
|
|
#include <memory> // Para shared_ptr, unique_ptr
|
|
#include <vector> // Para vector
|
|
|
|
#include "ui/service_menu.h" // Para ServiceMenu
|
|
#include "utils.h" // Para Color
|
|
|
|
class MenuOption;
|
|
// Forward declarations
|
|
class Text;
|
|
|
|
class MenuRenderer {
|
|
public:
|
|
MenuRenderer(const ServiceMenu *menu_state, std::shared_ptr<Text> element_text, std::shared_ptr<Text> title_text);
|
|
|
|
// Métodos principales de la vista
|
|
void render(const ServiceMenu *menu_state);
|
|
void update(const ServiceMenu *menu_state);
|
|
|
|
// Método para notificar al renderer que el layout puede haber cambiado
|
|
void onLayoutChanged(const ServiceMenu *menu_state);
|
|
void setLayout(const ServiceMenu *menu_state);
|
|
|
|
// Getters
|
|
[[nodiscard]] auto getRect() const -> const SDL_FRect & { return rect_; }
|
|
|
|
private:
|
|
// --- Referencias a los renderizadores de texto ---
|
|
std::shared_ptr<Text> element_text_;
|
|
std::shared_ptr<Text> title_text_;
|
|
|
|
// --- Variables de estado de la vista (layout y animación) ---
|
|
SDL_FRect rect_{};
|
|
SDL_FRect border_rect_{};
|
|
size_t width_ = 0;
|
|
size_t height_ = 0;
|
|
size_t options_height_ = 0;
|
|
size_t options_padding_ = 0;
|
|
size_t options_y_ = 0;
|
|
size_t title_height_ = 0;
|
|
size_t title_padding_ = 0;
|
|
size_t upper_height_ = 0;
|
|
size_t lower_height_ = 0;
|
|
size_t lower_padding_ = 0;
|
|
Uint32 color_counter_ = 0;
|
|
|
|
// --- Variables para animación de resize ---
|
|
SDL_FRect rect_anim_from_{};
|
|
SDL_FRect rect_anim_to_{};
|
|
int resize_anim_step_ = 0;
|
|
int resize_anim_steps_ = 8;
|
|
bool resizing_ = false;
|
|
|
|
// --- Anchos precalculados ---
|
|
std::array<int, 5> group_menu_widths_ = {};
|
|
|
|
// --- Métodos privados de la vista ---
|
|
void setAnchors(const ServiceMenu *menu_state);
|
|
auto calculateNewRect(const ServiceMenu *menu_state) -> SDL_FRect;
|
|
void resize(const ServiceMenu *menu_state);
|
|
void setSize(const ServiceMenu *menu_state);
|
|
void updateResizeAnimation();
|
|
void precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>> &all_options, const ServiceMenu *menu_state);
|
|
[[nodiscard]] auto getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const -> int;
|
|
auto getAnimatedSelectedColor() const -> Color;
|
|
void updateColorCounter();
|
|
auto setRect(SDL_FRect rect) -> SDL_FRect;
|
|
};
|