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

Block shortcuts when a modal popup is open #7643

Open
rodrigorc opened this issue Jun 1, 2024 · 1 comment
Open

Block shortcuts when a modal popup is open #7643

rodrigorc opened this issue Jun 1, 2024 · 1 comment

Comments

@rodrigorc
Copy link
Contributor

Version/Branch of Dear ImGui:

Version 1.90.7

Back-ends:

n/a

Compiler, OS:

all

Full config/build information:

No response

Details:

I need to disable shortcuts when a modal popup is active.

These new shortcuts are great, and I have a full window ImGui application where I would like to use them. Think of main menu actions such as "Open new tab" or "Save all" in a text editor.

Since I have a few non-modal windows popping around I'm flagging the shortcuts with ImGuiInputFlags_RouteGlobal so that the main window gets the notification even when it does not have the focus.

The only issue is that they are activated even when a modal pop-up window is shown, such a confirmation question:

  • User presses Ctrl+Q.
  • The main window receives the "quit" shortcut, correctly.
  • Modal question "Are you sure you want to quit without saving?".
  • User presses any other shortcut. It is activated, but it should not because there is a modal popup blocking the UI.

Currently I'm using IsPopupOpen(NULL, ImGuiPopupFlags_AnyPopup) to disable the shortcuts, which is not ideal because it disables them too for non-modal pop-ups, which it should not (it interacts badly with ImGuiInputFlags_Tooltip).

I think it should be nice to have a flag ImGuiInputFlags_RouteUnlessModal for that.
Naturally, having a ImGuiPopupFlags_AnyModal for the IsPopupOpen() would be useful, too.

Or am I missing an obvious way to do what I want with the current version?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@ocornut
Copy link
Owner

ocornut commented Jun 3, 2024

I will try to work on this soon.

Currently I'm using IsPopupOpen(NULL, ImGuiPopupFlags_AnyPopup) to disable the shortcuts, which is not ideal because it disables them too for non-modal pop-ups,

In the meanwhile you can use FindBlockingModal(NULL) != NULL as better workaround.

Aside from technical issues suggested in #7646 i believe this may need some careful design:

  • I don't necessarily think that blocking shortcuts below a modal is always specific to a modal: could be desirable for popup?
  • Heck I am not even 100% sure it is always desirable that a modal blocks shortcuts, even if I agree it's likely desirable most of the times.
  • I don't know yet if the right design would be to alter routing options at the polling site (as you suggested), or if we also need flags for popup themselves to select how we block things, or we need a combination of both.
  • Note that modals may be stacked. Some users use long-lived modals (e.g. full featured editors/tools) where of course Shortcuts() declared in that modal need to work within the modal, but probably not if a nested modal appears.
  • Handing this is therefore going to alter the perception of ImGuiInputFlags_RouteGlobal, just as the default ImGuiInputFlags_RouteFocused, the calling location matters.

Intuitively I would imagine that we would swap your proposal of ImGuiInputFlags_RouteUnlessModal to ImGuiInputFlags_RouteOverModals.

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