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

Check if window is visible #1365

Closed
haferburg opened this issue Oct 12, 2017 · 3 comments
Closed

Check if window is visible #1365

haferburg opened this issue Oct 12, 2017 · 3 comments

Comments

@haferburg
Copy link

haferburg commented Oct 12, 2017

This is a follow up to #1061.

Here is the code I would like to be able to write, which is currently not possible:

    bool WasDisplayedYet = ImGui::WindowWasActive(Title);
    if (!WasDisplayedYet) {
      ImVec2 TextSize = ImGui::CalcTextSize(FileName);
      ImGui::SetNextWindowSize(ImVec2(TextSize.x + 200.f, 100.f));
    }

    ImGui::Begin(Title, &DisplayDialog);

So I want to compute the size of the window, but only if I need to, i. e. if the window wasn't visible before.

I could compute the preferred size, then pass it in as the third parameter to Begin(), but that only works the first time the window.

The other option would be to call SetNextWindowSize(), which is only possible before calling Begin(). But in order to check whether or not the window was already visible, I can only call IsWindowAppearing() after calling Begin(). So I can't use that either.

The documentation says SetWindowSize() is not recommended, but it's the only way I got this to work without modifying imgui. And it causes the window to jump after the first frame, which is not pretty.

@ocornut
Copy link
Owner

ocornut commented Oct 17, 2017

Why not using the ImGuiWindowFlags_AlwaysAutoResize window flag?

then pass it in as the third parameter to Begin(), but that only works the first time the window.

Avoid using the 5 argument version of Begin. You can use SetNextWindowSize/SetWindowSize instead.

@ocornut
Copy link
Owner

ocornut commented May 2, 2018

@haferburg Any news on that problem you had?
I don't think you can solve this problem in a satisfactory manner. What you are asking if it was possible would also lead to one-frame glitch on a reappearing window if the title changed, since you wouldn't calculate the size during that frame and therefore the window would use the old size for a frame.

If you are still interested in this, could you post more context and intent. What are you trying to solve by not calling SetNextWindowSize() every frame?

@haferburg
Copy link
Author

@ocornut Hi Omar,
what I was trying to do was display a "Save As" dialog that would display a file path, and I wanted to change the size of the dialog depending on the CalcTextSize() of the current path.

To be honest, it was probably not the best idea. A dialog should be able to display information properly without the need to be resized. I'll close this for now. Thank you for checking back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants