File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -310,6 +310,8 @@ namespace ImFlow
310310 template <typename T, typename ... Params>
311311 std::shared_ptr<T> addNode (const ImVec2& pos, Params&&... args);
312312
313+ void emplaceNode (const ImVec2& pos, const std::shared_ptr<BaseNode>& node);
314+
313315 private:
314316 /* *
315317 * @brief <BR>Helper struct for creating a node struct from a lambda
@@ -385,6 +387,13 @@ namespace ImFlow
385387 */
386388 void rightClickPopUpContent (std::function<void (BaseNode* node)> content) { m_rightClickPopUp = std::move (content); }
387389
390+ /* *
391+ * @brief <BR>Pop-up when drag_dropping
392+ * @details Sets the node pos when drag dropping a node to the grid
393+ * @param content Function or Lambda containing only the pos of the mouse when clicked
394+ */
395+ void dragDropTarget (std::function<void (const ImVec2 &)> content) { m_dragdropTarget = std::move (content); }
396+
388397 /* *
389398 * @brief <BR>Get mouse clicking status
390399 * @return [TRUE] if mouse is clicked and click hasn't been consumed
@@ -522,6 +531,7 @@ namespace ImFlow
522531 ImGuiKey m_droppedLinkPupUpComboKey = ImGuiKey_None;
523532 Pin* m_droppedLinkLeft = nullptr ;
524533 std::function<void (BaseNode* node)> m_rightClickPopUp;
534+ std::function<void (const ImVec2 &)> m_dragdropTarget;
525535 BaseNode* m_hoveredNodeAux = nullptr ;
526536
527537 BaseNode* m_hoveredNode = nullptr ;
Original file line number Diff line number Diff line change @@ -239,6 +239,18 @@ namespace ImFlow {
239239 m_links.push_back (link);
240240 }
241241
242+ void ImNodeFlow::emplaceNode (const ImVec2& pos, const std::shared_ptr<BaseNode>& n)
243+ {
244+ n->setPos (pos);
245+ n->setHandler (this );
246+ if (!n->getStyle ())
247+ n->setStyle (NodeStyle::cyan ());
248+
249+ auto uid = reinterpret_cast <uintptr_t >(n.get ());
250+ n->setUID (uid);
251+ m_nodes[uid] = n;
252+ }
253+
242254 void ImNodeFlow::update () {
243255 // Updating looping stuff
244256 m_hovering = nullptr ;
@@ -335,5 +347,13 @@ namespace ImFlow {
335347 m_pinRecursionBlacklist.clear ();
336348
337349 m_context.end ();
350+
351+ if (ImGui::BeginDragDropTarget ())
352+ {
353+ if (m_dragdropTarget)
354+ m_dragdropTarget (screen2grid (ImGui::GetMousePos ()));
355+
356+ ImGui::EndDragDropTarget ();
357+ }
338358 }
339359}
You can’t perform that action at this time.
0 commit comments