Commit 4597fa04 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

imnodes: bump to 0.3

parent 9587ffc1
Pipeline #16377 passed with stage
in 1 minute and 10 seconds
This diff is collapsed.
/*
* MIT License
*
* Copyright (c) 2019 Johann Muszynski
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef NELARIUS_IMNODES_IMGUI_IMNODES_H
#define NELARIUS_IMNODES_IMGUI_IMNODES_H
#pragma once
#include <stddef.h>
#if defined(__GNUC__) || defined(__clang__)
#define DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED __declspec(deprecated)
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED
#endif
struct ImVec2;
namespace imnodes {
......@@ -85,7 +69,15 @@ enum AttributeFlags
// is connected to. NOTE: the user has to actually delete the link for this
// to work. A deleted link can be detected by calling IsLinkDestroyed()
// after EndNodeEditor().
AttributeFlags_EnableLinkDetachWithDragClick = 1 << 0
AttributeFlags_EnableLinkDetachWithDragClick = 1 << 0,
// Visual snapping of an in progress link will trigger IsLink
// Created/Destroyed events. Allows for previewing the creation of a link
// while dragging it across attributes. See here for demo:
// https://github.com/Nelarius/imnodes/issues/41#issuecomment-647132113
// NOTE: the user has to actually delete the link for this to work. A
// deleted link can be detected by calling IsLinkDestroyed() after
// EndNodeEditor().
AttributeFlags_EnableLinkCreationOnSnap = 1 << 1
};
struct IO
......@@ -165,8 +157,8 @@ struct Style
// An editor context corresponds to a set of nodes in a single workspace
// (created with a single Begin/EndNodeEditor pair)
//
// By default, the library creates an editor context behind the scenes, so
// using any of the imnodes functions doesn't require you to explicitly create a
// By default, the library creates an editor context behind the scenes, so using
// any of the imnodes functions doesn't require you to explicitly create a
// context.
struct EditorContext;
......@@ -235,19 +227,35 @@ BeginNodeTitleBar();
void
EndNodeTitleBar();
// Attributes are ImGui UI elements embedded within the node. Attributes have
// pin shapes rendered next to them. Links are created between pins.
// Attributes are ImGui UI elements embedded within the node. Attributes can
// have pin shapes rendered next to them. Links are created between pins.
//
// Input and output attributes are otherwise identical, except that pins are
// rendered on the left side of the node for input attributes, and on the right
// side for output attributes.
// The activity status of an attribute can be checked via the
// IsAttributeActive() and IsAnyAttributeActive() function calls. This is one
// easy way of checking for any changes made to an attribute's drag float UI,
// for instance.
//
// The attribute ids must be unique.
// Each attribute id must be unique.
// Create an input attribute block. The pin is rendered on left side.
void
BeginInputAttribute(int id, PinShape shape = PinShape_CircleFilled);
void
EndInputAttribute();
// Create an output attribute block. The pin is rendered on the right side.
void
BeginOutputAttribute(int id, PinShape shape = PinShape_CircleFilled);
void
EndOutputAttribute();
// Create a static attribute block. A static attribute has no pin, and therefore
// can't be linked to anything. However, you can still use IsAttributeActive()
// and IsAnyAttributeActive() to check for attribute activity.
void
BeginStaticAttribute(int id);
void
EndStaticAttribute();
// Can still be used with any of the three previous Begin{*}Attribute functions.
DEPRECATED void
EndAttribute();
// Push a single AttributeFlags value. By default, only AttributeFlags_None is
......@@ -272,12 +280,6 @@ void
SetNodeScreenSpacePos(int node_id, const ImVec2& screen_space_pos);
void
SetNodeGridSpacePos(int node_id, const ImVec2& grid_pos);
ImVec2
GetNodeScreenSpacePos(int node_id);
ImVec2
GetNodeGridSpacePos(int node_id);
// Enable or disable the ability to click and drag a specific node.
void
SetNodeDraggable(int node_id, const bool draggable);
......@@ -310,9 +312,6 @@ GetSelectedNodes(int* node_ids);
void
GetSelectedLinks(int* link_ids);
void
ClearSelectedNodesAndLinks();
// Was the previous attribute active? This will continuously return true while
// the left mouse button is being pressed over the UI content of the attribute.
bool
......@@ -329,11 +328,19 @@ IsAnyAttributeActive(int* attribute_id = 0);
bool
IsLinkStarted(int* started_at_attribute_id);
// Did the user drop the dragged link before attaching it to a pin?
// There are two different kinds of situations to consider when handling this
// event: 1) a link which is created at a pin and then dropped 2) an existing
// link which is detached from a pin and then dropped Use the
// including_detached_links flag to control whether this function triggers when
// the user detaches a link and drops it.
bool
IsLinkDropped();
IsLinkDropped(int* started_at_attribute_id = 0,
bool including_detached_links = true);
// Did the user finish creating a new link?
bool
IsLinkCreated(int* started_at_attribute_id, int* ended_at_attribute_id);
IsLinkCreated(int* started_at_attribute_id,
int* ended_at_attribute_id,
bool* created_from_snap = 0);
// Was an existing link detached from a pin by the user? The detached link's id
// is assigned to the output argument link_id.
bool
......@@ -366,5 +373,3 @@ LoadCurrentEditorStateFromIniFile(const char* file_name);
void
LoadEditorStateFromIniFile(EditorContext* editor, const char* file_name);
} // namespace imnodes
#endif
\ No newline at end of file
......@@ -1428,7 +1428,7 @@ editor::show_model_cluster(cluster& mdl) noexcept
if (auto* port = sim.input_ports.try_to_get(*it); port) {
imnodes::BeginInputAttribute(get_in(*it));
ImGui::TextUnformatted(port->name.c_str());
imnodes::EndAttribute();
imnodes::EndInputAttribute();
++it;
} else {
it = mdl.input_ports.erase(it);
......@@ -1444,7 +1444,7 @@ editor::show_model_cluster(cluster& mdl) noexcept
if (auto* port = sim.output_ports.try_to_get(*it); port) {
imnodes::BeginOutputAttribute(get_out(*it));
ImGui::TextUnformatted(port->name.c_str());
imnodes::EndAttribute();
imnodes::EndOutputAttribute();
++it;
} else {
it = mdl.output_ports.erase(it);
......@@ -1617,7 +1617,7 @@ add_input_attribute(editor& ed, const Dynamics& dyn) noexcept
for (size_t i = 0, e = std::size(dyn.x); i != e; ++i) {
imnodes::BeginInputAttribute(ed.get_in(dyn.x[i]));
ImGui::TextUnformatted(names[i]);
imnodes::EndAttribute();
imnodes::EndInputAttribute();
}
}
}
......@@ -1632,7 +1632,7 @@ add_output_attribute(editor& ed, const Dynamics& dyn) noexcept
for (size_t i = 0, e = std::size(dyn.y); i != e; ++i) {
imnodes::BeginOutputAttribute(ed.get_out(dyn.y[i]));
ImGui::TextUnformatted(names[i]);
imnodes::EndAttribute();
imnodes::EndOutputAttribute();
}
}
}
......@@ -2709,23 +2709,23 @@ editor::show_editor() noexcept
imnodes::GetSelectedNodes(selected_nodes.begin());
log_w.log(7, "%d model(s) to delete\n", num_selected_nodes);
free_children(selected_nodes);
imnodes::ClearSelectedNodesAndLinks();
// imnodes::ClearSelectedNodesAndLinks();
} else if (ImGui::IsKeyReleased('D')) {
imnodes::GetSelectedNodes(selected_nodes.begin());
log_w.log(7, "%d model(s)/group(s) to copy\n", num_selected_nodes);
copy(selected_nodes);
imnodes::ClearSelectedNodesAndLinks();
// imnodes::ClearSelectedNodesAndLinks();
} else if (ImGui::IsKeyReleased('G')) {
if (num_selected_nodes > 1) {
imnodes::GetSelectedNodes(selected_nodes.begin());
log_w.log(7, "%d model(s) to group\n", num_selected_nodes);
group(selected_nodes);
imnodes::ClearSelectedNodesAndLinks();
// imnodes::ClearSelectedNodesAndLinks();
} else if (num_selected_nodes == 1) {
imnodes::GetSelectedNodes(selected_nodes.begin());
log_w.log(7, "group to ungroup\n");
ungroup(selected_nodes[0]);
imnodes::ClearSelectedNodesAndLinks();
// imnodes::ClearSelectedNodesAndLinks();
}
}
selected_nodes.resize(0);
......@@ -2765,7 +2765,7 @@ editor::show_editor() noexcept
}
}
}
imnodes::ClearSelectedNodesAndLinks();
// imnodes::ClearSelectedNodesAndLinks();
selected_links.resize(0);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment