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

Constraint of only min or max window size #1139

Closed
degracode opened this issue May 11, 2017 · 4 comments
Closed

Constraint of only min or max window size #1139

degracode opened this issue May 11, 2017 · 4 comments

Comments

@degracode
Copy link

I've got a tweak to ApplySizeFullWithConstraint that allows you to constrain only the minimum, or only the maximum size of a window. This is useful where I want to use ImGuiWindowFlags_AlwaysAutoResize, but with a minimum so that the title bar text is visible, and the window is at least a reasonable size. Eg:

SetNextWindowSizeConstraints(ImVec2(100.0f, -1.0f), ImVec2(-1.0f, -1.0f));

        // Using -1,-1 on either X/Y axis to preserve the current size.
        ImRect cr = g.SetNextWindowSizeConstraintRect;
        new_size.x = (cr.Min.x >= 0) ? ImMax(new_size.x, cr.Min.x) : window->SizeFull.x;
        new_size.x = (cr.Max.x >= 0) ? ImMin(new_size.x, cr.Max.x) : new_size.x;
        new_size.y = (cr.Min.y >= 0) ? ImMax(new_size.y, cr.Min.y) : window->SizeFull.y;
        new_size.y = (cr.Max.y >= 0) ? ImMax(new_size.y, cr.Max.y) : new_size.y;
        if (g.SetNextWindowSizeConstraintCallback)

Is there a better way I could do this?

@ocornut
Copy link
Owner

ocornut commented May 11, 2017

Hello,
You could achieve it through the callback (meh!), I think your patch would make sense to apply tho. Will look into it. Thanks!
Omar

@notSam25
Copy link

Has anyone found a solution for setting the max window size? I saw that ImGui has a min var(ImGuiStyleVar_WindowMinSize) but I didn't see a max, please enlighten me.

@notSam25
Copy link

Has anyone found a solution for setting the max window size? I saw that ImGui has a min var(ImGuiStyleVar_WindowMinSize) but I didn't see a max, please enlighten me.

Nevermind, I found a function after a bit of documentation spelunking. My solution was using SetNextWindowSizeConstraints.

@ocornut
Copy link
Owner

ocornut commented Nov 13, 2023

I have now answered for #3186, but essentially the correct way to do what you requested is:

SetNextWindowSizeConstraints(ImVec2(100.0f, 0.0f), ImVec2(FLT_MAX, FLT_MAX));

@ocornut ocornut closed this as completed Nov 13, 2023
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

3 participants