do
local self = {
ToLoad = {}
}
ImGuiWantLoadFontEx = function(font_info)
font_info.dest[0] = ImGuiStubFont
local font_path = GetFontFullPath(font_info)
if not doesFileExist(font_path) then
print("font '" .. font_path .. "' doesn't exist, using default")
return
end
-- if not loaded, load it at next frame
table.insert(self.ToLoad, font_info)
end
ImGuiWantLoadFont = function(filename, size, dest)
local font_info = {
filename = filename,
size = size,
dest = dest
}
ImGuiWantLoadFontEx(font_info)
end
self.frame = ImGui.OnFrame(
function() return #self.ToLoad > 0 end,
function()
local FontAtlas = ImGui.GetIO().Fonts
for _, font_info in pairs(self.ToLoad) do
local glyph_ranges_builder = ImGui.ImFontGlyphRangesBuilder()
glyph_ranges_builder:AddRanges(FontAtlas:GetGlyphRangesDefault())
glyph_ranges_builder:AddRanges(FontAtlas:GetGlyphRangesCyrillic())
local glyph_ranges = ImGui.ImVector_ImWchar()
glyph_ranges_builder:BuildRanges(glyph_ranges)
local font = FontAtlas:AddFontFromFileTTF(GetFontFullPath(font_info), font_info.size, nil, glyph_ranges[0].Data)
if not font then
print("failed to load '" .. font_info.filename .. "' font")
return
end
print("font loaded " .. tostring(font))
font_info.dest[0] = font
end
ImGui.InvalidateFontsTexture()
self.ToLoad = {}
end,
function(pl) pl.HideCursor = true end
)
ImGuiFrames._FontsLoader = self
end