ImGuiManager: Add CompactFontRange()

This commit is contained in:
Stenzek
2024-08-25 23:39:14 +10:00
parent e8b787fb57
commit a7f3d7b02d
3 changed files with 150 additions and 0 deletions

View File

@ -159,6 +159,38 @@ void ImGuiManager::SetEmojiFontRange(std::vector<WCharType> range)
ReloadFontDataIfActive();
}
std::vector<ImGuiManager::WCharType> ImGuiManager::CompactFontRange(std::span<const WCharType> range)
{
std::vector<ImWchar> ret;
for (auto it = range.begin(); it != range.end();)
{
auto next_it = it;
++next_it;
// Combine sequential ranges.
const ImWchar start_codepoint = *it;
ImWchar end_codepoint = start_codepoint;
while (next_it != range.end())
{
const ImWchar next_codepoint = *next_it;
if (next_codepoint != (end_codepoint + 1))
break;
// Yep, include it.
end_codepoint = next_codepoint;
++next_it;
}
ret.push_back(start_codepoint);
ret.push_back(end_codepoint);
it = next_it;
}
return ret;
}
void ImGuiManager::SetGlobalScale(float global_scale)
{
if (s_global_prescale == global_scale)

View File

@ -26,6 +26,9 @@ void SetFontPathAndRange(std::string path, std::vector<WCharType> range);
/// Should NOT be terminated with zeros, unlike the font range above.
void SetEmojiFontRange(std::vector<WCharType> range);
/// Returns a compacted font range, with adjacent glyphs merged into one pair.
std::vector<WCharType> CompactFontRange(std::span<const WCharType> range);
/// Changes the global scale.
void SetGlobalScale(float global_scale);