clang-tidy modernize
This commit is contained in:
@@ -26,21 +26,21 @@ class MenuOption {
|
||||
|
||||
virtual ~MenuOption() = default;
|
||||
|
||||
const std::string &getCaption() const { return caption_; }
|
||||
ServiceMenu::SettingsGroup getGroup() const { return group_; }
|
||||
bool isHidden() const { return hidden_; }
|
||||
[[nodiscard]] auto getCaption() const -> const std::string & { return caption_; }
|
||||
[[nodiscard]] auto getGroup() const -> ServiceMenu::SettingsGroup { return group_; }
|
||||
[[nodiscard]] auto isHidden() const -> bool { return hidden_; }
|
||||
void setHidden(bool hidden) { hidden_ = hidden; }
|
||||
|
||||
virtual Behavior getBehavior() const = 0;
|
||||
virtual std::string getValueAsString() const { return ""; }
|
||||
[[nodiscard]] virtual auto getBehavior() const -> Behavior = 0;
|
||||
[[nodiscard]] virtual auto getValueAsString() const -> std::string { return ""; }
|
||||
virtual void adjustValue(bool adjust_up) {}
|
||||
virtual ServiceMenu::SettingsGroup getTargetGroup() const { return ServiceMenu::SettingsGroup::MAIN; }
|
||||
[[nodiscard]] virtual auto getTargetGroup() const -> ServiceMenu::SettingsGroup { return ServiceMenu::SettingsGroup::MAIN; }
|
||||
virtual void executeAction() {}
|
||||
|
||||
// Método virtual para que cada opción calcule el ancho de su valor más largo.
|
||||
virtual int getMaxValueWidth(Text *text_renderer) const { return 0; }
|
||||
virtual auto getMaxValueWidth(Text *text_renderer) const -> int { return 0; }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
std::string caption_;
|
||||
ServiceMenu::SettingsGroup group_;
|
||||
bool hidden_;
|
||||
@@ -53,14 +53,14 @@ class BoolOption : public MenuOption {
|
||||
BoolOption(const std::string &cap, ServiceMenu::SettingsGroup grp, bool *var)
|
||||
: MenuOption(cap, grp), linked_variable_(var) {}
|
||||
|
||||
Behavior getBehavior() const override { return Behavior::ADJUST; }
|
||||
std::string getValueAsString() const override {
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::ADJUST; }
|
||||
[[nodiscard]] auto getValueAsString() const -> std::string override {
|
||||
return *linked_variable_ ? Lang::getText("[SERVICE_MENU] ON") : Lang::getText("[SERVICE_MENU] OFF");
|
||||
}
|
||||
void adjustValue(bool /*adjust_up*/) override {
|
||||
*linked_variable_ = !*linked_variable_;
|
||||
}
|
||||
int getMaxValueWidth(Text *text_renderer) const override {
|
||||
auto getMaxValueWidth(Text *text_renderer) const -> int override {
|
||||
return std::max(
|
||||
text_renderer->lenght(Lang::getText("[SERVICE_MENU] ON"), -2),
|
||||
text_renderer->lenght(Lang::getText("[SERVICE_MENU] OFF"), -2));
|
||||
@@ -75,13 +75,13 @@ class IntOption : public MenuOption {
|
||||
IntOption(const std::string &cap, ServiceMenu::SettingsGroup grp, int *var, int min, int max, int step)
|
||||
: MenuOption(cap, grp), linked_variable_(var), min_value_(min), max_value_(max), step_value_(step) {}
|
||||
|
||||
Behavior getBehavior() const override { return Behavior::ADJUST; }
|
||||
std::string getValueAsString() const override { return std::to_string(*linked_variable_); }
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::ADJUST; }
|
||||
[[nodiscard]] auto getValueAsString() const -> std::string override { return std::to_string(*linked_variable_); }
|
||||
void adjustValue(bool adjust_up) override {
|
||||
int new_value = *linked_variable_ + (adjust_up ? step_value_ : -step_value_);
|
||||
*linked_variable_ = std::clamp(new_value, min_value_, max_value_);
|
||||
}
|
||||
int getMaxValueWidth(Text *text_renderer) const override {
|
||||
auto getMaxValueWidth(Text *text_renderer) const -> int override {
|
||||
int max_width = 0;
|
||||
|
||||
// Iterar por todos los valores posibles en el rango
|
||||
@@ -100,14 +100,13 @@ class IntOption : public MenuOption {
|
||||
|
||||
class ListOption : public MenuOption {
|
||||
public:
|
||||
ListOption(const std::string &cap, ServiceMenu::SettingsGroup grp, std::vector<std::string> values, std::function<std::string()> current_value_getter, std::function<void(const std::string &)> new_value_setter)
|
||||
: MenuOption(cap, grp),
|
||||
value_list_(std::move(values)),
|
||||
getter_(std::move(current_value_getter)),
|
||||
setter_(std::move(new_value_setter)),
|
||||
list_index_(0) {
|
||||
sync();
|
||||
}
|
||||
ListOption(const std::string &cap, ServiceMenu::SettingsGroup grp, std::vector<std::string> values, std::function<std::string()> current_value_getter, std::function<void(const std::string &)> new_value_setter)
|
||||
: MenuOption(cap, grp),
|
||||
value_list_(std::move(values)),
|
||||
getter_(std::move(current_value_getter)),
|
||||
setter_(std::move(new_value_setter)) {
|
||||
sync();
|
||||
}
|
||||
|
||||
void sync() {
|
||||
std::string current_value = getter_();
|
||||
@@ -119,8 +118,8 @@ class ListOption : public MenuOption {
|
||||
}
|
||||
}
|
||||
|
||||
Behavior getBehavior() const override { return Behavior::ADJUST; }
|
||||
std::string getValueAsString() const override {
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::ADJUST; }
|
||||
[[nodiscard]] auto getValueAsString() const -> std::string override {
|
||||
return value_list_.empty() ? "" : value_list_[list_index_];
|
||||
}
|
||||
void adjustValue(bool adjust_up) override {
|
||||
@@ -131,7 +130,7 @@ class ListOption : public MenuOption {
|
||||
: (list_index_ + size - 1) % size;
|
||||
setter_(value_list_[list_index_]);
|
||||
}
|
||||
int getMaxValueWidth(Text *text_renderer) const override {
|
||||
auto getMaxValueWidth(Text *text_renderer) const -> int override {
|
||||
int max_w = 0;
|
||||
for (const auto &val : value_list_) {
|
||||
max_w = std::max(max_w, text_renderer->lenght(val, -2));
|
||||
@@ -143,7 +142,7 @@ class ListOption : public MenuOption {
|
||||
std::vector<std::string> value_list_;
|
||||
std::function<std::string()> getter_;
|
||||
std::function<void(const std::string &)> setter_;
|
||||
size_t list_index_;
|
||||
size_t list_index_{0};
|
||||
};
|
||||
|
||||
class FolderOption : public MenuOption {
|
||||
@@ -151,10 +150,10 @@ class FolderOption : public MenuOption {
|
||||
FolderOption(const std::string &cap, ServiceMenu::SettingsGroup grp, ServiceMenu::SettingsGroup target)
|
||||
: MenuOption(cap, grp), target_group_(target) {}
|
||||
|
||||
Behavior getBehavior() const override { return Behavior::SELECT; }
|
||||
ServiceMenu::SettingsGroup getTargetGroup() const override { return target_group_; }
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::SELECT; }
|
||||
[[nodiscard]] auto getTargetGroup() const -> ServiceMenu::SettingsGroup override { return target_group_; }
|
||||
|
||||
private:
|
||||
private:
|
||||
ServiceMenu::SettingsGroup target_group_;
|
||||
};
|
||||
|
||||
@@ -163,7 +162,7 @@ class ActionOption : public MenuOption {
|
||||
ActionOption(const std::string &cap, ServiceMenu::SettingsGroup grp, std::function<void()> action, bool hidden = false)
|
||||
: MenuOption(cap, grp, hidden), action_(std::move(action)) {}
|
||||
|
||||
Behavior getBehavior() const override { return Behavior::SELECT; }
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::SELECT; }
|
||||
void executeAction() override {
|
||||
if (action_)
|
||||
action_();
|
||||
|
||||
@@ -100,7 +100,7 @@ void MenuRenderer::setAnchors(const ServiceMenu *menu_state) {
|
||||
height_ = upper_height_ + lower_height_;
|
||||
}
|
||||
|
||||
SDL_FRect MenuRenderer::calculateNewRect(const ServiceMenu *menu_state) {
|
||||
auto MenuRenderer::calculateNewRect(const ServiceMenu *menu_state) -> SDL_FRect {
|
||||
width_ = getMenuWidthForGroup(menu_state->getCurrentGroup());
|
||||
const auto &display_options = menu_state->getDisplayOptions();
|
||||
lower_height_ = ((display_options.size() > 0 ? display_options.size() - 1 : 0) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||
@@ -172,7 +172,7 @@ void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<Menu
|
||||
}
|
||||
}
|
||||
|
||||
int MenuRenderer::getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const {
|
||||
auto MenuRenderer::getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const -> int {
|
||||
return group_menu_widths_[static_cast<int>(group)];
|
||||
}
|
||||
|
||||
@@ -185,12 +185,12 @@ void MenuRenderer::updateColorCounter() {
|
||||
}
|
||||
}
|
||||
|
||||
Color MenuRenderer::getAnimatedSelectedColor() {
|
||||
auto MenuRenderer::getAnimatedSelectedColor() -> Color {
|
||||
static auto color_cycle_ = generateMirroredCycle(param.service_menu.selected_color, ColorCycleStyle::HUE_WAVE);
|
||||
return color_cycle_.at(color_counter_ % color_cycle_.size());
|
||||
}
|
||||
|
||||
SDL_FRect MenuRenderer::setRect(SDL_FRect rect) {
|
||||
auto MenuRenderer::setRect(SDL_FRect rect) -> SDL_FRect {
|
||||
border_rect_ = {rect.x - 1, rect.y + 1, rect.w + 2, rect.h - 2};
|
||||
return rect;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_FRect, Uint32
|
||||
#include <stddef.h> // Para size_t
|
||||
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <vector> // Para vector
|
||||
#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
|
||||
@@ -26,9 +26,9 @@ class MenuRenderer {
|
||||
void setLayout(const ServiceMenu *menu_state);
|
||||
|
||||
// Getters
|
||||
const SDL_FRect &getRect() const { return rect_; }
|
||||
[[nodiscard]] auto getRect() const -> const SDL_FRect & { return rect_; }
|
||||
|
||||
private:
|
||||
private:
|
||||
// --- Referencias a los renderizadores de texto ---
|
||||
std::shared_ptr<Text> element_text_;
|
||||
std::shared_ptr<Text> title_text_;
|
||||
@@ -60,13 +60,13 @@ class MenuRenderer {
|
||||
|
||||
// --- Métodos privados de la vista ---
|
||||
void setAnchors(const ServiceMenu *menu_state);
|
||||
SDL_FRect calculateNewRect(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);
|
||||
int getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const;
|
||||
Color getAnimatedSelectedColor();
|
||||
[[nodiscard]] auto getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const -> int;
|
||||
auto getAnimatedSelectedColor() -> Color;
|
||||
void updateColorCounter();
|
||||
SDL_FRect setRect(SDL_FRect rect);
|
||||
auto setRect(SDL_FRect rect) -> SDL_FRect;
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
ServiceMenu *ServiceMenu::instance = nullptr;
|
||||
void ServiceMenu::init() { ServiceMenu::instance = new ServiceMenu(); }
|
||||
void ServiceMenu::destroy() { delete ServiceMenu::instance; }
|
||||
ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance; }
|
||||
auto ServiceMenu::get() -> ServiceMenu * { return ServiceMenu::instance; }
|
||||
|
||||
// Constructor
|
||||
ServiceMenu::ServiceMenu()
|
||||
@@ -106,7 +106,13 @@ void ServiceMenu::selectOption() {
|
||||
return;
|
||||
if (current_settings_group_ == SettingsGroup::MAIN)
|
||||
main_menu_selected_ = selected_;
|
||||
auto &selected_option = display_options_.at(selected_);
|
||||
|
||||
auto *selected_option = display_options_.at(selected_);
|
||||
if (!selected_option) {
|
||||
// This shouldn't happen in normal operation, but protects against null pointer
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto folder = dynamic_cast<FolderOption *>(selected_option)) {
|
||||
previous_settings_group_ = current_settings_group_;
|
||||
current_settings_group_ = folder->getTargetGroup();
|
||||
@@ -184,7 +190,7 @@ void ServiceMenu::applySettingsSettings() {
|
||||
setHiddenOptions();
|
||||
}
|
||||
|
||||
MenuOption *ServiceMenu::getOptionByCaption(const std::string &caption) const {
|
||||
auto ServiceMenu::getOptionByCaption(const std::string &caption) const -> MenuOption * {
|
||||
for (const auto &option : options_) {
|
||||
if (option->getCaption() == caption) {
|
||||
return option.get();
|
||||
@@ -195,7 +201,7 @@ MenuOption *ServiceMenu::getOptionByCaption(const std::string &caption) const {
|
||||
|
||||
// --- Getters y otros ---
|
||||
|
||||
ServiceMenu::GroupAlignment ServiceMenu::getCurrentGroupAlignment() const {
|
||||
auto ServiceMenu::getCurrentGroupAlignment() const -> ServiceMenu::GroupAlignment {
|
||||
switch (current_settings_group_) {
|
||||
case SettingsGroup::VIDEO:
|
||||
case SettingsGroup::AUDIO:
|
||||
@@ -206,7 +212,7 @@ ServiceMenu::GroupAlignment ServiceMenu::getCurrentGroupAlignment() const {
|
||||
}
|
||||
}
|
||||
|
||||
size_t ServiceMenu::countOptionsInGroup(SettingsGroup group) const {
|
||||
auto ServiceMenu::countOptionsInGroup(SettingsGroup group) const -> size_t {
|
||||
size_t count = 0;
|
||||
for (const auto &option : options_) {
|
||||
if (option->getGroup() == group && !option->isHidden()) {
|
||||
@@ -269,7 +275,7 @@ void ServiceMenu::playSelectSound() { Audio::get()->playSound("service_menu_sele
|
||||
void ServiceMenu::playBackSound() { Audio::get()->playSound("service_menu_select.wav", Audio::Group::INTERFACE); }
|
||||
|
||||
// Devuelve el nombre del grupo como string para el título
|
||||
std::string ServiceMenu::settingsGroupToString(SettingsGroup group) const {
|
||||
auto ServiceMenu::settingsGroupToString(SettingsGroup group) const -> std::string {
|
||||
switch (group) {
|
||||
case SettingsGroup::MAIN:
|
||||
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h> // Para size_t
|
||||
|
||||
#include <cstddef> // Para size_t
|
||||
#include <memory> // Para unique_ptr
|
||||
#include <string> // Para basic_string, string
|
||||
#include <utility> // Para pair
|
||||
@@ -34,7 +33,7 @@ class ServiceMenu {
|
||||
|
||||
static void init();
|
||||
static void destroy();
|
||||
static ServiceMenu *get();
|
||||
static auto get() -> ServiceMenu *;
|
||||
|
||||
void toggle();
|
||||
void render();
|
||||
@@ -49,17 +48,17 @@ class ServiceMenu {
|
||||
void moveBack();
|
||||
|
||||
// --- Getters para que el Renderer pueda leer el estado ---
|
||||
bool isEnabled() const { return enabled_; }
|
||||
const std::string &getTitle() const { return title_; }
|
||||
SettingsGroup getCurrentGroup() const { return current_settings_group_; }
|
||||
GroupAlignment getCurrentGroupAlignment() const;
|
||||
const std::vector<MenuOption *> &getDisplayOptions() const { return display_options_; }
|
||||
const std::vector<std::unique_ptr<MenuOption>> &getAllOptions() const { return options_; }
|
||||
size_t getSelectedIndex() const { return selected_; }
|
||||
const std::vector<std::pair<std::string, std::string>> &getOptionPairs() const { return option_pairs_; }
|
||||
size_t countOptionsInGroup(SettingsGroup group) const;
|
||||
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
|
||||
[[nodiscard]] auto getTitle() const -> const std::string & { return title_; }
|
||||
[[nodiscard]] auto getCurrentGroup() const -> SettingsGroup { return current_settings_group_; }
|
||||
[[nodiscard]] auto getCurrentGroupAlignment() const -> GroupAlignment;
|
||||
[[nodiscard]] auto getDisplayOptions() const -> const std::vector<MenuOption *> & { return display_options_; }
|
||||
[[nodiscard]] auto getAllOptions() const -> const std::vector<std::unique_ptr<MenuOption>> & { return options_; }
|
||||
[[nodiscard]] auto getSelectedIndex() const -> size_t { return selected_; }
|
||||
[[nodiscard]] auto getOptionPairs() const -> const std::vector<std::pair<std::string, std::string>> & { return option_pairs_; }
|
||||
[[nodiscard]] auto countOptionsInGroup(SettingsGroup group) const -> size_t;
|
||||
|
||||
private:
|
||||
private:
|
||||
// --- Lógica de estado del menú (Modelo) ---
|
||||
bool enabled_ = false;
|
||||
std::vector<std::unique_ptr<MenuOption>> options_;
|
||||
@@ -88,19 +87,19 @@ class ServiceMenu {
|
||||
void applyVideoSettings();
|
||||
void applyAudioSettings();
|
||||
void applySettingsSettings();
|
||||
MenuOption *getOptionByCaption(const std::string &caption) const;
|
||||
[[nodiscard]] auto getOptionByCaption(const std::string &caption) const -> MenuOption *;
|
||||
void adjustListValues();
|
||||
void playMoveSound();
|
||||
void playAdjustSound();
|
||||
void playSelectSound();
|
||||
void playBackSound();
|
||||
std::string settingsGroupToString(SettingsGroup group) const;
|
||||
[[nodiscard]] auto settingsGroupToString(SettingsGroup group) const -> std::string;
|
||||
void setHiddenOptions();
|
||||
|
||||
// --- Singleton ---
|
||||
ServiceMenu();
|
||||
~ServiceMenu() = default;
|
||||
ServiceMenu(const ServiceMenu &) = delete;
|
||||
ServiceMenu &operator=(const ServiceMenu &) = delete;
|
||||
auto operator=(const ServiceMenu &) -> ServiceMenu & = delete;
|
||||
static ServiceMenu *instance;
|
||||
};
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "ui_message.h"
|
||||
|
||||
#include <cmath> // Para pow
|
||||
#include <utility>
|
||||
|
||||
#include "text.h" // Para TEXT_CENTER, TEXT_COLOR, Text
|
||||
|
||||
// Constructor: inicializa el renderizador, el texto y el color del mensaje
|
||||
UIMessage::UIMessage(std::shared_ptr<Text> text_renderer, const std::string &message_text, const Color &color)
|
||||
: text_renderer_(text_renderer), text_(message_text), color_(color) {}
|
||||
UIMessage::UIMessage(std::shared_ptr<Text> text_renderer, std::string message_text, const Color &color)
|
||||
: text_renderer_(std::move(text_renderer)), text_(std::move(message_text)), color_(color) {}
|
||||
|
||||
// Muestra el mensaje en la posición base_x, base_y con animación de entrada desde arriba
|
||||
void UIMessage::show() {
|
||||
@@ -76,7 +77,7 @@ void UIMessage::render() {
|
||||
}
|
||||
|
||||
// Devuelve true si el mensaje está visible actualmente
|
||||
bool UIMessage::isVisible() const {
|
||||
auto UIMessage::isVisible() const -> bool {
|
||||
return visible_;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,25 +11,25 @@ class Text;
|
||||
class UIMessage {
|
||||
public:
|
||||
// Constructor: recibe el renderizador de texto, el mensaje y el color
|
||||
UIMessage(std::shared_ptr<Text> text_renderer, const std::string &message_text, const Color &color);
|
||||
UIMessage(std::shared_ptr<Text> text_renderer, std::string message_text, const Color &color);
|
||||
|
||||
// Muestra el mensaje con animación de entrada
|
||||
void show();
|
||||
// Muestra el mensaje con animación de entrada
|
||||
void show();
|
||||
|
||||
// Oculta el mensaje con animación de salida
|
||||
void hide();
|
||||
// Oculta el mensaje con animación de salida
|
||||
void hide();
|
||||
|
||||
// Actualiza el estado de la animación (debe llamarse cada frame)
|
||||
void update();
|
||||
// Actualiza el estado de la animación (debe llamarse cada frame)
|
||||
void update();
|
||||
|
||||
// Dibuja el mensaje en pantalla si está visible
|
||||
void render();
|
||||
// Dibuja el mensaje en pantalla si está visible
|
||||
void render();
|
||||
|
||||
// Indica si el mensaje está visible actualmente
|
||||
bool isVisible() const;
|
||||
// Indica si el mensaje está visible actualmente
|
||||
[[nodiscard]] auto isVisible() const -> bool;
|
||||
|
||||
// Permite actualizar la posición del mensaje (por ejemplo, si el menú se mueve)
|
||||
void setPosition(float new_base_x, float new_base_y);
|
||||
// Permite actualizar la posición del mensaje (por ejemplo, si el menú se mueve)
|
||||
void setPosition(float new_base_x, float new_base_y);
|
||||
|
||||
private:
|
||||
// --- Configuración ---
|
||||
|
||||
Reference in New Issue
Block a user