fix label font cache

This commit is contained in:
MihailRis 2025-09-30 18:22:39 +03:00
parent c8ba5b5dbb
commit edc6810283
7 changed files with 75 additions and 36 deletions

View file

@ -38,6 +38,10 @@ bool Font::isPrintableChar(uint codepoint) const {
}
}
int FontMetrics::calcWidth(std::wstring_view text, size_t offset, size_t length) const {
return std::min(text.length() - offset, length) * glyphInterval;
}
int Font::calcWidth(std::wstring_view text, size_t length) const {
return calcWidth(text, 0, length);
}

View file

@ -4,7 +4,9 @@
#include <string>
#include <vector>
#include <glm/glm.hpp>
#include "typedefs.hpp"
#include "FontMetics.hpp"
class Texture;
class Batch2D;
@ -90,4 +92,8 @@ public:
) const;
const Texture* getPage(int page) const;
FontMetrics getMetrics() const {
return {lineHeight, yoffset, glyphInterval};
}
};

View file

@ -0,0 +1,11 @@
#pragma once
#include <string>
struct FontMetrics {
int lineHeight;
int yoffset;
int glyphInterval = 8;
int calcWidth(std::wstring_view text, size_t offset=0, size_t length=-1) const;
};