Skip to content

Commit

Permalink
Fix handling IMGUI_BUNDLE_DISABLE_IMPLOT & IMGUI_BUNDLE_DISABLE_IMGUI…
Browse files Browse the repository at this point in the history
…_NODE_EDITOR (fix #242)
  • Loading branch information
pthom committed Aug 27, 2024
1 parent a6ae1ad commit 226ecaa
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef IMGUI_BUNDLE_WITH_IMMVISION
#if defined(IMGUI_BUNDLE_WITH_IMMVISION) && defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
#include "hello_imgui/hello_imgui.h"
#include "immapp/immapp.h"
#include "imgui.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
#include "imgui-node-editor/imgui_node_editor.h"
#include "imgui_md_wrapper.h"
#include "immapp/immapp.h"
Expand Down Expand Up @@ -98,3 +99,7 @@ int main()

ImmApp::Run(runnerParams, addOnsParams);
}

#else // #if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
int main(){}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if defined(IMGUI_BUNDLE_WITH_IMPLOT) && defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
#include "imgui.h"
#include "imgui-node-editor/imgui_node_editor.h"
#include "implot/implot.h"
Expand Down Expand Up @@ -43,3 +44,7 @@ int main(int, char**)
addons_params.withNodeEditor = true;
ImmApp::Run(runner_params, addons_params);
}

#else // #if defined(IMGUI_BUNDLE_WITH_IMPLOT) && defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
int main(){}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
#include "imgui.h"
#include "immapp/immapp.h"
#include "imgui-node-editor/imgui_node_editor.h"
Expand Down Expand Up @@ -55,3 +56,6 @@ int main(int, char**)
ImmApp::Run(runnerParams, addOnsParams);
return 0;
}
#else // #if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
int main() {}
#endif
41 changes: 4 additions & 37 deletions bindings/imgui_bundle/demos_cpp/sandbox/sandnode_suspend.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
#include "immapp/immapp.h"
#include "imgui.h"
#include "hello_imgui/hello_imgui.h"
Expand Down Expand Up @@ -93,40 +94,6 @@ int main()
ImmApp::Run(runnerParams, addonsParams);
return 0;
}

/*
from imgui_bundle import imgui, immapp, hello_imgui, ImVec2, imgui_node_editor as ed
# poem = poem.replace("\n", "")
_node_id = ed.NodeId.create()
def gui():
global poem
ed.begin("Graph")
ed.begin_node(_node_id)
if imgui.button("O"):
imgui.open_popup("expandable_str_popup")
if imgui.begin_popup("expandable_str_popup"):
ed.suspend()
imgui.input_text_multiline("##value_text", poem, ImVec2(0, hello_imgui.em_size(15)))
ed.resume()
imgui.end_popup()
ed.end_node()
ed.end()
#imgui.input_text_multiline("poem", poem)
#imgui.text_wrapped(poem)
immapp.run(gui, with_node_editor=True)
*/
#else // #if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
int main(){}
#endif
13 changes: 10 additions & 3 deletions external/immapp/immapp/immapp_widgets.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include "immapp/immapp_widgets.h"
#include "hello_imgui/hello_imgui.h"
#ifdef IMGUI_BUNDLE_WITH_IMPLOT
#include "implot/implot.h"
#include "implot/implot_internal.h"
#endif
#ifdef IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR
#include "imgui-node-editor/imgui_node_editor.h"
#include "imgui-node-editor/imgui_node_editor_internal.h"
#endif

namespace ImmApp
{
#if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
namespace ed = ax::NodeEditor;

static void DisableUserInputInNodeEditor()
Expand All @@ -16,8 +21,9 @@ namespace ImmApp
if (nodeContext)
nodeContext->DisableUserInputThisFrame();
}
#endif // #if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)


#if defined(IMGUI_BUNDLE_WITH_IMPLOT) && defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
bool BeginPlotInNodeEditor(const char* title_id, const ImVec2& size, ImPlotFlags flags)
{
ImPlot::GetCurrentContext()->CanDragPlotInNodeEditor = true;
Expand Down Expand Up @@ -78,8 +84,9 @@ namespace ImmApp
ImVec2 new_size_em = HelloImGui::PixelsToEm(new_size_pixels);
return new_size_em;
}
#endif // #if defined(IMGUI_BUNDLE_WITH_IMPLOT) && defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)


#if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
ImVec2 WidgetWithResizeHandle_InNodeEditor(
const char* id,
VoidFunction guiFunction, // your function to draw the widget
Expand Down Expand Up @@ -108,5 +115,5 @@ namespace ImmApp
ImVec2 new_size_em = HelloImGui::PixelsToEm(new_size_pixels);
return new_size_em;
}

#endif // #if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
}
7 changes: 6 additions & 1 deletion external/immapp/immapp/immapp_widgets.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "imgui.h"
#ifdef IMGUI_BUNDLE_WITH_IMPLOT
#include "implot/implot.h"
#endif

#include <functional>

Expand All @@ -9,6 +11,7 @@ namespace ImmApp
{
using VoidFunction = std::function<void(void)>;

#if defined(IMGUI_BUNDLE_WITH_IMPLOT) && defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
// These functions wrap ImPlot::BeginPlot and ImPlot::EndPlot,
// but they enable to make the plot content draggable inside a node
bool BeginPlotInNodeEditor(const char* title_id, const ImVec2& size=ImVec2(-1,0), ImPlotFlags flags=0);
Expand All @@ -33,7 +36,9 @@ namespace ImmApp
ImPlotFlags flags=0,
float resizeHandleSizeEm=1.0f
);
#endif // #if defined(IMGUI_BUNDLE_WITH_IMPLOT) && defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)

#if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
// WidgetWithResizeHandle_InNodeEditor: shows a resizable widget inside a node
// Returns the new size of the widget.
ImVec2 WidgetWithResizeHandle_InNodeEditor(
Expand All @@ -49,5 +54,5 @@ namespace ImmApp
VoidFunction guiFunction, // your function to draw the widget
float resizeHandleSizeEm=1.0f
);

#endif // #if defined(IMGUI_BUNDLE_WITH_IMGUI_NODE_EDITOR)
}

0 comments on commit 226ecaa

Please sign in to comment.