Skip to content

Commit

Permalink
Added image resize example code by @soufianekhiat - closes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
juliettef committed Jan 26, 2021
1 parent 7c8e827 commit 1aadefd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ inline ImGui::MarkdownImageData ImageCallback( ImGui::MarkdownLinkCallbackData d
imageData.useLinkCallback = false;
imageData.user_texture_id = image;
imageData.size = ImVec2( 40.0f, 20.0f );

// For image resize when available size.x > image width, add
ImVec2 const contentSize = ImGui::GetContentRegionAvail();
if( imageData.size.x > contentSize.x )
{
float const ratio = imageData.size.y/imageData.size.x;
imageData.size.x = contentSize.x;
imageData.size.y = contentSize.x*ratio;
}

return imageData;
}

Expand Down Expand Up @@ -230,8 +240,9 @@ Using imgui_markdown as help viewer for Visual 6502 Remix with internal and exte
## Credits
Design and implementation - [Doug Binks](http://www.enkisoftware.com/about.html#doug) - [@dougbinks](https://github.com/dougbinks)
Implementation and maintenance - [Juliette Foucaut](http://www.enkisoftware.com/about.html#juliette) - [@juliettef](https://github.com/juliettef)
Thanks to [Omar Cornut for Dear ImGui](https://github.com/ocornut/imgui).
Implementation and maintenance - [Juliette Foucaut](http://www.enkisoftware.com/about.html#juliette) - [@juliettef](https://github.com/juliettef)
[Image resize](https://github.com/juliettef/imgui_markdown/pull/15) example code - [Soufiane Khiat](https://github.com/soufianekhiat)
Thanks to [Omar Cornut for Dear ImGui](https://github.com/ocornut/imgui)
## License (zlib)
Expand Down
10 changes: 10 additions & 0 deletions imgui_markdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ inline ImGui::MarkdownImageData ImageCallback( ImGui::MarkdownLinkCallbackData d
imageData.useLinkCallback = false;
imageData.user_texture_id = image;
imageData.size = ImVec2( 40.0f, 20.0f );
// For image resize when available size.x > image width, add
ImVec2 const contentSize = ImGui::GetContentRegionAvail();
if( imageData.size.x > contentSize.x )
{
float const ratio = imageData.size.y/imageData.size.x;
imageData.size.x = contentSize.x;
imageData.size.y = contentSize.x*ratio;
}
return imageData;
}
Expand Down

0 comments on commit 1aadefd

Please sign in to comment.