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

Redirecting window mouse wheel inputs to parent #1380

Closed
Twinki14 opened this issue Oct 20, 2017 · 4 comments
Closed

Redirecting window mouse wheel inputs to parent #1380

Twinki14 opened this issue Oct 20, 2017 · 4 comments

Comments

@Twinki14
Copy link

Twinki14 commented Oct 20, 2017

Currently i'm running into a problem of having Wrapped Text in a child region.

I have a child rregion, which consists of Columns, in those Columns I have another child region which has a TextWrapped of a description.

https://i.imgur.com/kvWAu6h.gif

The Window is intended to have enough items that scrolling will be needed, however when I hover over the Wrapped Text areas, it cannot scroll. I was able to solve it by using ImGuiWindowFlags_NoInputs on the child region inside the column, however if the Description now requires scrolling, users can no longer drag scroll, since all input isn't being cached for the child region.

Is there anyway I can block only specific inputs? or a potentially solution to this problem?

ADMIN Attached your GIF file. Please don't use imgur.com as those images will disappear:
kvwau6h

@ocornut
Copy link
Owner

ocornut commented Oct 23, 2017

Hello @Twinki14,

This was discussed in #1245, and while I would personally prefer Windows-style behavior to avoid that sort of issue you are hitting on, other people seemed to like Mac-style behavior.

Note that being used on Mac this means that most applications there who needs embedded scrolling regions tends to leave some space available.

For reference, the patch for Windows-style scrolling may be applied in NewFrame():
https://github.com/ocornut/imgui/blob/master/imgui.cpp#L2398

    // Scale & Scrolling
    if (g.HoveredWindow && g.IO.MouseWheel != 0.0f && !g.HoveredWindow->Collapsed)
    {
        ImGuiWindow* window = g.HoveredWindow;

By changing the 3 occurences of g.HoveredWindow to g.NavWindow here.

A possible solution is when we find the flag ImGuiWindowFlags_NoScrollWithMouse on a window we could search back among its parent until we find one that doesn't have this flag set and scroll that window. I will try that.

PS: Please use github attachment for pictures/gif so that the pictures won't disappear in the future and those threads can be relevant to future readers.

@ocornut
Copy link
Owner

ocornut commented Oct 23, 2017

If you replace:

        else if (!g.IO.KeyCtrl && !(window->Flags & ImGuiWindowFlags_NoScrollWithMouse))
        {
            // Scroll
            const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
            SetWindowScrollY(window, window->Scroll.y - g.IO.MouseWheel * window->CalcFontSize() * scroll_lines);
        }

with:

        else if (!g.IO.KeyCtrl)
        {
            // Scrolling
            // If the window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent
            ImGuiWindow* scroll_window = window;
            while (!(scroll_window->Flags & ImGuiWindowFlags_NoInputs) && (scroll_window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && scroll_window->ParentWindow)
                scroll_window = scroll_window->ParentWindow;

            if (!(scroll_window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(scroll_window->Flags & ImGuiWindowFlags_NoInputs))
            {
                const int scroll_lines = (scroll_window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
                SetWindowScrollY(scroll_window, scroll_window->Scroll.y - g.IO.MouseWheel * scroll_window->CalcFontSize() * scroll_lines);
            }
        }

It would solve your problem when passing ImGuiWindowFlags_NoScrollWithMouse to the child windows. However I'm not sure what would be the other side effects for people already using this flag and perhaps expecting mouse wheel to completely be ignored in that situation.

@ocornut ocornut changed the title Blocking specific inputs to a Child Region / Window? Redirecting window mouse wheel inputs to parent Dec 14, 2017
ocornut added a commit that referenced this issue Dec 14, 2017
…orwards the mouse wheel event to the parent window, unless either ImGuiWindowFlags_NoInputs or ImGuiWindowFlags_NoScrollbar are also set. (#1380, #1502)
@ocornut
Copy link
Owner

ocornut commented Dec 14, 2017

@Twinki14 You can now use the ImGuiWindowFlags_NoScrollWithMouse flag and by default on a child window it will forward the mouse wheel to its parent.

"Using the ImGuiWindowFlags_NoScrollWithMouse flag on a child window forwards the mouse wheel event to the parent window, unless either ImGuiWindowFlags_NoInputs or ImGuiWindowFlags_NoScrollbar are also set."

@ocornut ocornut closed this as completed Dec 14, 2017
ocornut added a commit that referenced this issue Jul 22, 2018
… window if ImGuiWindowFlags_NoScrollWithMouse is set. (#1463, #1380, #1502)
ocornut added a commit that referenced this issue Jul 2, 2019
…tically forwarded to parent window if ScrollMax is zero on the scrolling axis. Also still case if ImGuiWindowFlags_NoScrollWithMouse is set (not new), but previously the forwarding

  would be disabled if ImGuiWindowFlags_NoScrollbar was set on the child window, which is not the case any more (amend #1502, #1380).
@ocornut
Copy link
Owner

ocornut commented Jul 2, 2019

Note that I have amended this behavior today:

  • Mouse wheel scrolling while hovering a child window is automatically forwarded to parent window if ScrollMax is zero on the scrolling axis (so in a same position vertical mouse wheel can apply to a different window than the horizontal mouse wheel).
  • Also still he case if ImGuiWindowFlags_NoScrollWithMouse is set (not new), but previously the forwarding would be disabled if ImGuiWindowFlags_NoScrollbar was set on the child window, which is not the case any more. Forwarding can still be disabled by setting ImGuiWindowFlags_NoInputs.

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