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

Custom callback constraints in Constrained Resize example do not work #6210

Open
drunderscore opened this issue Mar 1, 2023 · 4 comments
Open

Comments

@drunderscore
Copy link

Version: e25e452
Branch: docking

Back-end/Renderer/Compiler/OS
GLFW + GLAD on Linux compiled with GCC 12

Expectation
The Constrained Resize example with the Custom: Aspect Ratio 16:9 should resize and be constrained to 16:9

Observed
Attempting to resize does not resize at all. None of the custom restrains allow resizing at all.

On the docking branch, with viewports disabled. Docking itself being enabled/disabled makes no difference.
Tested breifly on master at bfce775, also seems to occur.

@drunderscore
Copy link
Author

See attached video

2023-03-01.15-08-31.mp4

@cfillion
Copy link
Contributor

cfillion commented Mar 2, 2023

Noticed that too, it broke in 2569c64 and it can be restored with this patch (s/CurrentSize/DesiredSize/):

diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 19c4051f4..60608fcb1 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -7389,9 +7389,9 @@ static void ShowExampleAppConstrainedResize(bool* p_open)
     {
         // Helper functions to demonstrate programmatic constraints
         // FIXME: This doesn't take account of decoration size (e.g. title bar), library should make this easier.
-        static void AspectRatio(ImGuiSizeCallbackData* data)    { float aspect_ratio = *(float*)data->UserData; data->DesiredSize.x = IM_MAX(data->CurrentSize.x, data->CurrentSize.y); data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio); }
-        static void Square(ImGuiSizeCallbackData* data)         { data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->CurrentSize.x, data->CurrentSize.y); }
-        static void Step(ImGuiSizeCallbackData* data)           { float step = *(float*)data->UserData; data->DesiredSize = ImVec2((int)(data->CurrentSize.x / step + 0.5f) * step, (int)(data->CurrentSize.y / step + 0.5f) * step); }
+        static void AspectRatio(ImGuiSizeCallbackData* data)    { float aspect_ratio = *(float*)data->UserData; data->DesiredSize.x = IM_MAX(data->DesiredSize.x, data->DesiredSize.y); data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio); }
+        static void Square(ImGuiSizeCallbackData* data)         { data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->DesiredSize.x, data->DesiredSize.y); }
+        static void Step(ImGuiSizeCallbackData* data)           { float step = *(float*)data->UserData; data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); }
     };
 
     const char* test_desc[] =

However even the old behavior doesn't seem fully right as the 16:9 example can't resize with an horizontal edge and the square example can't be resized down with neither horizontal nor vertical edges. I haven't looked into it further.

Take

@drunderscore
Copy link
Author

@cfillion Thanks for that snippet above, worked alright on 16:9, but for an aspect ratio of 9:16 (vertically recorded video), it did some odd things without even resizing (looks like one of the dimensions rose quickly and then overflowed).

This part alone is what worked for me on 16:9 and 9:16, not sure why or how, but sometimes math works best when you least understand it 🎉
data->DesiredSize.y = data->DesiredSize.x / *reinterpret_cast<float*>(data->UserData);

Still shares a similar issue to yours above though -- can't resize from the top and bottom edges.

@ocornut
Copy link
Owner

ocornut commented Nov 13, 2023

Apologies for my late answer on this.

There are two sides to this:

  • I am utterly confused as to what happened with 2569c64, which indeed broke those demos in a commit explicitly mentioning working on them AND adding an extra demo. I verified that even with the full codebase of 2569c64 neither did work. I probably made a last minute change of changing DesiredSize to CurrentSize, maybe I wanted to try something, or tried to tweak how the calling logic worked, but clearly a mistake was made and demo broke at that point. I've pushed the fix now. Also applied the tweak to aspect ratio.

  • Resizing from borders didn't use to be so widespread in earlier years (initially was off by default, relied on backend supporting cursor change etc.). It's not the case anymore but I assume that's one reason why the demo was deemed good enough, but it needs more fixing. The logic calling CalcResizePosSizeFromAnyCorner() for border resizing would need to be altered too.

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