thedmd / imgui-node-editor

Node Editor built using Dear ImGui
MIT License
3.48k stars 527 forks source link

Manually set zoom/position of viewport? #296

Open bgribble opened 3 weeks ago

bgribble commented 3 weeks ago

In my application, I have custom keyboard and pointer bindings for many navigation operations. I would like to bind the + and - keys to incrementally zoom in and out the node editor, for example, and bind shift-mouse1-motion to drag the viewport. I would like to be able to set the viewport origin and zoom under control of my code rather than exclusively by pointy-clicky interaction with the node editor.

Zoom

I am aware of he GetCurrentZoom() function to read the zoom, but I can't find a corresponding SetCurrentZoom(zoom_val) or other way to change the zoom.

The implementation of GetCurrentZoom implies that I might be able to just change GetView().InvScale:

float ax::NodeEditor::GetCurrentZoom()
{
    return s_Editor->GetView().InvScale;
}

but I am using a Python binding of imgui-node-editor so I can't try that out. Is there an official API somewhere that I am missing?

Viewport position

I see the NavigateToContent() and NavigateToSelection() helpers, which look to move the viewport in specific ways, but I don't see any API to just say "place the viewport at upper_left, lower_right" or even to get the (upper_left, lower_right) of the current viewport. Internally, there's the NavigateTo action, but again I am working with a Python binding so I'm restricted to the public API.