12 _lines.push_back({{text}, {color}});
17 const std::vector<Color>& colors)
19 if (segments.size() != colors.size())
20 throw std::invalid_argument(
"segments and colors size mismatch");
21 _lines.push_back({segments, colors});
98 float sw =
static_cast<float>(GetScreenWidth());
99 float sh =
static_cast<float>(GetScreenHeight());
105 return {(sw - boxWidth) / 2.0f,
_margin};
109 return {
_margin, (sh - boxHeight) / 2.0f};
111 return {(sw - boxWidth) / 2.0f, (sh - boxHeight) / 2.0f};
113 return {sw - boxWidth -
_margin, (sh - boxHeight) / 2.0f};
117 return {(sw - boxWidth) / 2.0f, sh - boxHeight -
_margin};
127 if (
_lines.empty())
return;
129 int lineSpacing = scaledFontSize / 4;
130 int contentWidth = 0;
131 int contentHeight = 0;
133 for (
const auto& line :
_lines) {
135 for (
size_t i = 0; i < line.segments.size(); ++i)
137 contentWidth = std::max(contentWidth, lineWidth);
138 contentHeight += scaledFontSize + lineSpacing;
140 contentHeight -= lineSpacing;
142 float boxWidth = std::max(
static_cast<float>(contentWidth +
_padding * 2),
_minWidth);
146 Rectangle rect = {pos.x, pos.y, boxWidth, boxHeight};
150 DrawRectangleRounded(rect, 0.2f, 8, bg);
152 DrawRectangleRoundedLines(rect, 0.2f, 8,
static_cast<float>(
_borderThickness),
156 for (
const auto& line :
_lines) {
158 for (
size_t i = 0; i < line.segments.size(); ++i)
164 for (
size_t i = 0; i < line.segments.size(); ++i) {
165 TextRenderer::draw(line.segments[i],
static_cast<int>(textX),
static_cast<int>(textY),
166 scaledFontSize, line.colors[i]);
169 textY += scaledFontSize + lineSpacing;
static void draw(const std::string &text, int x, int y, int fontSize, Color color)
static int measure(const std::string &text, int fontSize)