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

Flag to only take mouse inputs on Titlebar? #5304

Closed
Bonkt opened this issue May 11, 2022 · 5 comments
Closed

Flag to only take mouse inputs on Titlebar? #5304

Bonkt opened this issue May 11, 2022 · 5 comments
Labels

Comments

@Bonkt
Copy link

Bonkt commented May 11, 2022

Using sfml I render my main application to a sf::RenderTexture that I then display on ImGui::Image(). So basically my dockspace and my whole window is at all times completely covered by ImGui begin() windows.

So when i try to dispatch mouse clicks to my application window ( my ImGui::Begin() window containing ImGui::Image where i display my rendered sfml texture.) i want to check if io.WantCaptureMouse.
The problem is that i also want to be able to move my "application" window around. So setting the flag ImGuiWindowFlags_NoMouseInputs does not work.

I read at many places that io.WantCaptureMouse is prefered over IsWindowHovered().
Is this still the case for my use case? Or would a new flag with a name like
ImGuiWindowFlags_OnlyMouseInputsOnTitlebar be a useful addition to the API?

Edit:
Basically i want to create something similiar looking to the "Canvas" demo. But instead of rendering the canvas in ImGui i want to render in SFML to a texture and then display that on a ImGui windows.

Also im using the docking branch, if that matters.

Originally posted by @Bonkt in #52 (comment)

@Bonkt Bonkt changed the title Flag to set only set take mouse inputs on Titlebar? Flag to only take mouse inputs on Titlebar? May 11, 2022
@rokups
Copy link
Contributor

rokups commented May 13, 2022

Could you please clarify what do you mean by "my application window"? What kind of window is that?

General rule is this:

  • When io.WantCaptureMouse == true, you pass sfml events to imgui only, you do not process events in your own application.
  • When io.WantCaptureMouse == false, you pass sfml events to imgui and you process events in your own application.

@Bonkt
Copy link
Author

Bonkt commented May 13, 2022

It is a ImGui::Begin() window with a single ImGui::Image() in it.
I render circuitWindowTexture in sfml in real time, then display it using Image().

So i want io.WantCaptureMouse = false when i am hovering the ImGui::Image().
And io.WantCaptureMouse = true on the Titlebar.

Thus a request for the flag ImGuiWindowFlags_OnlyMouseInputsOnTitlebar?

if (ImGui::Begin(windowName.c_str(), &isOpen, window_flags))
    {
        windowSize = ImGui::GetWindowSize();
        windowPos = ImGui::GetWindowPos();
        ImGui::Image(circuitWindowTexture);
     }  
ImGui::End();

I know and understand the "general rule" for how io.WantCaptureMouse works. I'm wondering whether my use case is common/reasonable enough to warrant the creation of a new window flag.
Or if constant warnings in documentations of using IsWindowHovered() should be disregarded for what im building, and i should use that.

@rokups
Copy link
Contributor

rokups commented May 13, 2022

Ah so its only imgui windows. We have no such flag. One way to achieve what you want is to use InvisibleButton() to cover entire body of the window. Then InvisibleButton() will capture clicks, you dont act on them and window is draggable only by a titlebar.

@ocornut
Copy link
Owner

ocornut commented May 13, 2022

Image();
if (IsItemHovered())
    CaptureMouseFromApp(false);

@ocornut ocornut added the inputs label May 13, 2022
@Bonkt
Copy link
Author

Bonkt commented May 20, 2022

Thanks, CaptureMouseFromApp(false) is what fits best,
I missed that function when looking through demo and the header file.

ocornut added a commit that referenced this issue May 23, 2022
…FrameWantCaptureMouse() and SetNextFrameWantCaptureKeyboard(). Added demo. (#5304, #4831, #4480, #533)
@ocornut ocornut closed this as completed Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants