1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Add button_url[] and hypertext element to allow mods to open web pages (#13825)

Fixes #12500
This commit is contained in:
rubenwardy 2024-03-24 17:19:23 +00:00 committed by GitHub
parent 6c4a110679
commit 24cc33e704
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 530 additions and 37 deletions

View file

@ -593,6 +593,40 @@ void str_replace(std::string &str, char from, char to)
std::replace(str.begin(), str.end(), from, to);
}
std::string wrap_rows(std::string_view from, unsigned row_len, bool has_color_codes)
{
std::string to;
to.reserve(from.size());
std::string last_color_code;
unsigned character_idx = 0;
bool inside_colorize = false;
for (size_t i = 0; i < from.size(); i++) {
if (!IS_UTF8_MULTB_INNER(from[i])) {
if (inside_colorize) {
last_color_code += from[i];
if (from[i] == ')') {
inside_colorize = false;
} else {
// keep reading
}
} else if (has_color_codes && from[i] == '\x1b') {
inside_colorize = true;
last_color_code = "\x1b";
} else {
// Wrap string after last inner byte of char
if (character_idx > 0 && character_idx % row_len == 0) {
to += '\n' + last_color_code;
}
character_idx++;
}
}
to += from[i];
}
return to;
}
/* Translated strings have the following format:
* \x1bT marks the beginning of a translated string
* \x1bE marks its end