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

Add support for zooming #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

smilediver
Copy link
Contributor

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:

  • In BeginNodeEditor() ImGui's internal mouse state is transformed to be in ImNodes grid space.
  • All ImGui calls after that are working in grid space. So basically nodes are rendered into draw list in grid space.
  • In EndNodeEditor() draw lists are transformed to screen space. This is where panning and zooming are applied.

@Auburn
Copy link
Collaborator

Auburn commented Dec 4, 2021

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
Copy link

XLPhere commented Dec 4, 2021

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):

  • text looks squished, even though no zoom was applied (this was me having zoom turned on in browser, i believe)
  • (when docked) area-background clips out of the window/area and moves around with the grid (see picture)
  • outside of the a certain area interacting (clicking/hovering) with node contents is not working though dragging works everywhere (the area which works is the same which has the correct background in the case of docking)
  • ImGui::SetTooltip spawns it's window at an offset position (this is probably due to what @Auburn mentioned)
  • Having a second node-editor has some other issues i have trouble summarizing, you will see when you try it out

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
Copy link
Owner

Nelarius commented Mar 9, 2022

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
Copy link
Owner

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
Copy link

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
Copy link
Collaborator

Auburn commented Feb 4, 2024

Have a look at #192 for my zoom implementation

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

Successfully merging this pull request may close these issues.

None yet

5 participants