aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/StringView.hpp18
-rw-r--r--include/Text.hpp38
2 files changed, 38 insertions, 18 deletions
diff --git a/include/StringView.hpp b/include/StringView.hpp
index 45d0f5b..c4e7ce3 100644
--- a/include/StringView.hpp
+++ b/include/StringView.hpp
@@ -68,6 +68,24 @@ namespace dchat
return data[index];
}
+ // Returns -1 if substr not found.
+ // TODO: Make this more efficient
+ usize find(const BasicStringView<CharType> &substr, usize offset = 0) const
+ {
+ if(substr.size == 0)
+ return -1;
+
+ if(offset + substr.size > size)
+ return -1;
+
+ for(usize i = offset; i < size - (substr.size - 1); ++i)
+ {
+ if(memcmp(data + i, substr.data, substr.size) == 0)
+ return i;
+ }
+ return -1;
+ }
+
const CharType *data;
usize size;
};
diff --git a/include/Text.hpp b/include/Text.hpp
index 016e852..daea7ca 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -10,6 +10,24 @@
namespace dchat
{
+ struct TextElement
+ {
+ enum class Type
+ {
+ TEXT,
+ EMOJI,
+ URL
+ };
+
+ TextElement() {}
+ TextElement(const StringViewUtf32 &_text, Type _type) : text(_text), type(_type), ownLine(false) {}
+
+ StringViewUtf32 text;
+ sf::Vector2f position;
+ Type type;
+ bool ownLine; // Currently only used for emoji, to make emoji bigger when it's the only thing on a line
+ };
+
class Text
{
public:
@@ -34,24 +52,7 @@ namespace dchat
private:
void stringSplitElements(sf::String &stringToSplit, usize startIndex);
void updateGeometry();
- private:
- struct TextElement
- {
- enum class Type
- {
- TEXT,
- EMOJI
- };
-
- TextElement() {}
- TextElement(const StringViewUtf32 &_text, Type _type) : text(_text), type(_type), ownLine(false) {}
-
- StringViewUtf32 text;
- sf::Vector2f position;
- Type type;
- bool ownLine; // Currently only used for emoji, to make emoji bigger when it's the only thing on a line
- };
-
+ private:
sf::String str;
const sf::Font *font;
unsigned int characterSize;
@@ -59,6 +60,7 @@ namespace dchat
float maxWidth;
sf::Vector2f position;
sf::Color color;
+ sf::Color urlColor;
bool dirty;
bool plainText;
float totalHeight;