Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually set zoom/position of viewport? #296

Open
bgribble opened this issue Jun 8, 2024 · 1 comment
Open

Manually set zoom/position of viewport? #296

bgribble opened this issue Jun 8, 2024 · 1 comment

Comments

@bgribble
Copy link

bgribble commented Jun 8, 2024

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.

@bgribble bgribble changed the title Manually set zoom? Manually set zoom/position of viewport? Jun 9, 2024
@bgribble
Copy link
Author

bgribble commented Oct 1, 2024

Bumping this with a pseudo-workaround.

  • Clear the selection with ClearSelection
  • Create an invisible (empty, no padding or border) node in at the upper-left of where you want the viewport to be
  • Create another invisible node at the lower-right
  • Select them with SelectNode
  • NavigateToSelection()

I am still working on restoring the original selection after this navigation, but the basic concept works for adjusting the viewport position and zoom from code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant