MCPcopy Create free account
hub / github.com/cinder/Cinder / ShowExampleAppConstrainedResize

Function ShowExampleAppConstrainedResize

src/imgui/imgui_demo.cpp:9595–9686  ·  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

9593// Demonstrate creating a window with custom resize constraints.
9594// Note that size constraints currently don't work on a docked window (when in 'docking' branch)
9595static void ShowExampleAppConstrainedResize(bool* p_open)
9596{
9597 struct CustomConstraints
9598 {
9599 // Helper functions to demonstrate programmatic constraints
9600 // FIXME: This doesn't take account of decoration size (e.g. title bar), library should make this easier.
9601 // FIXME: None of the three demos works consistently when resizing from borders.
9602 static void AspectRatio(ImGuiSizeCallbackData* data)
9603 {
9604 float aspect_ratio = *(float*)data->UserData;
9605 data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio);
9606 }
9607 static void Square(ImGuiSizeCallbackData* data)
9608 {
9609 data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->DesiredSize.x, data->DesiredSize.y);
9610 }
9611 static void Step(ImGuiSizeCallbackData* data)
9612 {
9613 float step = *(float*)data->UserData;
9614 data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step);
9615 }
9616 };
9617
9618 const char* test_desc[] =
9619 {
9620 "Between 100x100 and 500x500",
9621 "At least 100x100",
9622 "Resize vertical + lock current width",
9623 "Resize horizontal + lock current height",
9624 "Width Between 400 and 500",
9625 "Height at least 400",
9626 "Custom: Aspect Ratio 16:9",
9627 "Custom: Always Square",
9628 "Custom: Fixed Steps (100)",
9629 };
9630
9631 // Options
9632 static bool auto_resize = false;
9633 static bool window_padding = true;
9634 static int type = 6; // Aspect Ratio
9635 static int display_lines = 10;
9636
9637 // Submit constraint
9638 float aspect_ratio = 16.0f / 9.0f;
9639 float fixed_step = 100.0f;
9640 if (type == 0) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(500, 500)); // Between 100x100 and 500x500
9641 if (type == 1) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100
9642 if (type == 2) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Resize vertical + lock current width
9643 if (type == 3) ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Resize horizontal + lock current height
9644 if (type == 4) ImGui::SetNextWindowSizeConstraints(ImVec2(400, -1), ImVec2(500, -1)); // Width Between and 400 and 500
9645 if (type == 5) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 400), ImVec2(-1, FLT_MAX)); // Height at least 400
9646 if (type == 6) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::AspectRatio, (void*)&aspect_ratio); // Aspect ratio
9647 if (type == 7) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square
9648 if (type == 8) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)&fixed_step); // Fixed Step
9649
9650 // Submit window
9651 if (!window_padding)
9652 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));

Callers 1

ShowDemoWindowMethod · 0.85

Calls 3

ImVec2Function · 0.85
ImVec4Class · 0.85
ComboFunction · 0.85

Tested by

no test coverage detected