mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp.git
synced 2025-10-30 08:03:03 +00:00
Fix errant RML tag in mod menu and insert breaks for newlines when setting element text
This commit is contained in:
parent
bb10d5d090
commit
51c6263f13
3 changed files with 23 additions and 3 deletions
|
|
@ -272,10 +272,30 @@ bool Element::is_enabled() const {
|
||||||
return enabled && !disabled_from_parent;
|
return enabled && !disabled_from_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adapted from RmlUi's `EncodeRml`.
|
||||||
|
std::string escape_rml(std::string_view string)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
result.reserve(string.size());
|
||||||
|
for (char c : string)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '<': result += "<"; break;
|
||||||
|
case '>': result += ">"; break;
|
||||||
|
case '&': result += "&"; break;
|
||||||
|
case '"': result += """; break;
|
||||||
|
case '\n': result += "<br/>"; break;
|
||||||
|
default: result += c; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void Element::set_text(std::string_view text) {
|
void Element::set_text(std::string_view text) {
|
||||||
if (can_set_text) {
|
if (can_set_text) {
|
||||||
// Escape the string into Rml to prevent element injection.
|
// Escape the string into Rml to prevent element injection.
|
||||||
base->SetInnerRML(Rml::StringUtilities::EncodeRml(std::string(text)));
|
base->SetInnerRML(escape_rml(text));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(false && "Attempted to set text of an element that cannot have its text set.");
|
assert(false && "Attempted to set text of an element that cannot have its text set.");
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public:
|
||||||
virtual ~Element();
|
virtual ~Element();
|
||||||
void clear_children();
|
void clear_children();
|
||||||
bool remove_child(ResourceId child);
|
bool remove_child(ResourceId child);
|
||||||
bool remove_child(Element *child) { remove_child(child->get_resource_id()); }
|
bool remove_child(Element *child) { return remove_child(child->get_resource_id()); }
|
||||||
void add_style(Style *style, std::string_view style_name);
|
void add_style(Style *style, std::string_view style_name);
|
||||||
void add_style(Style *style, const std::initializer_list<std::string_view> &style_names);
|
void add_style(Style *style, const std::initializer_list<std::string_view> &style_names);
|
||||||
void set_enabled(bool enabled);
|
void set_enabled(bool enabled);
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ void ModDetailsPanel::set_mod_details(const recomp::mods::ModDetails& details, c
|
||||||
title_label->set_text(cur_details.display_name);
|
title_label->set_text(cur_details.display_name);
|
||||||
version_label->set_text(cur_details.version.to_string());
|
version_label->set_text(cur_details.version.to_string());
|
||||||
|
|
||||||
std::string authors_str = "<i>Authors</i>:";
|
std::string authors_str = "Authors:";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (const std::string& author : details.authors) {
|
for (const std::string& author : details.authors) {
|
||||||
authors_str += (first ? " " : ", ") + author;
|
authors_str += (first ? " " : ", ") + author;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue