MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / ShowExampleAppConstrainedResize

Function ShowExampleAppConstrainedResize

external/imgui/imgui_demo.cpp:9928–10019  ·  view source on GitHub ↗

Demonstrate creating a window with custom resize constraints. Note that size constraints currently don't work on a docked window (when in 'docking' branch)

Source from the content-addressed store, hash-verified

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

Callers 1

ShowDemoWindowMethod · 0.85

Calls 2

ImVec2Function · 0.85
ImVec4Class · 0.85

Tested by

no test coverage detected