new UI system

This commit is contained in:
Jorijn van der Graaf 2026-05-01 23:35:37 +02:00
commit 216972e73a
82 changed files with 4837 additions and 3243 deletions

View file

@ -61,10 +61,26 @@ Font::Font(const std::filesystem::path& fontFilePath) {
std::uint32_t Font::GetLineWidth(const std::string_view text, float size) {
float scale = stbtt_ScaleForPixelHeight(&font, size);
std::uint32_t lineWidth = 0;
for (const char c : text) {
std::size_t i = 0;
while (i < text.size()) {
std::uint32_t cp = DecodeUtf8(text, i);
if (cp == 0) break;
int advance, lsb;
stbtt_GetCodepointHMetrics(&font, c, &advance, &lsb);
stbtt_GetCodepointHMetrics(&font, static_cast<int>(cp), &advance, &lsb);
lineWidth += (int)(advance * scale);
}
return lineWidth;
}
float Font::LineHeight(float size) {
float scale = stbtt_ScaleForPixelHeight(&font, size);
return (ascent - descent + lineGap) * scale;
}
float Font::AscentPx(float size) {
return ascent * stbtt_ScaleForPixelHeight(&font, size);
}
float Font::ScaleForSize(float size) {
return stbtt_ScaleForPixelHeight(&font, size);
}