Text: revisada la classe
window_message: correcions
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include "menu_option.h" // Para MenuOption
|
||||
#include "param.h" // Para Param, param, ParamServiceMenu, ParamGame
|
||||
#include "screen.h" // Para Screen
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR
|
||||
#include "text.h" // Para Text, Text::CENTER, Text::COLOR
|
||||
#include "utils.h" // Para Zone, truncateWithEllipsis
|
||||
|
||||
MenuRenderer::MenuRenderer(const ServiceMenu *menu_state, std::shared_ptr<Text> element_text, std::shared_ptr<Text> title_text)
|
||||
@@ -35,7 +35,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
|
||||
|
||||
// Dibuja el título
|
||||
float y = rect_.y + title_padding_;
|
||||
title_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, menu_state->getTitle(), -4, param.service_menu.title_color);
|
||||
title_text_->writeDX(Text::COLOR | Text::CENTER, param.game.game_area.center_x, y, menu_state->getTitle(), -4, param.service_menu.title_color);
|
||||
|
||||
// Dibuja la línea separadora
|
||||
y = rect_.y + upper_height_;
|
||||
@@ -46,38 +46,38 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
|
||||
y = options_y_;
|
||||
const auto &option_pairs = menu_state->getOptionPairs();
|
||||
const auto &display_options = menu_state->getDisplayOptions();
|
||||
|
||||
|
||||
for (size_t i = 0; i < option_pairs.size(); ++i) {
|
||||
const bool IS_SELECTED = (i == menu_state->getSelectedIndex());
|
||||
const Color ¤t_color = IS_SELECTED ? param.service_menu.selected_color : param.service_menu.text_color;
|
||||
|
||||
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 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);
|
||||
|
||||
|
||||
// Si la opción tiene Behavior::BOTH, añadir indicador visual
|
||||
if (i < display_options.size() && display_options[i]->getBehavior() == MenuOption::Behavior::BOTH) {
|
||||
truncated_value = "► " + truncated_value + " ◄";
|
||||
truncated_value = "-" + truncated_value + "-";
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
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 {
|
||||
// Para opciones centradas, también truncamos si es necesario
|
||||
const int available_width = rect_.w - (ServiceMenu::OPTIONS_HORIZONTAL_PADDING * 2);
|
||||
std::string truncated_caption = getTruncatedValue(option_pairs.at(i).first, available_width);
|
||||
|
||||
|
||||
// Si la opción tiene Behavior::BOTH, añadir indicador visual
|
||||
if (i < display_options.size() && display_options[i]->getBehavior() == MenuOption::Behavior::BOTH) {
|
||||
truncated_caption = "► " + truncated_caption + " ◄";
|
||||
truncated_caption = "-" + truncated_caption + "-";
|
||||
}
|
||||
|
||||
element_text_->writeDX(TEXT_CENTER | TEXT_COLOR, rect_.x + rect_.w / 2, y, truncated_caption, -2, current_color);
|
||||
|
||||
element_text_->writeDX(Text::CENTER | Text::COLOR, rect_.x + rect_.w / 2, y, truncated_caption, -2, current_color);
|
||||
}
|
||||
y += options_height_ + options_padding_;
|
||||
}
|
||||
@@ -196,7 +196,7 @@ void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<Menu
|
||||
if (option->getGroup() != sg) {
|
||||
continue;
|
||||
}
|
||||
max_option_width = std::max(max_option_width, element_text_->lenght(option->getCaption(), -2));
|
||||
max_option_width = std::max(max_option_width, element_text_->length(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 -
|
||||
@@ -240,14 +240,14 @@ auto MenuRenderer::setRect(SDL_FRect rect) -> SDL_FRect {
|
||||
}
|
||||
|
||||
auto MenuRenderer::getTruncatedValueWidth(const std::string &value, int available_width) const -> int {
|
||||
int value_width = element_text_->lenght(value, -2);
|
||||
int value_width = element_text_->length(value, -2);
|
||||
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 ellipsis_width = element_text_->length("...", -2);
|
||||
int available_for_text = available_width - ellipsis_width;
|
||||
|
||||
if (available_for_text <= 0) {
|
||||
@@ -260,17 +260,17 @@ auto MenuRenderer::getTruncatedValueWidth(const std::string &value, int availabl
|
||||
|
||||
// Verificamos el ancho real del texto truncado
|
||||
std::string truncated = truncateWithEllipsis(value, max_chars);
|
||||
return element_text_->lenght(truncated, -2);
|
||||
return element_text_->length(truncated, -2);
|
||||
}
|
||||
|
||||
auto MenuRenderer::getTruncatedValue(const std::string &value, int available_width) const -> std::string {
|
||||
int value_width = element_text_->lenght(value, -2);
|
||||
int value_width = element_text_->length(value, -2);
|
||||
if (value_width <= available_width) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Calculamos cuántos caracteres podemos mostrar
|
||||
int ellipsis_width = element_text_->lenght("...", -2);
|
||||
int ellipsis_width = element_text_->length("...", -2);
|
||||
int available_for_text = available_width - ellipsis_width;
|
||||
|
||||
if (available_for_text <= 0) {
|
||||
@@ -283,7 +283,7 @@ auto MenuRenderer::getTruncatedValue(const std::string &value, int available_wid
|
||||
|
||||
// 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) {
|
||||
while (element_text_->length(truncated, -2) > available_width && max_chars > 1) {
|
||||
max_chars--;
|
||||
truncated = truncateWithEllipsis(value, max_chars);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user