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

Preserve DragFloat from changing value when overlap #4702

Open
JaroslavHolecek opened this issue Nov 8, 2021 · 7 comments
Open

Preserve DragFloat from changing value when overlap #4702

JaroslavHolecek opened this issue Nov 8, 2021 · 7 comments

Comments

@JaroslavHolecek
Copy link

Version: 1.85
Branch: master

Is it possible somehow preserve (deactivate) DragFloat from changing its value (by dragging) in situation where DragFloat is overlapped by other widget (in my case Group ) and I drag this widget (Group)?

I simply want to move with Group in front (I make "node_editor" and Group is movable node ) and not change value of DragFloat in back.
Thank you.

I try to set AllowOverlap by #3909 (comment)
But this seem to work for two overalapped DragFloat -> I want to use it in case when DragFloat is overlapped by Group...

@ocornut
Copy link
Owner

ocornut commented Nov 8, 2021

Hello,

Your question is worded as too specifically (and maybe a XY Problem, this does not have much to do with DragFloat().

We can attempt to make AllowOverlap work with groups if it doesn't already, but please provide a minimum repro to first see if that is the case.

Otherwise you should use individual windows as a delimiter for hovering.

@JaroslavHolecek
Copy link
Author

Thanks for fast response - Sorry for XY
Yes, generally should be enough to extend AllowOverlap to Group (or any Item that react to IsItemClicked/Hoovered etc.) (in sense that Group or other Item can be the overlapping one )
I will try to show some repo (tomorrow).

My node_editor is quite similar to https://github.com/thedmd/imgui-node-editor -> nodes are not window, but Groups of other elements -> than they can overlap -> when I grab and drag node (Group) I also fire changing value on underlying DragFloat - which I dont want.
And you are right, also I drag two overlapping nodes (Groups) when grab they on overlapping point - which I dont want too...

@JaroslavHolecek
Copy link
Author

I am sorry for being late...

Repro code is:
`
static float value = 0;
static ImVec2 text_position = ImVec2(300, 100);
static bool moving_text = false;

ImGui::SetCursorPos(ImVec2(100, 100));
ImGui::PushItemWidth(50);
ImGui::DragFloat("df", &value);
ImGui::SetItemAllowOverlap();
ImGui::PopItemWidth();

ImGui::SetCursorPos(text_position);
ImGui::Text("This text is Group and drag flat is really DragFloat or Group - in my case. ");
if (ImGui::IsItemClicked(0)) { moving_text = true; }
if (ImGui::IsMouseReleased(0)) { moving_text = false; }

if (moving_text && ImGui::IsMouseDragging(0))
{
text_position.x += ImGui::GetMouseDragDelta(0).x;
ImGui::ResetMouseDragDelta(0);
}
`

If you move text over the DragFloat, release mouse and then drag text by some point that overlap with DragFloat -> you move with text and change value in DragFloat too... I do not want change value in DragFloat in this case.

In my real scenario are two cases:

  1. DragFloat is really DragFloat and text is Group
  2. DragFloat is Group and text is Group

@JaroslavHolecek
Copy link
Author

@ocornut I am just not sure whether repro code ping you.

@ocornut
Copy link
Owner

ocornut commented Dec 7, 2021

Sorry this is too tricky and ambiguous to understand. This is not much a question about drag float.

I think maybe you should use BeginDisabled() or underlying ImGuiItemFlags_Disabled flag on the DragFloat simply.

@JaroslavHolecek
Copy link
Author

OK, maybe more general issue is possibility of disabling interaction of lower item when two items overlap for "all item types" (as button behave).

When I want to use ImGuiItemFlags_Disabled, I have to compute whether or not Text overlap DragFloat (in my example) - which is not easy computation. And somewhere in Imgui this computation already run (for buttons at least)

@ocornut
Copy link
Owner

ocornut commented Dec 7, 2021

And somewhere in Imgui this computation already run (for buttons at least)

No computation is running. Hovering is given on a first-submitted first-served basis by default, and with AllowOverlap it allows override + checks the previous frame value (g.HoveredIdPreviousFrame).
If you use an item that had an identifier (e.g. InvisibleButton()) instead of Text() it'll have a chance to work.

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

No branches or pull requests

2 participants