Skip to content

Commit

Permalink
Fixed minor issues with example code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dougbinks committed Oct 21, 2020
1 parent d1b2680 commit 7c8e827
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ static ImFont* H1 = NULL;
static ImFont* H2 = NULL;
static ImFont* H3 = NULL;

static ImGui::MarkdownConfig mdConfig;


void LinkCallback( ImGui::MarkdownLinkCallbackData data_ )
{
std::string url( data_.link, data_.linkLength );
Expand All @@ -101,7 +104,7 @@ inline ImGui::MarkdownImageData ImageCallback( ImGui::MarkdownLinkCallbackData d
// In your application you would load an image based on data_ input. Here we just use the imgui font texture.
ImTextureID image = ImGui::GetIO().Fonts->TexID;
// > C++14 can use ImGui::MarkdownImageData imageData{ true, false, image, ImVec2( 40.0f, 20.0f ) };
MarkdownImageData imageData;
ImGui::MarkdownImageData imageData;
imageData.isValid = true;
imageData.useLinkCallback = false;
imageData.user_texture_id = image;
Expand All @@ -123,7 +126,7 @@ void LoadFonts( float fontSize_ = 12.0f )
H1 = io.Fonts->AddFontFromFileTTF( "myfont-bold.ttf", fontSizeH1 );
}

void ExampleMarkdownFormatCallback( const MarkdownFormatInfo& markdownFormatInfo_, bool start_ )
void ExampleMarkdownFormatCallback( const ImGui::MarkdownFormatInfo& markdownFormatInfo_, bool start_ )
{
// Call the default first so any settings can be overwritten by our implementation.
// Alternatively could be called or not called in a switch statement on a case by case basis.
Expand All @@ -133,7 +136,7 @@ void ExampleMarkdownFormatCallback( const MarkdownFormatInfo& markdownFormatInfo
switch( markdownFormatInfo_.type )
{
// example: change the colour of heading level 2
case MarkdownFormatType::HEADING:
case ImGui::MarkdownFormatType::HEADING:
{
if( markdownFormatInfo_.level == 2 )
{
Expand All @@ -159,7 +162,6 @@ void Markdown( const std::string& markdown_ )
{
// You can make your own Markdown function with your prefered string container and markdown config.
// > C++14 can use ImGui::MarkdownConfig mdConfig{ LinkCallback, NULL, ImageCallback, ICON_FA_LINK, { { H1, true }, { H2, true }, { H3, false } }, NULL };
MarkdownConfig mdConfig;
mdConfig.linkCallback = LinkCallback;
mdConfig.tooltipCallback = NULL;
mdConfig.imageCallback = ImageCallback;
Expand Down
10 changes: 6 additions & 4 deletions imgui_markdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ static ImFont* H1 = NULL;
static ImFont* H2 = NULL;
static ImFont* H3 = NULL;
static ImGui::MarkdownConfig mdConfig;
void LinkCallback( ImGui::MarkdownLinkCallbackData data_ )
{
std::string url( data_.link, data_.linkLength );
Expand All @@ -106,7 +109,7 @@ inline ImGui::MarkdownImageData ImageCallback( ImGui::MarkdownLinkCallbackData d
// In your application you would load an image based on data_ input. Here we just use the imgui font texture.
ImTextureID image = ImGui::GetIO().Fonts->TexID;
// > C++14 can use ImGui::MarkdownImageData imageData{ true, false, image, ImVec2( 40.0f, 20.0f ) };
MarkdownImageData imageData;
ImGui::MarkdownImageData imageData;
imageData.isValid = true;
imageData.useLinkCallback = false;
imageData.user_texture_id = image;
Expand All @@ -128,7 +131,7 @@ void LoadFonts( float fontSize_ = 12.0f )
H1 = io.Fonts->AddFontFromFileTTF( "myfont-bold.ttf", fontSizeH1 );
}
void ExampleMarkdownFormatCallback( const MarkdownFormatInfo& markdownFormatInfo_, bool start_ )
void ExampleMarkdownFormatCallback( const ImGui::MarkdownFormatInfo& markdownFormatInfo_, bool start_ )
{
// Call the default first so any settings can be overwritten by our implementation.
// Alternatively could be called or not called in a switch statement on a case by case basis.
Expand All @@ -138,7 +141,7 @@ void ExampleMarkdownFormatCallback( const MarkdownFormatInfo& markdownFormatInfo
switch( markdownFormatInfo_.type )
{
// example: change the colour of heading level 2
case MarkdownFormatType::HEADING:
case ImGui::MarkdownFormatType::HEADING:
{
if( markdownFormatInfo_.level == 2 )
{
Expand All @@ -164,7 +167,6 @@ void Markdown( const std::string& markdown_ )
{
// You can make your own Markdown function with your prefered string container and markdown config.
// > C++14 can use ImGui::MarkdownConfig mdConfig{ LinkCallback, NULL, ImageCallback, ICON_FA_LINK, { { H1, true }, { H2, true }, { H3, false } }, NULL };
MarkdownConfig mdConfig;
mdConfig.linkCallback = LinkCallback;
mdConfig.tooltipCallback = NULL;
mdConfig.imageCallback = ImageCallback;
Expand Down

0 comments on commit 7c8e827

Please sign in to comment.