clang-tidy

This commit is contained in:
2025-08-10 14:13:11 +02:00
parent 0204a8896a
commit c727cb6541
21 changed files with 255 additions and 209 deletions

View File

@@ -15,17 +15,25 @@
void MenuRenderer::ResizeAnimation::start(float from_w, float from_h, float to_w, float to_h) {
start_width = from_w; start_height = from_h;
target_width = to_w; target_height = to_h;
elapsed = 0.0f; active = true;
elapsed = 0.0F;
active = true;
}
void MenuRenderer::ResizeAnimation::stop() { active = false;
elapsed = 0.0F;
}
void MenuRenderer::ResizeAnimation::stop() { active = false; elapsed = 0.0f; }
void MenuRenderer::ShowHideAnimation::startShow(float to_w, float to_h) {
type = Type::SHOWING; target_width = to_w; target_height = to_h;
elapsed = 0.0f; active = true;
elapsed = 0.0F;
active = true;
}
void MenuRenderer::ShowHideAnimation::startHide() { type = Type::HIDING;
elapsed = 0.0F;
active = true;
}
void MenuRenderer::ShowHideAnimation::stop() { type = Type::NONE; active = false;
elapsed = 0.0F;
}
void MenuRenderer::ShowHideAnimation::startHide() { type = Type::HIDING; elapsed = 0.0f; active = true; }
void MenuRenderer::ShowHideAnimation::stop() { type = Type::NONE; active = false; elapsed = 0.0f; }
MenuRenderer::MenuRenderer(const ServiceMenu *menu_state, std::shared_ptr<Text> element_text, std::shared_ptr<Text> title_text)
: element_text_(std::move(element_text)), title_text_(std::move(title_text)) {
@@ -34,7 +42,9 @@ MenuRenderer::MenuRenderer(const ServiceMenu *menu_state, std::shared_ptr<Text>
}
void MenuRenderer::render(const ServiceMenu *menu_state) {
if (!visible_) return;
if (!visible_) {
return;
}
// Dibuja la sombra
if (param.service_menu.drop_shadow) {
@@ -57,7 +67,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
if (shouldShowContent()) {
// Dibuja el título
float y = rect_.y + title_padding_;
title_text_->writeDX(Text::COLOR | Text::CENTER, rect_.x + rect_.w / 2.0f, y, menu_state->getTitle(), -4, param.service_menu.title_color);
title_text_->writeDX(Text::COLOR | Text::CENTER, rect_.x + rect_.w / 2.0F, y, menu_state->getTitle(), -4, param.service_menu.title_color);
// Dibuja la línea separadora
y = rect_.y + upper_height_;
@@ -73,15 +83,15 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
const Color &current_color = IS_SELECTED ? param.service_menu.selected_color : param.service_menu.text_color;
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) {
const int available_width = rect_.w - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2) - element_text_->length(option_pairs.at(i).first, -2) - ServiceMenu::MIN_GAP_OPTION_VALUE;
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_->length(option_pairs.at(i).first, -2) - ServiceMenu::MIN_GAP_OPTION_VALUE;
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_->length(truncated_value, -2);
element_text_->writeColored(X, y, truncated_value, current_color, -2);
} else {
const int available_width = rect_.w - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2);
std::string truncated_caption = getTruncatedValue(option_pairs.at(i).first, available_width);
element_text_->writeDX(Text::CENTER | Text::COLOR, rect_.x + rect_.w / 2.0f, y, truncated_caption, -2, current_color);
const int AVAILABLE_WIDTH = rect_.w - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2);
std::string truncated_caption = getTruncatedValue(option_pairs.at(i).first, AVAILABLE_WIDTH);
element_text_->writeDX(Text::CENTER | Text::COLOR, rect_.x + rect_.w / 2.0F, y, truncated_caption, -2, current_color);
}
y += options_height_ + options_padding_;
}
@@ -89,7 +99,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
}
void MenuRenderer::update(const ServiceMenu *menu_state) {
float delta_time = 1.0f / 60.0f; // Asumiendo 60 FPS
float delta_time = 1.0F / 60.0F; // Asumiendo 60 FPS
updateAnimations(delta_time);
if (visible_) {
@@ -101,7 +111,9 @@ void MenuRenderer::update(const ServiceMenu *menu_state) {
// --- Nuevos métodos de control ---
void MenuRenderer::show(const ServiceMenu* menu_state) {
if (visible_) return;
if (visible_) {
return;
}
visible_ = true;
// Calcula el tamaño final y lo usa para la animación
@@ -114,14 +126,16 @@ void MenuRenderer::show(const ServiceMenu* menu_state) {
show_hide_animation_.startShow(target_rect.w, target_rect.h);
// El tamaño inicial es cero para la animación
rect_.w = 0.0f;
rect_.h = 0.0f;
rect_.w = 0.0F;
rect_.h = 0.0F;
updatePosition();
}
void MenuRenderer::hide() {
if (!visible_ || show_hide_animation_.type == ShowHideAnimation::Type::HIDING) return;
if (!visible_ || show_hide_animation_.type == ShowHideAnimation::Type::HIDING) {
return;
}
// Detener animación de resize si la hubiera
resize_animation_.stop();
@@ -234,7 +248,9 @@ void MenuRenderer::updateShowHideAnimation(float delta_time) {
rect_.w = show_hide_animation_.target_width;
rect_.h = show_hide_animation_.target_height;
} else if (show_hide_animation_.type == ShowHideAnimation::Type::HIDING) {
rect_.w = 0.0f; rect_.h = 0.0f; visible_ = false;
rect_.w = 0.0F;
rect_.h = 0.0F;
visible_ = false;
}
show_hide_animation_.stop();
updatePosition();
@@ -244,8 +260,8 @@ void MenuRenderer::updateShowHideAnimation(float delta_time) {
rect_.w = show_hide_animation_.target_width * progress;
rect_.h = show_hide_animation_.target_height * progress;
} else if (show_hide_animation_.type == ShowHideAnimation::Type::HIDING) {
rect_.w = show_hide_animation_.target_width * (1.0f - progress);
rect_.h = show_hide_animation_.target_height * (1.0f - progress);
rect_.w = show_hide_animation_.target_width * (1.0F - progress);
rect_.h = show_hide_animation_.target_height * (1.0F - progress);
}
updatePosition();
}
@@ -274,8 +290,8 @@ void MenuRenderer::updateResizeAnimation(float delta_time) {
void MenuRenderer::updatePosition() {
switch (position_mode_) {
case PositionMode::CENTERED:
rect_.x = anchor_x_ - rect_.w / 2.0f;
rect_.y = anchor_y_ - rect_.h / 2.0f;
rect_.x = anchor_x_ - rect_.w / 2.0F;
rect_.y = anchor_y_ - rect_.h / 2.0F;
break;
case PositionMode::FIXED:
rect_.x = anchor_x_;
@@ -289,12 +305,17 @@ void MenuRenderer::updatePosition() {
// Resto de métodos (sin cambios significativos)
void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>> &all_options, const ServiceMenu *menu_state) {
for (int &w : group_menu_widths_) w = ServiceMenu::MIN_WIDTH;
for (int &w : group_menu_widths_) {
w = ServiceMenu::MIN_WIDTH;
}
for (int group = 0; group < 5; ++group) {
auto sg = static_cast<ServiceMenu::SettingsGroup>(group);
int max_option_width = 0, max_value_width = 0;
int max_option_width = 0;
int max_value_width = 0;
for (const auto &option : all_options) {
if (option->getGroup() != sg) continue;
if (option->getGroup() != sg) {
continue;
}
max_option_width = std::max(max_option_width, element_text_->length(option->getCaption(), -2));
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) {
int max_available_value_width = static_cast<int>(max_menu_width_) - max_option_width - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2) - ServiceMenu::MIN_GAP_OPTION_VALUE;
@@ -302,7 +323,9 @@ void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<Menu
}
}
size_t total_width = max_option_width + (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2);
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) total_width += ServiceMenu::MIN_GAP_OPTION_VALUE + max_value_width;
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_));
}
}
@@ -375,5 +398,5 @@ auto MenuRenderer::getTruncatedValue(const std::string &value, int available_wid
return truncated;
}
auto MenuRenderer::easeOut(float t) const -> float { return 1.0f - (1.0f - t) * (1.0f - t); }
auto MenuRenderer::easeOut(float t) const -> float { return 1.0F - (1.0F - t) * (1.0F - t); }
auto MenuRenderer::shouldShowContent() const -> bool { return !show_hide_animation_.active; }