imgui: Suggestion about blocking IO events

Suggestion:

Is it possible to add a features like pseudo code below.

//before scope, io event is ok
ImGui.IOBlockBegin();
//in scope, io event will be blocked
ImGui.IOBlockEnd();
//after scope, io event is ok

why ?
In some cases, i need to limit the scope of event response。

if(limit) ImGui.IOBlockBegin();

if(ImGui.Begin("win1"))//io event will be block in win1
{
    if(ImGui.IsKeyPress(Key.A)) doSomething1;
}
ImGui.End();

if(limit) ImGui.IOBlockEnd();
if(ImGui.Begin("win2")) //io event will be catched only in win2
{
        if(ImGui.IsKeyPress(Key.A)) doSomething2;
}
ImGui.End();
if(limit) ImGui.IOBlockBegin();

if(limit) ImGui.IOBlockEnd();

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

Some problems with using a scoped lock like you suggested:

  • some interactions are not polled within the Begin/End scope of the window. for example, keyboard navigation requests are currently queued in NavUpdate(). moving the code may be good but is not trivial at all.
  • I expect that down the line you will likely want to access certain keys/buttons and end up needing more granularity.
  • What about mouse hovering? it is part of IO. sometimes you want to prevent it, sometimes not (but modal windows handle this). You can decide you make your overlay a modal to handle this part.

I am attaching my WIP patch for reference if you want to experiment with it. imgui-ed69690-WIP scoped lock access to inputs.patch

If you make your overlay a modal taking focus everything will work as you wanted without needing a change.

Some pointers:

  • We generally use modal window BeginPopupModal() to block mouse interactions behind a window.
  • Why do you need that window to not take focus?
  • If i understand correctly your window isn’t really interactive, it’s mostly a visual overlay?

The whole question revolve around how the other windows are polling inputs. The general aim is that the input routing system or manual gating (e.g. testing if (IsWindowFocused())) should handle this, but in the typical setup it would require the black window to be focused, that’s why I am wondering why it is a problem for you to focus it.

I worked on a feature which was almost exactly what you asked in the first post, but the user in the end realized it didn’t solve their problem correctly (but I don’t know why, I’ll ask them). I could resurrect this feature as it is very little code.

I asked two questions for which both answers are likely opposite, and you are answering “YES”. Please clarify which question you are answering.

Image

  • red area is “top window” real area
    • any windows behind it should not process event
    • include main menu
    • include any widgets (they will respond when mouse hovering)
  • 50% alpha black is background for video play (not importent )
  • pure black is video (like full screen mode)

In some cases, i need to limit the scope of event response。

Your pseudo code can be implemented by storing/passing your own bool to your functions.

But as mentioned I believe you should look at other ways to handle this:

  • manually gate inputs in some window by tests such as if (ImGui::IsWindowFocused(...))
  • using Shortcut() and routing system, the default “focused route” being in essence similar to using IsWindowFocused() (but it handle many more details).

It’d be better if you expressed your problem without focusing on an expected possible solution.

In some cases, i need to limit the scope of event response。

This feels like an XY problem. Why do you need to do that?

I suspect you can accomplish your goals using the shortcuts API with the appropriate route flag or the experimental key ownership API.