@mori2003/jsimgui
Version:
JavaScript bindings for Dear ImGui.
536 lines (535 loc) • 19.1 kB
JavaScript
// @ts-nocheck
// [EXPERIMENTAL | INCOMPLETE]
// Manually written bindings for imnodes:
// https://github.com/Nelarius/imnodes using version `b2ec254`
import { Mod, ReferenceStruct, ImVec2 } from "./imgui.js";
export const ImNodesCol = {
NodeBackground: 0,
NodeBackgroundHovered: 1,
NodeBackgroundSelected: 2,
NodeOutline: 3,
TitleBar: 4,
TitleBarHovered: 5,
TitleBarSelected: 6,
Link: 7,
LinkHovered: 8,
LinkSelected: 9,
Pin: 10,
PinHovered: 11,
BoxSelector: 12,
BoxSelectorOutline: 13,
GridBackground: 14,
GridLine: 15,
GridLinePrimary: 16,
MiniMapBackground: 17,
MiniMapBackgroundHovered: 18,
MiniMapOutline: 19,
MiniMapOutlineHovered: 20,
MiniMapNodeBackground: 21,
MiniMapNodeBackgroundHovered: 22,
MiniMapNodeBackgroundSelected: 23,
MiniMapNodeOutline: 24,
MiniMapLink: 25,
MiniMapLinkSelected: 26,
MiniMapCanvas: 27,
MiniMapCanvasOutline: 28,
COUNT: 29,
};
export const ImNodesStyleVar = {
GridSpacing: 0,
NodeCornerRounding: 1,
NodePadding: 2,
NodeBorderThickness: 3,
LinkThickness: 4,
LinkLineSegmentsPerLength: 5,
LinkHoverDistance: 6,
PinCircleRadius: 7,
PinQuadSideLength: 8,
PinTriangleSideLength: 9,
PinLineThickness: 10,
PinHoverRadius: 11,
PinOffset: 12,
MiniMapPadding: 13,
MiniMapOffset: 14,
COUNT: 15,
};
export const ImNodesStyleFlags = {
None: 0,
NodeOutline: 1 << 0,
GridLines: 1 << 2,
GridLinesPrimary: 1 << 3,
GridSnapping: 1 << 4,
};
export const ImNodesPinShape = {
Circle: 0,
CircleFilled: 1,
Triangle: 2,
TriangleFilled: 3,
Quad: 4,
QuadFilled: 5,
};
export const ImNodesAttributeFlags = {
None: 0,
EnableLinkDetachWithDragClick: 1 << 0,
EnableLinkCreationOnSnap: 1 << 1,
};
export const ImNodesMiniMapLocation = {
BottomLeft: 0,
BottomRight: 1,
TopLeft: 2,
TopRight: 3,
};
export class ImNodesContext extends ReferenceStruct {
}
export class ImNodesEditorContext extends ReferenceStruct {
}
export class ImNodesIO extends ReferenceStruct {
get AltMouseButton() {
return this.ptr.get_AltMouseButton();
}
set AltMouseButton(v) {
this.ptr.set_AltMouseButton(v);
}
get AutoPanningSpeed() {
return this.ptr.get_AutoPanningSpeed();
}
set AutoPanningSpeed(v) {
this.ptr.set_AutoPanningSpeed(v);
}
}
export class ImNodesStyle extends ReferenceStruct {
get GridSpacing() {
return this.ptr.get_GridSpacing();
}
set GridSpacing(v) {
this.ptr.set_GridSpacing(v);
}
get NodeCornerRounding() {
return this.ptr.get_NodeCornerRounding();
}
set NodeCornerRounding(v) {
this.ptr.set_NodeCornerRounding(v);
}
get NodePadding() {
return ImVec2.From(this.ptr.get_NodePadding());
}
set NodePadding(v) {
this.ptr.set_NodePadding(v);
}
get NodeBorderThickness() {
return this.ptr.get_NodeBorderThickness();
}
set NodeBorderThickness(v) {
this.ptr.set_NodeBorderThickness(v);
}
get LinkThickness() {
return this.ptr.get_LinkThickness();
}
set LinkThickness(v) {
this.ptr.set_LinkThickness(v);
}
get LinkLineSegmentsPerLength() {
return this.ptr.get_LinkLineSegmentsPerLength();
}
set LinkLineSegmentsPerLength(v) {
this.ptr.set_LinkLineSegmentsPerLength(v);
}
get LinkHoverDistance() {
return this.ptr.get_LinkHoverDistance();
}
set LinkHoverDistance(v) {
this.ptr.set_LinkHoverDistance(v);
}
get PinCircleRadius() {
return this.ptr.get_PinCircleRadius();
}
set PinCircleRadius(v) {
this.ptr.set_PinCircleRadius(v);
}
get PinQuadSideLength() {
return this.ptr.get_PinQuadSideLength();
}
set PinQuadSideLength(v) {
this.ptr.set_PinQuadSideLength(v);
}
get PinTriangleSideLength() {
return this.ptr.get_PinTriangleSideLength();
}
set PinTriangleSideLength(v) {
this.ptr.set_PinTriangleSideLength(v);
}
get PinLineThickness() {
return this.ptr.get_PinLineThickness();
}
set PinLineThickness(v) {
this.ptr.set_PinLineThickness(v);
}
get PinHoverRadius() {
return this.ptr.get_PinHoverRadius();
}
set PinHoverRadius(v) {
this.ptr.set_PinHoverRadius(v);
}
get PinOffset() {
return this.ptr.get_PinOffset();
}
set PinOffset(v) {
this.ptr.set_PinOffset(v);
}
get MiniMapPadding() {
return ImVec2.From(this.ptr.get_MiniMapPadding());
}
set MiniMapPadding(v) {
this.ptr.set_MiniMapPadding(v);
}
get MiniMapOffset() {
return ImVec2.From(this.ptr.get_MiniMapOffset());
}
set MiniMapOffset(v) {
this.ptr.set_MiniMapOffset(v);
}
get Flags() {
return this.ptr.get_Flags();
}
set Flags(v) {
this.ptr.set_Flags(v);
}
get Colors() {
return this.ptr.get_Colors();
}
set Colors(v) {
this.ptr.set_Colors(v);
}
}
export class ImNodes {
static CreateContext() {
return ImNodesContext.From(Mod.export.ImNodes_CreateContext());
}
static DestroyContext(ctx = null) {
Mod.export.ImNodes_DestroyContext(ctx?.ptr ?? null);
}
static GetCurrentContext() {
return ImNodesContext.From(Mod.export.ImNodes_GetCurrentContext());
}
static SetCurrentContext(ctx) {
Mod.export.ImNodes_SetCurrentContext(ctx);
}
static EditorContextCreate() {
return ImNodesEditorContext.From(Mod.export.ImNodes_EditorContextCreate());
}
static EditorContextFree(ctx) {
Mod.export.ImNodes_EditorContextFree(ctx);
}
static EditorContextSet(ctx) {
Mod.export.ImNodes_EditorContextSet(ctx);
}
static EditorContextGetPanning() {
return ImVec2.From(Mod.export.ImNodes_EditorContextGetPanning());
}
static EditorContextResetPanning(pos) {
Mod.export.ImNodes_EditorContextResetPanning(pos);
}
static EditorContextMoveToNode(node_id) {
Mod.export.ImNodes_EditorContextMoveToNode(node_id);
}
static GetIO() {
return ImNodesIO.From(Mod.export.ImNodes_GetIO());
}
/**
* Returns the global style struct. See the struct declaration for default values.
*/
static GetStyle() {
return ImNodesStyle.From(Mod.export.ImNodes_GetStyle());
}
/**
* Style presets matching the dear imgui styles of the same name. If dest is NULL, the active
* context's ImNodesStyle instance will be used as the destination.
*/
static StyleColorsDark(dest = null) {
Mod.export.ImNodes_StyleColorsDark(dest?.ptr ?? null);
}
static StyleColorsClassic(dest = null) {
Mod.export.ImNodes_StyleColorsClassic(dest?.ptr ?? null);
}
static StyleColorsLight(dest = null) {
Mod.export.ImNodes_StyleColorsLight(dest?.ptr ?? null);
}
/**
* The top-level function call. Call this before calling BeginNode/EndNode. Calling this function
* will result the node editor grid workspace being rendered.
*/
static BeginNodeEditor() {
Mod.export.ImNodes_BeginNodeEditor();
}
static EndNodeEditor() {
Mod.export.ImNodes_EndNodeEditor();
}
/**
* Add a navigable minimap to the editor; call before EndNodeEditor after all
* nodes and links have been specified
*/
static MiniMap(minimap_size_fraction = 0.2, location = 2) {
Mod.export.ImNodes_MiniMap(minimap_size_fraction, location);
}
/**
* Use PushColorStyle and PopColorStyle to modify ImNodesStyle::Colors mid-frame.
*/
static PushColorStyle(item, color) {
Mod.export.ImNodes_PushColorStyle(item, color);
}
static PopColorStyle() {
Mod.export.ImNodes_PopColorStyle();
}
static PushStyleVar(style_item, value) {
Mod.export.ImNodes_PushStyleVar(style_item, value);
}
static PushStyleVarImVec2(style_item, value) {
Mod.export.ImNodes_PushStyleVarImVec2(style_item, value);
}
static PopStyleVar(count = 1) {
Mod.export.ImNodes_PopStyleVar(count);
}
/**
* id can be any positive or negative integer, but INT_MIN is currently reserved for internal use.
*/
static BeginNode(id) {
Mod.export.ImNodes_BeginNode(id);
}
static EndNode() {
Mod.export.ImNodes_EndNode();
}
static GetNodeDimensions(id) {
return ImVec2.From(Mod.export.ImNodes_GetNodeDimensions(id));
}
/**
* Place your node title bar content (such as the node title, using ImGui::Text) between the
* following function calls. These functions have to be called before adding any attributes, or the
* layout of the node will be incorrect.
*/
static BeginNodeTitleBar() {
Mod.export.ImNodes_BeginNodeTitleBar();
}
static EndNodeTitleBar() {
Mod.export.ImNodes_EndNodeTitleBar();
}
// Attributes are ImGui UI elements embedded within the node. Attributes can have pin shapes
// rendered next to them. Links are created between pins.
//
// 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.
//
// Each attribute id must be unique.
/**
* Create an input attribute block. The pin is rendered on left side.
*/
static BeginInputAttribute(id, shape = 1) {
Mod.export.ImNodes_BeginInputAttribute(id, shape);
}
static EndInputAttribute() {
Mod.export.ImNodes_EndInputAttribute();
}
/**
* Create an output attribute block. The pin is rendered on the right side.
*/
static BeginOutputAttribute(id, shape = 1) {
Mod.export.ImNodes_BeginOutputAttribute(id, shape);
}
static EndOutputAttribute() {
Mod.export.ImNodes_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.
*/
static BeginStaticAttribute(id) {
Mod.export.ImNodes_BeginStaticAttribute(id);
}
static EndStaticAttribute() {
Mod.export.ImNodes_EndStaticAttribute();
}
/**
* Push a single AttributeFlags value. By default, only AttributeFlags_None is set.
*/
static PushAttributeFlag(flag) {
Mod.export.ImNodes_PushAttributeFlag(flag);
}
static PopAttributeFlag() {
Mod.export.ImNodes_PopAttributeFlag();
}
/**
* Render a link between attributes.
* The attributes ids used here must match the ids used in Begin(Input|Output)Attribute function
* calls. The order of start_attr and end_attr doesn't make a difference for rendering the link.
*/
static Link(id, start_attribute_id, end_attribute_id) {
Mod.export.ImNodes_Link(id, start_attribute_id, end_attribute_id);
}
/**
* Enable or disable the ability to click and drag a specific node.
*/
static SetNodeDraggable(node_id, draggable) {
Mod.export.ImNodes_SetNodeDraggable(node_id, draggable);
}
// The node's position can be expressed in three coordinate systems:
// * screen space coordinates, -- the origin is the upper left corner of the window.
// * editor space coordinates -- the origin is the upper left corner of the node editor window
// * grid space coordinates, -- the origin is the upper left corner of the node editor window,
// translated by the current editor panning vector (see EditorContextGetPanning() and
// EditorContextResetPanning())
// Use the following functions to get and set the node's coordinates in these coordinate systems.
static SetNodeScreenSpacePos(node_id, screen_space_pos) {
Mod.export.ImNodes_SetNodeScreenSpacePos(node_id, screen_space_pos);
}
static SetNodeEditorSpacePos(node_id, editor_space_pos) {
Mod.export.ImNodes_SetNodeEditorSpacePos(node_id, editor_space_pos);
}
static SetNodeGridSpacePos(node_id, grid_space_pos) {
Mod.export.ImNodes_SetNodeGridSpacePos(node_id, grid_space_pos);
}
static GetNodeScreenSpacePos(node_id) {
return ImVec2.From(Mod.export.ImNodes_GetNodeScreenSpacePos(node_id));
}
static GetNodeEditorSpacePos(node_id) {
return ImVec2.From(Mod.export.ImNodes_GetNodeEditorSpacePos(node_id));
}
static GetNodeGridSpacePos(node_id) {
return ImVec2.From(Mod.export.ImNodes_GetNodeGridSpacePos(node_id));
}
/**
* If ImNodesStyleFlags_GridSnapping is enabled, snap the specified node's origin to the grid.
*/
static SnapNodeToGrid(node_id) {
Mod.export.ImNodes_SnapNodeToGrid(node_id);
}
/**
* Returns true if the current node editor canvas is being hovered over by the mouse, and is not
* blocked by any other windows.
*/
static IsEditorHovered() {
return Mod.export.ImNodes_IsEditorHovered();
}
// The following functions return true if a UI element is being hovered over by the mouse cursor.
// Assigns the id of the UI element being hovered over to the function argument. Use these functions
// after EndNodeEditor() has been called.
static IsNodeHovered(node_id) {
return Mod.export.ImNodes_IsNodeHovered(node_id);
}
static IsLinkHovered(link_id) {
return Mod.export.ImNodes_IsLinkHovered(link_id);
}
static IsPinHovered(attribute_id) {
return Mod.export.ImNodes_IsPinHovered(attribute_id);
}
// Use The following two functions to query the number of selected nodes or links in the current
// editor. Use after calling EndNodeEditor().
static NumSelectedNodes() {
return Mod.export.ImNodes_NumSelectedNodes();
}
static NumSelectedLinks() {
return Mod.export.ImNodes_NumSelectedLinks();
}
// Get the selected node/link ids. The pointer argument should point to an integer array with at
// least as many elements as the respective NumSelectedNodes/NumSelectedLinks function call
// returned.
static GetSelectedNodes(node_ids) {
Mod.export.ImNodes_GetSelectedNodes(node_ids);
}
static GetSelectedLinks(link_ids) {
Mod.export.ImNodes_GetSelectedLinks(link_ids);
}
// Clears the list of selected nodes/links. Useful if you want to delete a selected node or link.
static ClearNodeSelection() {
Mod.export.ImNodes_ClearNodeSelection();
}
static ClearLinkSelection() {
Mod.export.ImNodes_ClearLinkSelection();
}
// Use the following functions to add or remove individual nodes or links from the current editors
// selection. Note that all functions require the id to be an existing valid id for this editor.
// Select-functions has the precondition that the object is currently considered unselected.
// Clear-functions has the precondition that the object is currently considered selected.
// Preconditions listed above can be checked via IsNodeSelected/IsLinkSelected if not already
// known.
static SelectNode(node_id) {
Mod.export.ImNodes_SelectNode(node_id);
}
static ClearNodeSelectionID(node_id) {
Mod.export.ImNodes_ClearNodeSelectionID(node_id);
}
static IsNodeSelected(node_id) {
return Mod.export.ImNodes_IsNodeSelected(node_id);
}
static SelectLink(link_id) {
Mod.export.ImNodes_SelectLink(link_id);
}
static ClearLinkSelectionID(link_id) {
Mod.export.ImNodes_ClearLinkSelectionID(link_id);
}
static IsLinkSelected(link_id) {
return Mod.export.ImNodes_IsLinkSelected(link_id);
}
/**
* 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.
*/
static IsAttributeActive() {
return Mod.export.ImNodes_IsAttributeActive();
}
/**
* Was any attribute active? If so, sets the active attribute id to the output function argument.
*/
static IsAnyAttributeActive(attribute_id = null) {
return Mod.export.ImNodes_IsAnyAttributeActive(attribute_id);
}
// Use the following functions to query a change of state for an existing link, or new link. Call
// these after EndNodeEditor().
/**
* Did the user start dragging a new link from a pin?
*/
static IsLinkStarted(started_at_attribute_id) {
return Mod.export.ImNodes_IsLinkStarted(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.
*/
static IsLinkDropped(started_at_attribute_id = null, including_detached_links = true) {
return Mod.export.ImNodes_IsLinkDropped(started_at_attribute_id, including_detached_links);
}
/**
* Did the user finish creating a new link?
*/
static IsLinkCreated(started_at_attribute_id = null, ended_at_attribute_id = null, created_from_snap = null) {
return Mod.export.ImNodes_IsLinkCreated(started_at_attribute_id, ended_at_attribute_id, created_from_snap);
}
static IsLinkCreatedEx(started_at_node_id = null, started_at_attribute_id = null, ended_at_node_id = null, ended_at_attribute_id = null, created_from_snap = null) {
return Mod.export.ImNodes_IsLinkCreatedEx(started_at_node_id, started_at_attribute_id, ended_at_node_id, ended_at_attribute_id, created_from_snap);
}
/**
* Was an existing link detached from a pin by the user? The detached link's id is assigned to the
* output argument link_id.
*/
static IsLinkDestroyed(link_id) {
return Mod.export.ImNodes_IsLinkDestroyed(link_id);
}
// Use the following functions to write the editor context's state to a string, or directly to a
// file. The editor context is serialized in the INI file format.
static SaveCurrentEditorStateToIniString() {
return Mod.export.ImNodes_SaveCurrentEditorStateToIniString();
}
static SaveEditorStateToIniString(editor) {
return Mod.export.ImNodes_SaveEditorStateToIniString(editor?.ptr ?? null);
}
static LoadCurrentEditorStateFromIniString(data) {
Mod.export.ImNodes_LoadCurrentEditorStateFromIniString(data);
}
static LoadEditorStateFromIniString(editor, data) {
Mod.export.ImNodes_LoadEditorStateFromIniString(editor?.ptr ?? null, data);
}
}