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:
parent
6c4a110679
commit
24cc33e704
17 changed files with 530 additions and 37 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue