70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <SDL3/SDL.h>
|
|
#include "ui/service_menu.h" // Necesario para las enums y para acceder al estado del menú
|
|
#include "utils.h" // Para Color
|
|
|
|
// Forward declarations
|
|
class Text;
|
|
class MenuOption;
|
|
|
|
class MenuRenderer {
|
|
public:
|
|
MenuRenderer(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);
|
|
|
|
// Getters
|
|
const SDL_FRect& getRect() const { 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_{};
|
|
Color bg_color_ = SERV_MENU_BG_COLOR;
|
|
Color title_color_ = SERV_MENU_TITLE_COLOR;
|
|
Color text_color_ = SERV_MENU_TEXT_COLOR;
|
|
Color selected_color_ = SERV_MENU_SELECTED_COLOR;
|
|
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 ---
|
|
int group_menu_widths_[5]{};
|
|
|
|
// --- Métodos privados de la vista ---
|
|
void setAnchors(const ServiceMenu* menu_state);
|
|
void resize(const ServiceMenu* menu_state);
|
|
void updateResizeAnimation();
|
|
void precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>>& all_options, const ServiceMenu* menu_state);
|
|
int getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const;
|
|
Color getAnimatedSelectedColor();
|
|
void updateColorCounter();
|
|
};
|