30 bool _showDot =
false;
31 bool _seedSet =
false;
32 std::size_t _seed = 0;
34 std::vector<sf::Color> _palette{ {124, 92, 255}, {58, 160, 224}, {224, 138, 58} };
37 static std::size_t hash(
const std::string& s)
38 { std::size_t h = 0;
for (
char c : s) h = h * 31u + (
unsigned char)c;
return h; }
42 if (_palette.empty())
return;
43 const std::size_t k = (_seedSet ? _seed : hash(_name)) % _palette.size();
44 _chip.setFillColor(_palette[k]);
49 _chip.setPosition(_pos);
50 _chip.setSize({ _size, _size });
51 auto b = _label.getLocalBounds();
52 _label.setPosition({ _pos.x + _size * 0.5f - (b.position.x + b.size.x) * 0.5f,
53 _pos.y + _size * 0.5f - _size * 0.30f });
54 const float d = std::max(6.f, _size * 0.28f);
55 _dot.setSize({ d, d });
56 _dot.setPosition({ _pos.x + _size - d, _pos.y + _size - d });
62 _label.setFillColor(
sf::Color(235, 238, 245));
63 _label.setCharacterSize(11);
64 _dot.setFillColor(_dotColor);
65 _dot.setVisible(
false);
76 std::string out;
bool atStart =
true;
79 if (c ==
' ') { atStart =
true;
continue; }
80 if (atStart && out.size() < 2) { out += (char)std::toupper((
unsigned char)c); atStart =
false; }
82 if (out.empty() && !name.empty()) out += (char)std::toupper((
unsigned char)name[0]);
94 void setColorSeed(std::size_t seed) { _seed = seed; _seedSet =
true; applyColor(); }
95 void setPalette(std::vector<sf::Color> palette) { _palette = std::move(palette); applyColor(); }
96 void setAvatarSize(
float px) { _size = px; _label.setCharacterSize((
unsigned)(px * 0.42f)); relayout(); }
99 void setPresence(
bool present) { _showDot = present; _dot.setVisible(present); }
A framework-integrated text object with word-wrap support.