#pragma once #include "AftrImGuiIncludes.h" #include "imgui/imgui_markdown/imgui_markdown.h" #include //ICONS are in "src/imgui/imgui_markdown/IconsFontAwesome6.h" //https://github.com/juliettef/IconFontCppHeaders //SLN: Want to search for all the available ICONS??? //Look at this link (we only support "SOLID" right now) //https://fontawesome.com/icons/categories/maps namespace Aftr { class AftrImGui_Markdown_Renderer; //forward declaration //This is the easiest, move convienient way to render markdown. This object simply pairs //a Markdown_Renderer with a string containing a markdown document. to Simply create one of //these objects via its constructor. Then each frame call .draw_markdown() where you //would like the Markdown to appear. class AftrImGui_Markdown_Doc { public: //AftrImGui_Markdown_Doc( std::string markdown_doc ); AftrImGui_Markdown_Doc( std::filesystem::path const& path_to_markdown_document ); ~AftrImGui_Markdown_Doc() = default; std::string const& getMarkdownText() const noexcept { return this->markdown_text; } private: std::string markdown_text; }; //Draws the specified Markdown text at the current ImGui cursor location. //This can be manually called if desired; however, the simplest way to make markdown render is to //create an instance of AftrImGui_Markdown_Renderer by calling Aftr::make_default_MarkdownRenderer() //and then invoking AftrImGui_Markdown_Renderer::draw_markdown( str ) or draw_markdown_demo(), //here is an example to draw the demo and then draw a md string named myMarkdownStr. // // EASIEST WAY TO DRAW MARKDOWN EXAMPLE: //AftrImGui_Markdown_Renderer r{ make_default_MarkdownRenderer() }; //r.draw_markdown_demo(); //just draws the built in demo //r.draw_markdown( myMarkdownStr ); //draws the contents of myMarkdownStr as a markdown document // //Another example of loading a markdown document from a text file: //AftrImGui_Markdown_Renderer r{ make_default_MarkdownRenderer() }; //AftrImGui_Markdown_Doc doc{ std::filesystem::path{ "/home/user/myMarkdownDoc.md" } }; //r.draw_markdown( doc ); void draw_markdown( std::string const& text_with_markdown, ImGui::MarkdownConfig const& mdConfig ); void draw_markdown( AftrImGui_Markdown_Renderer const& renderer, std::string const& text_with_markdown ); //wrapper that calls AftrImGui_Markdown_Renderer::draw_markdown void draw_markdown( AftrImGui_Markdown_Renderer const& renderer, AftrImGui_Markdown_Doc const& markdown_doc ); //wrapper that calls AftrImGui_Markdown_Renderer::draw_markdown AftrImGui_Markdown_Renderer make_default_MarkdownRenderer( float fontSize = 16.0f ); ImGui::MarkdownConfig make_default_MardownConfig( float fontSize = 16.0f ); class AftrImGui_Markdown_Renderer { public: //Draws the in passed markdown text using the MarkdownConfig set in this class instance (this->cfg). void draw_markdown( std::string const& text_with_markdown ) const; //Same as above but takes as input a Markdown_Doc that owns its text. This text can be either loaded //from a file or set as an input parameter via the constructor. It may be more convenient to store a //std::vector if loading strings from file or dynamics strings, or a mixture //of the two. void draw_markdown( AftrImGui_Markdown_Doc const& markdown_doc ) const; //Draws a Demo showing off Markdown in AftrBurner, one can call this instead of passing //in their own markdown string. void draw_markdown_demo() const; //To easily create a AftrImGui_Markdown_Renderer, simply call //auto md = Aftr::make_default_MarkdownRenderer(); AftrImGui_Markdown_Renderer( ImGui::MarkdownConfig&& mdConfig ); ~AftrImGui_Markdown_Renderer() = default; ImGui::MarkdownConfig cfg; }; //Callbacks that can be customized by changing the MarkdownConfig cfg; //Called when a link to a url is clicked. Will popup a box showing the URL path with link icon void LinkCallback( ImGui::MarkdownLinkCallbackData data_ ); //Called when an image is to be rendered inside a markdown string ImGui::MarkdownImageData ImageCallback( ImGui::MarkdownLinkCallbackData data_ ); }