Pasaeta de linters

This commit is contained in:
2025-08-06 13:05:04 +02:00
parent 8ed2dbcd4f
commit 1224af2a9b
40 changed files with 623 additions and 592 deletions

View File

@@ -51,21 +51,21 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) {
// Para opciones alineadas a la izquierda, truncamos el valor si es necesario
const int available_width = rect_.w - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2) -
element_text_->lenght(option_pairs.at(i).first, -2) -
ServiceMenu::MIN_GAP_OPTION_VALUE;
const std::string truncated_value = getTruncatedValue(option_pairs.at(i).second, available_width);
const int AVAILABLE_WIDTH = rect_.w - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2) -
element_text_->lenght(option_pairs.at(i).first, -2) -
ServiceMenu::MIN_GAP_OPTION_VALUE;
const std::string TRUNCATED_VALUE = getTruncatedValue(option_pairs.at(i).second, AVAILABLE_WIDTH);
element_text_->writeColored(rect_.x + ServiceMenu::OPTIONS_HORIZONTAL_PADDING, y, option_pairs.at(i).first, current_color, -2);
const int X = rect_.x + rect_.w - ServiceMenu::OPTIONS_HORIZONTAL_PADDING - element_text_->lenght(truncated_value, -2);
element_text_->writeColored(X, y, truncated_value, current_color, -2);
const int X = rect_.x + rect_.w - ServiceMenu::OPTIONS_HORIZONTAL_PADDING - element_text_->lenght(TRUNCATED_VALUE, -2);
element_text_->writeColored(X, y, TRUNCATED_VALUE, current_color, -2);
} else {
// Para opciones centradas, también truncamos si es necesario
const int available_width = rect_.w - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2);
const std::string truncated_caption = getTruncatedValue(option_pairs.at(i).first, available_width);
element_text_->writeDX(TEXT_CENTER | TEXT_COLOR, rect_.x + rect_.w / 2, y, truncated_caption, -2, current_color);
const int AVAILABLE_WIDTH = rect_.w - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2);
const std::string TRUNCATED_CAPTION = getTruncatedValue(option_pairs.at(i).first, AVAILABLE_WIDTH);
element_text_->writeDX(TEXT_CENTER | TEXT_COLOR, rect_.x + rect_.w / 2, y, TRUNCATED_CAPTION, -2, current_color);
}
y += options_height_ + options_padding_;
}
@@ -96,8 +96,8 @@ void MenuRenderer::setLayout(const ServiceMenu *menu_state) {
void MenuRenderer::initializeMaxSizes() {
// Establecemos los límites máximos basados en el tamaño de la pantalla
// Dejamos un margen del 10% en cada lado para que el menú no ocupe toda la pantalla
max_menu_width_ = static_cast<size_t>(param.game.game_area.rect.w * 0.9f);
max_menu_height_ = static_cast<size_t>(param.game.game_area.rect.h * 0.9f);
max_menu_width_ = static_cast<size_t>(param.game.game_area.rect.w * 0.9F);
max_menu_height_ = static_cast<size_t>(param.game.game_area.rect.h * 0.9F);
}
void MenuRenderer::setAnchors(const ServiceMenu *menu_state) {
@@ -123,7 +123,7 @@ void MenuRenderer::setAnchors(const ServiceMenu *menu_state) {
auto MenuRenderer::calculateNewRect(const ServiceMenu *menu_state) -> SDL_FRect {
width_ = std::min(static_cast<size_t>(getMenuWidthForGroup(menu_state->getCurrentGroup())), max_menu_width_);
const auto &display_options = menu_state->getDisplayOptions();
lower_height_ = ((!display_options.empty() ? display_options.size() - 1 : 0) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
height_ = std::min(upper_height_ + lower_height_, max_menu_height_);
@@ -187,10 +187,10 @@ void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<Menu
max_option_width = std::max(max_option_width, element_text_->lenght(option->getCaption(), -2));
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) {
// Para calcular el ancho máximo, necesitamos considerar la truncación
int max_available_value_width = static_cast<int>(max_menu_width_) - max_option_width -
(ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2) -
ServiceMenu::MIN_GAP_OPTION_VALUE;
int max_available_value_width = static_cast<int>(max_menu_width_) - max_option_width -
(ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2) -
ServiceMenu::MIN_GAP_OPTION_VALUE;
int actual_value_width = getTruncatedValueWidth(option->getValueAsString(), max_available_value_width);
max_value_width = std::max(max_value_width, actual_value_width);
}
@@ -199,8 +199,8 @@ void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<Menu
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) {
total_width += ServiceMenu::MIN_GAP_OPTION_VALUE + max_value_width;
}
group_menu_widths_[group] = std::min(std::max((int)ServiceMenu::MIN_WIDTH, (int)total_width),
static_cast<int>(max_menu_width_));
group_menu_widths_[group] = std::min(std::max((int)ServiceMenu::MIN_WIDTH, (int)total_width),
static_cast<int>(max_menu_width_));
}
}
@@ -232,20 +232,20 @@ auto MenuRenderer::getTruncatedValueWidth(const std::string &value, int availabl
if (value_width <= available_width) {
return value_width;
}
// Calculamos cuántos caracteres podemos mostrar más los puntos suspensivos
// Estimamos el ancho de los puntos suspensivos como 3 caracteres promedio
int ellipsis_width = element_text_->lenght("...", -2);
int available_for_text = available_width - ellipsis_width;
if (available_for_text <= 0) {
return ellipsis_width; // Solo mostramos los puntos suspensivos
return ellipsis_width; // Solo mostramos los puntos suspensivos
}
// Calculamos aproximadamente cuántos caracteres caben
float char_width = static_cast<float>(value_width) / value.length();
size_t max_chars = static_cast<size_t>(available_for_text / char_width);
auto max_chars = static_cast<size_t>(available_for_text / char_width);
// Verificamos el ancho real del texto truncado
std::string truncated = truncateWithEllipsis(value, max_chars);
return element_text_->lenght(truncated, -2);
@@ -256,25 +256,25 @@ auto MenuRenderer::getTruncatedValue(const std::string &value, int available_wid
if (value_width <= available_width) {
return value;
}
// Calculamos cuántos caracteres podemos mostrar
int ellipsis_width = element_text_->lenght("...", -2);
int available_for_text = available_width - ellipsis_width;
if (available_for_text <= 0) {
return "..."; // Solo mostramos los puntos suspensivos
return "..."; // Solo mostramos los puntos suspensivos
}
// Calculamos aproximadamente cuántos caracteres caben
float char_width = static_cast<float>(value_width) / value.length();
size_t max_chars = static_cast<size_t>(available_for_text / char_width);
auto max_chars = static_cast<size_t>(available_for_text / char_width);
// Ajustamos iterativamente hasta que el texto quepa
std::string truncated = truncateWithEllipsis(value, max_chars);
while (element_text_->lenght(truncated, -2) > available_width && max_chars > 1) {
max_chars--;
truncated = truncateWithEllipsis(value, max_chars);
}
return truncated;
}

View File

@@ -5,6 +5,7 @@
#include <array> // Para array
#include <cstddef> // Para size_t
#include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "color.h" // Para Color

View File

@@ -3,12 +3,14 @@
#include <algorithm> // Para max
#include "audio.h" // Para Audio
#include "difficulty.h" // Para Difficulty
#include "difficulty.h" // Para getCodeFromName, getNameFromCode
#include "input.h" // Para Input
#include "lang.h" // Para getText, getCodeFromName, getNameFromCode
#include "menu_option.h" // Para MenuOption, BoolOption, ActionOption, IntOption, FolderOption, ListOption
#include "menu_option.h" // Para MenuOption, ListOption, ActionOption, BoolOption, FolderOption, IntOption
#include "menu_renderer.h" // Para MenuRenderer
#include "options.h" // Para PendingChanges, VideoOptions, pending_changes, video, AudioOptions, SettingsOptions, audio, checkPendingChanges, settings, WindowOptions, getDifficultyCodeFromName, getDifficultyNameFromCode, window, MusicOptions, SoundOptions
#include "options.h" // Para PendingChanges, pending_changes, checkPendingChanges, GamepadManager, Video, gamepad_manager, video, Audio, Settings, audio, settings, Gamepad, Window, window, Music, Sound
#include "param.h" // Para Param, param, ParamGame, ParamServiceMenu
#include "player.h" // Para Player
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.hpp" // Para Name, name, Options, options
@@ -285,7 +287,7 @@ void ServiceMenu::initializeOptions() {
options_.push_back(std::make_unique<ActionOption>(
Lang::getText("[SERVICE_MENU] SWAP_CONTROLLERS"),
SettingsGroup::CONTROLS,
[this]() {
[]() {
Options::gamepad_manager.swapPlayers();
}));

View File

@@ -9,7 +9,7 @@
#include "ui_message.h" // Para UIMessage
class MenuOption;
class MenuRenderer;
class MenuRenderer;
class ServiceMenu {
public: