imgui-node-editor
imgui-node-editor copied to clipboard
Can't control grid snap behavior
It looks like ed::DragAction::Process does some kind of fancy logic around trying to snap nodes to their pins; this is a neat idea, but if you have some nodes with different pin start positions, you get weird alignment that can't be corrected.
Personally I'd rather the lines move a bit than the nodes be at weird start heights.
Perhaps an editor setting to use simple snapping at a 0,0 pivot?
you get weird alignment that can't be corrected.
I noticed that too.
A bit of brief first, what I think is the issue behind the scenes, just before I look into the code:
New node position isn't aligned or is aligned before layouting is done (positions of pins can shift after first frame, which is not visible on rendered image because stack layouts were made to always output correct visuals). My guess is the former happens which lead to odd alignments.
Addressing behavior above may help with mittigation of oddly placed nodes.
simple snapping at a 0,0 pivot? In theory this how it is supposed to work. : )
Second part of the issue is the ability to control grid alignment. #213 requested ability to turn it off, which I think it is reasonable. Also no one set of rules may be desirable for all kinds of nodes. I think I should add ability to control that.
New setting will allow to control aligning and I will expose control over that to the API.
Do you have any other particular aligning rules in mind? Like top/left corners of nodes should fit the gird.
One other thing that I've been struggling with is that when you create a new node, it isn't snapped to the grid. Since I can't predict what a "snapped" position is, you have to wiggle the node once to get it snapped back to the grid.
It'd be nice there was a way to query a snapped position for a given spot. I suppose this is complicated by not having layout info for the node, but it's enough of a QOL issue that there should probably be some kind of solution. This is also why I think simplifying the alignment rules would be helpful.
If you are adding any configurability to snapping, I would propose the ability to swap the behavior for dragging nodes with and without ALT.
In my application, "smooth" un-snapped dragging is by far preferable, not least because it makes the app feel responsive (snapped dragging feels like the app is not keeping up). But sometimes it would be nice to have nodes snap to a grid, so ALT-drag would be a good shortcut.
Also, the grid size should be configurable and potentially zoom-sensitive. When zoomed way in, as one might do for fine editing, the quantum of motion is too large. OTOH, practically speaking, when you are zoomed in is when you are most likely to want a snap-to-grid effect -- because you are zoomed in, you often can't see enough context to be able to eyeball-align nodes, and it's helpful to have them want to snap into alignment.