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

Avoid copies when working with EnrichedString

This commit is contained in:
sfan5 2024-08-27 13:51:02 +02:00
parent fa4529b4f1
commit 19a58745c9
6 changed files with 53 additions and 54 deletions

View file

@ -513,12 +513,15 @@ void CGUITTFont::setFontHinting(const bool enable, const bool enable_auto_hintin
void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
{
draw(EnrichedString(std::wstring(text.c_str()), color), position, hcenter, vcenter, clip);
// Allow colors to work for strings that have passed through irrlicht by catching
// them here and converting them to enriched just before drawing.
EnrichedString s(text.c_str(), color);
draw(s, position, hcenter, vcenter, clip);
}
void CGUITTFont::draw(const EnrichedString &text, const core::rect<s32>& position, bool hcenter, bool vcenter, const core::rect<s32>* clip)
{
const std::vector<video::SColor> &colors = text.getColors();
const auto &colors = text.getColors();
if (!Driver)
return;

View file

@ -61,7 +61,7 @@ namespace gui
static irr::gui::IGUIStaticText *add(
irr::gui::IGUIEnvironment *guienv,
const wchar_t *text,
std::wstring_view text,
const core::rect< s32 > &rectangle,
bool border = false,
bool wordWrap = true,
@ -204,7 +204,7 @@ inline void setStaticText(irr::gui::IGUIStaticText *static_text, const EnrichedS
}
}
inline void setStaticText(irr::gui::IGUIStaticText *static_text, const wchar_t *text)
inline void setStaticText(irr::gui::IGUIStaticText *static_text, std::wstring_view text)
{
setStaticText(static_text, EnrichedString(text, static_text->getOverrideColor()));
}