Demonstrate creating a window with custom resize constraints. Note that size constraints currently don't work on a docked window (when in 'docking' branch)
| 9909 | // Demonstrate creating a window with custom resize constraints. |
| 9910 | // Note that size constraints currently don't work on a docked window (when in 'docking' branch) |
| 9911 | static void ShowExampleAppConstrainedResize(bool* p_open) |
| 9912 | { |
| 9913 | struct CustomConstraints |
| 9914 | { |
| 9915 | // Helper functions to demonstrate programmatic constraints |
| 9916 | // FIXME: This doesn't take account of decoration size (e.g. title bar), library should make this easier. |
| 9917 | // FIXME: None of the three demos works consistently when resizing from borders. |
| 9918 | static void AspectRatio(ImGuiSizeCallbackData* data) |
| 9919 | { |
| 9920 | float aspect_ratio = *(float*)data->UserData; |
| 9921 | data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio); |
| 9922 | } |
| 9923 | static void Square(ImGuiSizeCallbackData* data) |
| 9924 | { |
| 9925 | data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->DesiredSize.x, data->DesiredSize.y); |
| 9926 | } |
| 9927 | static void Step(ImGuiSizeCallbackData* data) |
| 9928 | { |
| 9929 | float step = *(float*)data->UserData; |
| 9930 | data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); |
| 9931 | } |
| 9932 | }; |
| 9933 | |
| 9934 | const char* test_desc[] = |
| 9935 | { |
| 9936 | "Between 100x100 and 500x500", |
| 9937 | "At least 100x100", |
| 9938 | "Resize vertical + lock current width", |
| 9939 | "Resize horizontal + lock current height", |
| 9940 | "Width Between 400 and 500", |
| 9941 | "Height at least 400", |
| 9942 | "Custom: Aspect Ratio 16:9", |
| 9943 | "Custom: Always Square", |
| 9944 | "Custom: Fixed Steps (100)", |
| 9945 | }; |
| 9946 | |
| 9947 | // Options |
| 9948 | static bool auto_resize = false; |
| 9949 | static bool window_padding = true; |
| 9950 | static int type = 6; // Aspect Ratio |
| 9951 | static int display_lines = 10; |
| 9952 | |
| 9953 | // Submit constraint |
| 9954 | float aspect_ratio = 16.0f / 9.0f; |
| 9955 | float fixed_step = 100.0f; |
| 9956 | if (type == 0) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(500, 500)); // Between 100x100 and 500x500 |
| 9957 | if (type == 1) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100 |
| 9958 | if (type == 2) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Resize vertical + lock current width |
| 9959 | if (type == 3) ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Resize horizontal + lock current height |
| 9960 | if (type == 4) ImGui::SetNextWindowSizeConstraints(ImVec2(400, -1), ImVec2(500, -1)); // Width Between and 400 and 500 |
| 9961 | if (type == 5) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 400), ImVec2(-1, FLT_MAX)); // Height at least 400 |
| 9962 | if (type == 6) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::AspectRatio, (void*)&aspect_ratio); // Aspect ratio |
| 9963 | if (type == 7) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square |
| 9964 | if (type == 8) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)&fixed_step); // Fixed Step |
| 9965 | |
| 9966 | // Submit window |
| 9967 | if (!window_padding) |
| 9968 | ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); |
no test coverage detected