Skip to content

Commit

Permalink
update imgui_md ([Bundle]: imgui_md::BLOCK_CODE: do not use ImGuiColo…
Browse files Browse the repository at this point in the history
…rTextEdit in node editor), cf #281
  • Loading branch information
pthom committed Nov 21, 2024
1 parent d8d7c55 commit 1a40c5e
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
63 changes: 63 additions & 0 deletions bindings/imgui_bundle/demos_cpp/sandbox/sandbox_node_md_code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifdef IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR
#include "immapp/immapp.h"
#include "imgui.h"
#include "misc/cpp/imgui_stdlib.h"
#include "imgui_md_wrapper/imgui_md_wrapper.h"
#include "imgui-node-editor/imgui_node_editor.h"


namespace ed = ax::NodeEditor;

void Gui()
{
ImGuiMd::RenderUnindented(R"(
Below is a code block rendered in markdown outside of a node editor: it should use ImGuiColorTextEdit
```cpp
// This is a code block
int main() {
return 0;
}
```
)");

ed::Begin("My Node Editor");
ed::BeginNode(1);

ImGui::Dummy(ImVec2(500, 0));
ImGuiMd::RenderUnindented(R"(
Below is a code block rendered in markdown inside a node editor:
it should not use ImGuiColorTextEdit, but instead render as a simple code block,
with no syntax highlighting (but using a code font).
```cpp
// This is a code block
int main() {
return 0;
}
```
)");

ed::EndNode();
ed::End();
}


int main(int, char**)
{
HelloImGui::RunnerParams runnerParams;
ImmApp::AddOnsParams addOnsParams;
runnerParams.callbacks.ShowGui = Gui;
addOnsParams.withMarkdown = true;

// important: force the window content width to be the same as the node width
addOnsParams.withNodeEditor = true;
addOnsParams.withNodeEditorConfig = ed::Config();
addOnsParams.withNodeEditorConfig->ForceWindowContentWidthToNodeWidth = true;

ImmApp::Run(runnerParams, addOnsParams);
return 0;
}
#else
int main() {}
#endif
46 changes: 46 additions & 0 deletions bindings/imgui_bundle/demos_python/sandbox/sandbox_node_md_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from imgui_bundle import immapp, imgui, imgui_md, imgui_node_editor as ed, ImVec2


def gui():
imgui_md.render_unindented("""
Below is a code block rendered in markdown outside of a node editor: it should use ImGuiColorTextEdit
```cpp
// This is a code block
int main() {
return 0;
}
""")

ed.begin("My Node Editor")
ed.begin_node(ed.NodeId(1))
imgui.dummy(ImVec2(500, 0))
imgui_md.render_unindented("""
Below is a code block rendered in markdown inside a node editor:
it should not use ImGuiColorTextEdit, but instead render as a simple code block,
with no syntax highlighting (but using a code font).
```cpp
// This is a code block
int main() {
return 0;
}
""")
ed.end_node()
ed.end()


def main():
runner_params = immapp.RunnerParams()
runner_params.callbacks.show_gui = gui
add_ons_params = immapp.AddOnsParams()
add_ons_params.with_markdown = True

# important: force the window content width to be the same as the node width
add_ons_params.with_node_editor = True
add_ons_params.with_node_editor_config = ed.Config()
add_ons_params.with_node_editor_config.force_window_content_width_to_node_width = True

immapp.run(runner_params, add_ons_params)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion external/imgui_md/imgui_md
Submodule imgui_md updated 1 files
+9 −2 imgui_md.cpp

0 comments on commit 1a40c5e

Please sign in to comment.