Nelarius / imnodes

A small, dependency-free node editor for dear imgui
MIT License
1.97k stars 241 forks source link

Add support for zooming #134

Open smilediver opened 2 years ago

smilediver commented 2 years ago

This adds supports for zooming.

The biggest change is that it makes everything between BeginNodeEditor() and EndNodeEditor() to work in grid space coordinates. This simplifies things a lot, since otherwise zooming adds yet another space, and this complicates things a lot. With this, there are basically just two spaces, the grid and the screen.

How it works:

Auburn commented 2 years ago

I had a quick go with this, it's really cool.

It seems to cause an issue with how ImGui checks the mouse position though, even if you never set any zoom.

Functions like ImGui::IsItemHovered & ImGui::BeginPopupContextWindow seem to be using an offset mouse position. From what I can see there are 2 issues with the position, the position is relative to the whole screen not the current window and it is offset by the node editor panning. Without this patch this issue doesn't happen.

I haven't looked into it much, was wondering if you had any ideas?

XLPhere commented 2 years ago

Hi, these are the issues i found while using this patch (without any modifications to my own code - I'm also using the docking-branch of imgui):

You can look at the issues in my App here: https://wasm.hcink.org/imnodes-134/ (web-version, which has the same issues as the desktop version for me - the app is still very WIP, but should be fine for demonstration of the issues above - moving the nodes around and selecting fields should be fine though - note that tooltips are only available on on some nodes) Here is also a screenshot for reference: Screenshot_20211204_124506

Nelarius commented 2 years ago

Hi there, and sorry about the long radio silence. I intend to tag a new release ASAP, then take a look at this pr & merge.

Nelarius commented 2 years ago

All right, took the code for a spin. Agree with Auburns, this is really cool!

I also noticed that some of the ImGui widget seems to be using untransformed grid space coordinates. Observed this with the menu bar getting highlighted, as well as when using ImGu::ColorEdit3. This explains why we see problems, even with a zoom of 1.

The first thing which comes to mind is that would we be able to do the clip rect and vertex transformations from GCS? I know thedmd mentioned this in the original GitHub issue:

This works but some problems arise around it. Working with global coordinate system (GCS) when scaling is involved isn't best experience.

Do we know anything about why working with the GCS is bad?

jamesmurphy-mc commented 10 months ago

Hi all, just wanted to bump and say I like the idea. Could someone tell me what is the current status of this feature and are there any roadblocks?

Auburn commented 5 months ago

Have a look at #192 for my zoom implementation