From 1892ff3c0db23ccdf7b0f6dc83cb1bdf4579b4ec Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 22 Jan 2020 19:09:11 +0100 Subject: StaticText/EnrichedString: Styling support (#9187) * StaticText/EnrichedString: Styling support * Fix tooltip fg/bgcolor * Fix default color for substr(), add unittests --- src/util/enriched_string.h | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/util/enriched_string.h') diff --git a/src/util/enriched_string.h b/src/util/enriched_string.h index 202d84cb0..eaab3bd91 100644 --- a/src/util/enriched_string.h +++ b/src/util/enriched_string.h @@ -32,6 +32,7 @@ public: const irr::video::SColor &color = irr::video::SColor(255, 255, 255, 255)); EnrichedString(const std::wstring &string, const std::vector &colors); + void clear(); void operator=(const wchar_t *str); void addAtEnd(const std::wstring &s, const irr::video::SColor &color); @@ -50,6 +51,14 @@ public: const wchar_t *c_str() const; const std::vector &getColors() const; const std::wstring &getString() const; + + void setDefaultColor(const irr::video::SColor &color); + void updateDefaultColor(); + inline const irr::video::SColor &getDefaultColor() const + { + return m_default_color; + } + inline bool operator==(const EnrichedString &other) const { return (m_string == other.m_string && m_colors == other.m_colors); @@ -58,12 +67,6 @@ public: { return !(*this == other); } - inline void clear() - { - m_string.clear(); - m_colors.clear(); - m_has_background = false; - } inline bool empty() const { return m_string.empty(); @@ -72,6 +75,7 @@ public: { return m_string.size(); } + inline bool hasBackground() const { return m_has_background; @@ -80,9 +84,19 @@ public: { return m_background; } + inline void setBackground(const irr::video::SColor &color) + { + m_background = color; + m_has_background = true; + } + private: std::wstring m_string; std::vector m_colors; - bool m_has_background = false; + bool m_has_background; + irr::video::SColor m_default_color; irr::video::SColor m_background; + // This variable defines the length of the default-colored text. + // Change this to a std::vector if an "end coloring" tag is wanted. + size_t m_default_length; }; -- cgit v1.2.3