-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update imgui_md ([Bundle]: imgui_md::BLOCK_CODE: do not use ImGuiColo…
…rTextEdit in node editor), cf #281
- Loading branch information
Showing
3 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
bindings/imgui_bundle/demos_cpp/sandbox/sandbox_node_md_code.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
bindings/imgui_bundle/demos_python/sandbox/sandbox_node_md_code.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |