Skip to content

Commit

Permalink
Fix / Added fontAwesome6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Mar 12, 2024
1 parent 8260b40 commit e89c10a
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 72 deletions.
4 changes: 2 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Version numbers are synced between hello_imgui and imgui_bundle.
# v1.5.0
* Breaking change: add FontAwesome options with support for v4 and v6:
- See e04af395c5a25e20861d06afd9ec0cddcccd7542
- the default icon font is now FontAwesome 6, which includes many more icons.
- added runnerParams.runnerCallbacks.defaultIconFont
- the default icon font is now FontAwesome 4, but v6 includes many more icons.
- added runnerParams.runnerCallbacks.defaultIconFont, where you can select v6
- you need to include manually the icons:
#include "hello_imgui/icons_font_awesome_6.h" or #include "hello_imgui/icons_font_awesome_4.h"

Expand Down
31 changes: 0 additions & 31 deletions src/hello_imgui/doc_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,37 +110,6 @@ See [hello_imgui_font.h](https://github.com/pthom/hello_imgui/blob/master/src/he
ImFont* LoadFont(const std::string & fontFilename, float fontSize,
const FontLoadingParams & params = {});
// Note: if you want to use a more recent version of Font Awesome,
// ===============================================================
// see example at src/hello_imgui_demos/hello_imgui_demo_fontawesome6
//
// The principle is summarized below:
// - Download Font_Awesome_6_Free-Solid-900.otf from https://fontawesome.com/download
// - Download IconsFontAwesome6.h from https://raw.githubusercontent.com/juliettef/IconFontCppHeaders/main/IconsFontAwesome6.h
//
// Code:
//
// // Prevent HelloImGui from loading Font Awesome 4 definitions, since we will load FontAwesome 6
// #define HELLOIMGUI_NO_FONT_AWESOME4
// #include "hello_imgui/hello_imgui.h"
// #include "IconsFontAwesome6.h"
//
// ...
//
// // Load the default font + merge it with Font Awesome 6
// HelloImGui::RunnerParams runnerParams;
// runnerParams.callbacks.LoadAdditionalFonts = []
// {
// // Load the default font
// HelloImGui::LoadFont("fonts/DroidSans.ttf", 15.0f);
//
// // Merge FontAwesome6 with the default font
// HelloImGui::FontLoadingParams fontParams;
// fontParams.mergeToLastFont = true;
// fontParams.useFullGlyphRange = true;
// HelloImGui::LoadFont("fonts/Font_Awesome_6_Free-Solid-900.otf", 15.0f, fontParams);
// };
```

----
Expand Down
4 changes: 3 additions & 1 deletion src/hello_imgui/doc_params.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ inline AnyEventCallback EmptyEventCallback() {return {}; }
## RunnerCallbacks
```cpp
// RunnerCallbacks is a struct that contains the callbacks
// that are called by the application
//
Expand Down Expand Up @@ -320,6 +319,9 @@ struct RunnerCallbacks
// (LoadDefaultFont_WithFontAwesome will load fonts from assets/fonts/
// but reverts to the ImGui embedded font if not found)
VoidFunction LoadAdditionalFonts = (VoidFunction)ImGuiDefaultSettings::LoadDefaultFont_WithFontAwesomeIcons;
// If LoadAdditionalFonts==LoadDefaultFont_WithFontAwesomeIcons, this parameter control
// which icon font will be loaded by default.
DefaultIconFont defaultIconFont = DefaultIconFont::FontAwesome4;
// `SetupImGuiConfig`: default=_ImGuiDefaultSettings::SetupDefaultImGuiConfig*.
// If needed, change ImGui config via SetupImGuiConfig
Expand Down
3 changes: 0 additions & 3 deletions src/hello_imgui/hello_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#include "hello_imgui/hello_imgui_assets.h"
#include "hello_imgui/hello_imgui_error.h"
#include "hello_imgui/hello_imgui_logger.h"
//#ifndef HELLOIMGUI_NO_FONT_AWESOME4
//#include "hello_imgui/icons_font_awesome_4.h"
//#endif
#include "hello_imgui/image_from_asset.h"
#include "hello_imgui/imgui_theme.h"
#include "hello_imgui/hello_imgui_font.h"
Expand Down
31 changes: 0 additions & 31 deletions src/hello_imgui/hello_imgui_font.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,6 @@ namespace HelloImGui
ImFont* LoadFont(const std::string & fontFilename, float fontSize,
const FontLoadingParams & params = {});


// Note: if you want to use a more recent version of Font Awesome,
// ===============================================================
// see example at src/hello_imgui_demos/hello_imgui_demo_fontawesome6
//
// The principle is summarized below:
// - Download Font_Awesome_6_Free-Solid-900.otf from https://fontawesome.com/download
// - Download IconsFontAwesome6.h from https://raw.githubusercontent.com/juliettef/IconFontCppHeaders/main/IconsFontAwesome6.h
//
// Code:
//
// // Prevent HelloImGui from loading Font Awesome 4 definitions, since we will load FontAwesome 6
// #define HELLOIMGUI_NO_FONT_AWESOME4
// #include "hello_imgui/hello_imgui.h"
// #include "IconsFontAwesome6.h"
//
// ...
//
// // Load the default font + merge it with Font Awesome 6
// HelloImGui::RunnerParams runnerParams;
// runnerParams.callbacks.LoadAdditionalFonts = []
// {
// // Load the default font
// HelloImGui::LoadFont("fonts/DroidSans.ttf", 15.0f);
//
// // Merge FontAwesome6 with the default font
// HelloImGui::FontLoadingParams fontParams;
// fontParams.mergeToLastFont = true;
// fontParams.useFullGlyphRange = true;
// HelloImGui::LoadFont("fonts/Font_Awesome_6_Free-Solid-900.otf", 15.0f, fontParams);
// };
// @@md


Expand Down
4 changes: 2 additions & 2 deletions src/hello_imgui/runner_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ std::string EdgeToolbarTypeName(EdgeToolbarType e);
// Breaking change in v1.5.0:
// - the default icon font is now FontAwesome 6, which includes many more icons.
// - you need to include manually icons_font_awesome_4.h or icons_font_awesome_6.h:
// #include "hello_imgui/icons_font_awesome_6.h"
// #include "hello_imgui/icons_font_awesome_6.h" or #include "hello_imgui/icons_font_awesome_4.h"
enum class DefaultIconFont
{
NoIcons,
Expand Down Expand Up @@ -191,7 +191,7 @@ struct RunnerCallbacks
VoidFunction LoadAdditionalFonts = (VoidFunction)ImGuiDefaultSettings::LoadDefaultFont_WithFontAwesomeIcons;
// If LoadAdditionalFonts==LoadDefaultFont_WithFontAwesomeIcons, this parameter control
// which icon font will be loaded by default.
DefaultIconFont defaultIconFont = DefaultIconFont::FontAwesome6;
DefaultIconFont defaultIconFont = DefaultIconFont::FontAwesome4;

// `SetupImGuiConfig`: default=_ImGuiDefaultSettings::SetupDefaultImGuiConfig*.
// If needed, change ImGui config via SetupImGuiConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "hello_imgui/hello_imgui.h"
#include "hello_imgui/icons_font_awesome_6.h"
#include "hello_imgui/icons_font_awesome_4.h"

int main(int, char *[]) {
int nb_cpp = 10, nb_cmake = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct AppState
//////////////////////////////////////////////////////////////////////////
void LoadFonts(AppState& appState) // This is called by runnerParams.callbacks.LoadAdditionalFonts
{
HelloImGui::GetRunnerParams()->callbacks.defaultIconFont = HelloImGui::DefaultIconFont::FontAwesome4;
HelloImGui::GetRunnerParams()->callbacks.defaultIconFont = HelloImGui::DefaultIconFont::FontAwesome6;
// First, load the default font (the default font should be loaded first)
HelloImGui::ImGuiDefaultSettings::LoadDefaultFont_WithFontAwesomeIcons();
// Then load the other fonts
Expand Down

0 comments on commit e89c10a

Please sign in to comment.