eliminades locales no utilitzades

modificats textos de ui a case tipo frase
notificacions llargues pasen a multilinea
This commit is contained in:
2026-04-17 10:11:31 +02:00
parent 5eb178b039
commit 8a44ab15e7
4 changed files with 118 additions and 184 deletions

View File

@@ -22,6 +22,41 @@
// [SINGLETON]
Notifier* Notifier::notifier = nullptr;
// Parte un texto en varias líneas cuando no cabe en max_width píxeles.
// Divide por espacios; si una palabra sola excede el ancho, queda en su propia línea.
static auto wrapToWidth(const std::string& text, int max_width, Text* text_obj, int kerning = 1) -> std::vector<std::string> {
if (max_width <= 0 || text_obj->length(text, kerning) <= max_width) {
return {text};
}
std::vector<std::string> lines;
std::string current;
std::string word;
auto flush_word = [&]() {
if (word.empty()) { return; }
const std::string CANDIDATE = current.empty() ? word : current + " " + word;
if (text_obj->length(CANDIDATE, kerning) <= max_width) {
current = CANDIDATE;
} else {
if (!current.empty()) { lines.push_back(current); }
current = word;
}
word.clear();
};
for (const char c : text) {
if (c == ' ') {
flush_word();
} else {
word += c;
}
}
flush_word();
if (!current.empty()) { lines.push_back(current); }
return lines;
}
// Definición de estilos predefinidos
const Notifier::Style Notifier::Style::DEFAULT = {
.bg_color = Defaults::Notification::BG_COLOR,
@@ -149,14 +184,6 @@ void Notifier::show(std::vector<std::string> texts, const Style& style, int icon
auto result = std::ranges::remove_if(texts, [](const std::string& s) -> bool { return s.empty(); });
texts.erase(result.begin(), result.end());
// Encuentra la cadena más larga
std::string longest;
for (const auto& text : texts) {
if (text.length() > longest.length()) {
longest = text;
}
}
// Inicializa variables
constexpr float TEXT_SIZE = LINE_HEIGHT;
const auto PADDING_IN_H = TEXT_SIZE;
@@ -164,6 +191,17 @@ void Notifier::show(std::vector<std::string> texts, const Style& style, int icon
const int ICON_SPACE = icon >= 0 ? ICON_SIZE + PADDING_IN_H : 0;
const TextAlign TEXT_IS = ICON_SPACE > 0 ? TextAlign::LEFT : style.text_align;
const float WIDTH = Options::game.width - (PADDING_OUT * 2);
const int MAX_TEXT_WIDTH = static_cast<int>(WIDTH - (PADDING_IN_H * 2) - ICON_SPACE);
// Si un texto no cabe en una línea, parte por espacios en varias líneas
std::vector<std::string> wrapped;
wrapped.reserve(texts.size());
for (const auto& t : texts) {
auto lines = wrapToWidth(t, MAX_TEXT_WIDTH, text_.get());
wrapped.insert(wrapped.end(), std::make_move_iterator(lines.begin()), std::make_move_iterator(lines.end()));
}
texts = std::move(wrapped);
const float HEIGHT = (TEXT_SIZE * texts.size()) + (PADDING_IN_V * 2);
const auto SHAPE = style.shape;