Constraint of only min or max window size #1139

Closed
opened 2017-05-11 10:38:41 +00:00 by degracode · 3 comments
degracode commented 2017-05-11 10:38:41 +00:00 (Migrated from github.com)

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?

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 commented 2017-05-11 10:44:31 +00:00 (Migrated from github.com)

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

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 commented 2022-11-17 22:42:55 +00:00 (Migrated from github.com)

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.

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 commented 2022-11-17 22:48:49 +00:00 (Migrated from github.com)

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.

> 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.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#1139
No description provided.