This commit is contained in:
Vlad committed 2026-04-30 15:15:11 +06:00
commit 4de8f78eca
29 files changed
+2052 -111

No files matched your search

+32
View File
@@ -347,6 +347,38 @@ bool TextRenderer::loadGlyphs(const std::string& ttfPath, int pixelSize, const s
return true;
}
float TextRenderer::measureTextWidth(const std::string& text, float scale) const
{
if (text.empty()) {
return 0.0f;
}
float penX = 0.0f;
float maxLineWidth = 0.0f;
size_t textPos = 0;
while (textPos < text.size()) {
uint32_t cp = nextUtf8Codepoint(text, textPos);
if (cp == '\n') {
maxLineWidth = max(maxLineWidth, penX);
penX = 0.0f;
continue;
}
auto it = glyphs.find(cp);
if (it == glyphs.end()) {
continue;
}
const GlyphInfo& g = it->second;
penX += static_cast<float>(g.advance >> 6) * scale;
}
maxLineWidth = max(maxLineWidth, penX);
return maxLineWidth;
}
void TextRenderer::drawText(const std::string& text, float x, float y, float scale, bool centered, std::array<float, 4> color)
{
if (!r || text.empty() || !atlasTexture) return;
+3
View File
@@ -29,6 +29,9 @@ public:
bool init(Renderer& renderer, const std::string& ttfPath, int pixelSize, const std::string& zipfilename);
void drawText(const std::string& text, float x, float y, float scale, bool centered, std::array<float, 4> color = { 1.f,1.f,1.f,1.f });
float measureTextWidth(const std::string& text, float scale = 1.0f) const;
float getLineHeight(float scale = 1.0f) const { return lineHeight * scale; }
// Clear cached meshes (call on window resize / DPI change)
void ClearCache();