Skip to content

Commit

Permalink
demodocking add: U8_TO_CHAR
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jan 3, 2024
1 parent fcce43a commit 5c2c49c
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ It demonstrates how to:

#include <sstream>

// Poor man's fix for C++ late arrival in the unicode party:
// - C++17: u8"my string" is of type const char*
// - C++20: u8"my string" is of type const char8_t*
// However, ImGui text functions expect const char*.
#ifdef __cpp_char8_t
#define U8_TO_CHAR(x) reinterpret_cast<const char*>(x)
#else
#define U8_TO_CHAR(x) x
#endif


//////////////////////////////////////////////////////////////////////////
// Our Application State
Expand Down Expand Up @@ -315,20 +325,20 @@ void DemoFonts(AppState& appState)
{
ImGui::PushFont(appState.EmojiFont);
// ✌️ (Victory Hand Emoji)
ImGui::Text("\U0000270C\U0000FE0F");
ImGui::Text(U8_TO_CHAR(u8"\U0000270C\U0000FE0F"));
ImGui::SameLine();

// ❤️ (Red Heart Emoji)
ImGui::Text("\U00002764\U0000FE0F");
ImGui::Text(U8_TO_CHAR(u8"\U00002764\U0000FE0F"));
ImGui::SameLine();

#ifdef IMGUI_USE_WCHAR32
// 🌴 (Palm Tree Emoji)
ImGui::Text("\U0001F334");
ImGui::Text(U8_TO_CHAR(u8"\U0001F334"));
ImGui::SameLine();

// 🚀 (Rocket Emoji)
ImGui::Text("\U0001F680");
ImGui::Text(U8_TO_CHAR(u8"\U0001F680"));
ImGui::SameLine();
#endif

Expand Down

0 comments on commit 5c2c49c

Please sign in to comment.