27 const std::vector<std::string>& segments,
const std::vector<Color>& colors)
29 if (segments.size() != colors.size()) {
30 throw std::invalid_argument(
"Segments and colors size mismatch");
33 std::vector<ColoredSegment> line;
34 for (
size_t i = 0; i < segments.size(); ++i) {
35 line.push_back({segments[i], colors[i]});
37 _lines.push_back(line);
85 if (_lines.empty())
return;
87 int lineSpacing = _fontSize / 4;
91 for (
const auto& line : _lines) {
93 for (
const auto& segment : line) {
96 boxWidth = std::max(boxWidth, lineWidth);
97 boxHeight += _fontSize + lineSpacing;
99 boxHeight -= lineSpacing;
101 boxWidth += _padding * 2;
102 boxHeight += _padding * 2;
104 Vector2 anchoredPos = _calculateAnchoredPosition(position, boxWidth, boxHeight);
105 Rectangle rect = {anchoredPos.x, anchoredPos.y,
static_cast<float>(boxWidth),
106 static_cast<float>(boxHeight)};
109 Color bgColorWithAlpha = {_bgColor.r, _bgColor.g, _bgColor.b, _bgAlpha};
110 DrawRectangleRounded(rect, 0.2f, 8, bgColorWithAlpha);
113 if (_borderThickness > 0) {
114 DrawRectangleRoundedLines(rect, 0.2f, 8, _borderThickness, _borderColor);
118 float textY = anchoredPos.y + _padding;
119 for (
const auto& line : _lines) {
120 float textX = anchoredPos.x + _padding;
121 for (
const auto& segment : line) {
123 _fontSize, segment.color);
126 textY += _fontSize + lineSpacing;
133 Vector2 anchoredPos = position;
139 anchoredPos.x -= boxWidth / 2.0f;
142 anchoredPos.x -= boxWidth;
145 anchoredPos.y -= boxHeight / 2.0f;
148 anchoredPos.x -= boxWidth / 2.0f;
149 anchoredPos.y -= boxHeight / 2.0f;
152 anchoredPos.x -= boxWidth;
153 anchoredPos.y -= boxHeight / 2.0f;
156 anchoredPos.y -= boxHeight;
159 anchoredPos.x -= boxWidth / 2.0f;
160 anchoredPos.y -= boxHeight;
163 anchoredPos.x -= boxWidth;
164 anchoredPos.y -= boxHeight;
static void draw(const std::string &text, int x, int y, int fontSize, Color color)
static int measure(const std::string &text, int fontSize)