1

Can anyone tell me how fonts are loaded in Imgui?

I mean: downloading at least 10 fonts at a time: no problem, everything works.

ImGuiIO* ImGuiIO_p = &ImGui::GetIO();
 
(*ImGuiIO_p).Fonts->AddFontDefault();               
 
(*ImGuiIO_p).Fonts->AddFontFromFileTTF(&path_utf8__to_TTF_file_1[0], size_Font, ImFontConfig_p, 0);
(*ImGuiIO_p).Fonts->AddFontFromFileTTF(&path_utf8__to_TTF_file_2[0], size_Font, ImFontConfig_p, 0);

The problem arises when I need to load some other font before I applied Build (), in this case, if I understand correctly, I need to remove ALL the downloaded fonts first:

(*ImGuiIO_p).Fonts->Clear();

Download them again and download the new font immediately:

ImGuiIO* ImGuiIO_p = &ImGui::GetIO();
 
(*ImGuiIO_p).Fonts->AddFontDefault();               
 
(*ImGuiIO_p).Fonts->AddFontFromFileTTF(&path_utf8__to_TTF_file_1[0], size_Font, ImFontConfig_p, 0);
(*ImGuiIO_p).Fonts->AddFontFromFileTTF(&path_utf8__to_TTF_file_2[0], size_Font, ImFontConfig_p, 0);
(*ImGuiIO_p).Fonts->AddFontFromFileTTF(&path_utf8__to_TTF_file_NEW[0], size_Font, ImFontConfig_p, 0); //new Load Font
 
(*ImGuiIO_p).Fonts->Build();

But somehow it's a bit weird. Maybe there is a way without deleting and reloading?

PS:I apparently somehow incorrectly checked the work of this code. There is no need to delete anything. You just need to add the Font and then call Build() again.

Lua_beg
  • 31
  • 6
  • 1
    why use `(*ImGuiIO_p).Fonts` instead of `ImGuiIO_p->Fonts`? – phuclv Jun 21 '23 at 15:58
  • @phuclv, if I use ImGuiIO_p->Fonts for the place (*ImGuiIO_p).Fonts - does this fix my problem with downloading Fonts ? – Lua_beg Jun 21 '23 at 16:04
  • 1
    obviously no, it'll improve readability and maintainability. That's why it's a comment. If it works then it'd already be an answer – phuclv Jun 21 '23 at 16:27

0 Answers0