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

Open
opened 2023-03-01 19:59:18 +00:00 by drunderscore · 3 comments
drunderscore commented 2023-03-01 19:59:18 +00:00 (Migrated from github.com)

Version: e25e4526cd
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 bfce7750b1, also seems to occur.

Version: e25e4526cd41cd6536194de098540d54244f54e9 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 bfce7750b168b5a857b4379596236dda7b58bd39, also seems to occur.
drunderscore commented 2023-03-01 20:11:20 +00:00 (Migrated from github.com)
See attached video https://user-images.githubusercontent.com/15949431/222254646-45c8fea7-54cb-48dd-a092-a5308dadf711.mp4
cfillion commented 2023-03-02 05:52:02 +00:00 (Migrated from github.com)

Noticed that too, it broke in 2569c64740 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

Noticed that too, it broke in 2569c6474061fe11a1613c3efbcfac3288518bd5 and it can be restored with this patch (s/CurrentSize/DesiredSize/): ```diff 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](https://user-images.githubusercontent.com/4297676/222342635-b368dffa-2faf-4036-98e1-adce2badb046.gif)
drunderscore commented 2023-03-05 17:00:53 +00:00 (Migrated from github.com)

@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.

@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 :tada: `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.
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#6210
No description provided.