-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d75887c
commit 7628138
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#pragma once | ||
|
||
#include "tactile/core/api.hpp" | ||
#include "tactile/foundation/prelude.hpp" | ||
|
||
namespace tactile { | ||
|
||
class IRenderer; | ||
|
||
/** | ||
* \brief Attempts to reload the Dear ImGui font texture atlas. | ||
* | ||
* \note This function does nothing if the renderer doesn't support font reloading. | ||
* | ||
* \param renderer the active renderer. | ||
* \param font_size the current font size. | ||
* \param framebuffer_scale the current display framebuffer scale. | ||
*/ | ||
TACTILE_CORE_API void try_reload_imgui_fonts(IRenderer& renderer, | ||
float font_size, | ||
float framebuffer_scale); | ||
|
||
} // namespace tactile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#include "tactile/core/ui/fonts.hpp" | ||
|
||
#include <IconsFontAwesome6.h> | ||
#include <imgui.h> | ||
|
||
#include "tactile/foundation/container/array.hpp" | ||
#include "tactile/foundation/log/logger.hpp" | ||
#include "tactile/foundation/render/renderer.hpp" | ||
|
||
namespace tactile { | ||
namespace { | ||
|
||
inline constexpr Array<ImWchar, 3> kFontIconRange {ICON_MIN_FA, ICON_MAX_FA, 0}; | ||
|
||
} // namespace | ||
|
||
void try_reload_imgui_fonts(IRenderer& renderer, | ||
const float font_size, | ||
const float framebuffer_scale) | ||
{ | ||
if (renderer.can_reload_fonts_texture()) { | ||
TACTILE_LOG_TRACE("Reloading fonts..."); | ||
|
||
auto& io = ImGui::GetIO(); | ||
io.Fonts->Clear(); | ||
|
||
ImFontConfig roboto_config {}; | ||
roboto_config.SizePixels = font_size * framebuffer_scale; | ||
io.Fonts->AddFontFromFileTTF("assets/fonts/roboto/Roboto-Regular.ttf", | ||
roboto_config.SizePixels, | ||
&roboto_config); | ||
|
||
// The global scale is 1 on most platforms, and 0.5 on macOS. | ||
io.FontGlobalScale = 1.0f / framebuffer_scale; | ||
|
||
ImFontConfig icon_config {}; | ||
icon_config.MergeMode = true; | ||
icon_config.SizePixels = font_size * framebuffer_scale; | ||
icon_config.GlyphMinAdvanceX = icon_config.SizePixels; | ||
icon_config.GlyphMaxAdvanceX = icon_config.GlyphMinAdvanceX; | ||
icon_config.GlyphOffset = {0, 2}; | ||
io.Fonts->AddFontFromFileTTF("assets/fonts/fa/" FONT_ICON_FILE_NAME_FAS, | ||
icon_config.GlyphMinAdvanceX, | ||
&icon_config, | ||
kFontIconRange.data()); | ||
|
||
io.Fonts->Build(); | ||
|
||
renderer.reload_fonts_texture(); | ||
|
||
ImGui::GetStyle().ScaleAllSizes(1.0f); | ||
} | ||
} | ||
|
||
} // namespace tactile |