SpiecsEngine
 
Loading...
Searching...
No Matches

◆ SetFonts()

void Spices::ImGuiH::SetFonts ( FontMode fontmode = FontMode::FONT_PROPORTIONAL_SCALED)
static

Looking for TTF fonts, first on the VULKAN SDK, then Windows default fonts.

Parameters
[in]fontmodeFontMode.

Set Nicer fonts.

Set Nicer fonts.

Definition at line 127 of file ImguiHelper.cpp.

128 {
130
131 ImGuiIO& io = ImGui::GetIO();
132 const float high_dpi_scale = GetDPIScale();
133
137 ImFont* font = nullptr;
138 if (fontmode == FONT_MONOSPACED_SCALED)
139 {
140 if (font == nullptr)
141 {
142 const std::string p = R"(C:/Windows/Fonts/consola.ttf)";
143 if (FileLibrary::FileLibrary_Exists(p.c_str()))
144 {
145 font = io.Fonts->AddFontFromFileTTF(p.c_str(), 12.0f * high_dpi_scale);
146 }
147 }
148 }
149 else if (fontmode == FONT_PROPORTIONAL_SCALED)
150 {
151 const char* vk_path = getenv("VK_SDK_PATH");
152 if (vk_path)
153 {
154 const std::string p = std::string(vk_path) + R"(/Samples/Layer-Samples/data/FreeSans.ttf)";
155 if (FileLibrary::FileLibrary_Exists(p.c_str()))
156 font = io.Fonts->AddFontFromFileTTF(p.c_str(), 16.0f * high_dpi_scale);
157 }
158 if (font == nullptr)
159 {
160 const std::string p = R"(C:/Windows/Fonts/segoeui.ttf)";
161 if (FileLibrary::FileLibrary_Exists(p.c_str()))
162 font = io.Fonts->AddFontFromFileTTF(p.c_str(), 16.0f * high_dpi_scale);
163 }
164 }
165
166 if (font == nullptr)
167 {
168 ImFontConfig font_config = ImFontConfig();
169 font_config.SizePixels = 13.0f * ((fontmode == FONT_FIXED) ? 1 : high_dpi_scale); // 13 is the default font size
170 io.Fonts->AddFontDefault(&font_config);
171 }
172
173 float iconFontSize = 15.0f * high_dpi_scale;
174
175 // merge in icons from Font Awesome
176 static constexpr ImWchar icons_ranges[] = { ICON_MIN_MD, ICON_MAX_16_MD, 0 };
177 ImFontConfig icons_config;
178 icons_config.MergeMode = true;
179 icons_config.PixelSnapH = true;
180 icons_config.GlyphMinAdvanceX = iconFontSize;
181 icons_config.GlyphOffset.y = 3.0f;
182
183 std::stringstream ss;
184 ss << SPICES_ENGINE_ASSETS_PATH << "Fonts/" << FONT_ICON_FILE_NAME_MD;
185 if (FileLibrary::FileLibrary_Exists(ss.str().c_str()))
186 {
187 io.Fonts->AddFontFromFileTTF(ss.str().c_str(), iconFontSize, &icons_config, icons_ranges);
188 }
189 }
#define SPICES_PROFILE_ZONE
static bool FileLibrary_Exists(const char *path)
Determine whether the given string is existing a file.
static float GetDPIScale()
Get GLFW DPI Scale.
@ FONT_MONOSPACED_SCALED
Definition ImguiHelper.h:35
@ FONT_FIXED
Definition ImguiHelper.h:33
@ FONT_PROPORTIONAL_SCALED
Definition ImguiHelper.h:34

References Spices::FileLibrary::FileLibrary_Exists(), Spices::FONT_MONOSPACED_SCALED, Spices::FONT_PROPORTIONAL_SCALED, and GetDPIScale().

Referenced by Spices::SlateRenderer::InitImgui().