Skip to content

Commit

Permalink
Add demo + doc / FontAwesome 6
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jan 30, 2024
1 parent 2fa9569 commit 133e2a0
Show file tree
Hide file tree
Showing 8 changed files with 1,475 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hello_imgui/hello_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#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.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: 31 additions & 0 deletions src/hello_imgui/hello_imgui_font.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace HelloImGui

// if true, the font will be loaded and then FontAwesome icons will be merged to it
// (deprecated, use mergeToLastFont instead, and load in two steps)
// This will use an old version of FontAwesome (FontAwesome 4)
bool mergeFontAwesome = false;
ImFontConfig fontConfigFontAwesome = ImFontConfig();
};
Expand All @@ -62,6 +63,36 @@ namespace HelloImGui
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, since we will load FontAwesome
// #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
1 change: 1 addition & 0 deletions src/hello_imgui_demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(subdirs
hello_idbfs
hello_imgui_demo_test_engine
hello_custom_background
hello_imgui_demo_fontawesome6
)
if(HELLOIMGUI_HAS_METAL)
# Demo of EDR (Extended Dynamic Range) support, only for Metal
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include(hello_imgui_add_app)
hello_imgui_add_app(hello_imgui_demo_fontawesome6 hello_imgui_demo_fontawesome6.cpp)
1,401 changes: 1,401 additions & 0 deletions src/hello_imgui_demos/hello_imgui_demo_fontawesome6/IconsFontAwesome6.h

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Prevent HelloImGui from loading Font Awesome, since we will load FontAwesome
#define HELLOIMGUI_NO_FONT_AWESOME4
#include "hello_imgui/hello_imgui.h"

// Found at https://raw.githubusercontent.com/juliettef/IconFontCppHeaders/main/IconsFontAwesome6.h
#include "IconsFontAwesome6.h"

#include "imgui.h"


int main()
{
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);
};

auto gui = []() {

ImGui::Text("Hello, world!" );
ImGui::Text(ICON_FA_FACE_SMILE);
ImGui::Text(ICON_FA_LAYER_GROUP);
ImGui::Text(ICON_FA_ADDRESS_CARD);
};

runnerParams.callbacks.ShowGui = gui;

HelloImGui::Run(runnerParams);
}

0 comments on commit 133e2a0

Please sign in to comment.