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)
Some problems with using a scoped lock like you suggested:
NavUpdate(). moving the code may be good but is not trivial at all.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:
BeginPopupModal()to block mouse interactions behind a window.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.
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:
if (ImGui::IsWindowFocused(...))Shortcut()and routing system, the default “focused route” being in essence similar to usingIsWindowFocused()(but it handle many more details).It’d be better if you expressed your problem without focusing on an expected possible solution.
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.