MCPcopy Create free account
hub / github.com/clementgallet/libTAS / ShowExampleAppConstrainedResize

Function ShowExampleAppConstrainedResize

src/external/imgui/imgui_demo.cpp:7676–7767  ·  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

7674// Demonstrate creating a window with custom resize constraints.
7675// Note that size constraints currently don't work on a docked window (when in 'docking' branch)
7676static void ShowExampleAppConstrainedResize(bool* p_open)
7677{
7678 struct CustomConstraints
7679 {
7680 // Helper functions to demonstrate programmatic constraints
7681 // FIXME: This doesn't take account of decoration size (e.g. title bar), library should make this easier.
7682 // FIXME: None of the three demos works consistently when resizing from borders.
7683 static void AspectRatio(ImGuiSizeCallbackData* data)
7684 {
7685 float aspect_ratio = *(float*)data->UserData;
7686 data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio);
7687 }
7688 static void Square(ImGuiSizeCallbackData* data)
7689 {
7690 data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->DesiredSize.x, data->DesiredSize.y);
7691 }
7692 static void Step(ImGuiSizeCallbackData* data)
7693 {
7694 float step = *(float*)data->UserData;
7695 data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step);
7696 }
7697 };
7698
7699 const char* test_desc[] =
7700 {
7701 "Between 100x100 and 500x500",
7702 "At least 100x100",
7703 "Resize vertical + lock current width",
7704 "Resize horizontal + lock current height",
7705 "Width Between 400 and 500",
7706 "Height at least 400",
7707 "Custom: Aspect Ratio 16:9",
7708 "Custom: Always Square",
7709 "Custom: Fixed Steps (100)",
7710 };
7711
7712 // Options
7713 static bool auto_resize = false;
7714 static bool window_padding = true;
7715 static int type = 6; // Aspect Ratio
7716 static int display_lines = 10;
7717
7718 // Submit constraint
7719 float aspect_ratio = 16.0f / 9.0f;
7720 float fixed_step = 100.0f;
7721 if (type == 0) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(500, 500)); // Between 100x100 and 500x500
7722 if (type == 1) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100
7723 if (type == 2) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Resize vertical + lock current width
7724 if (type == 3) ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Resize horizontal + lock current height
7725 if (type == 4) ImGui::SetNextWindowSizeConstraints(ImVec2(400, -1), ImVec2(500, -1)); // Width Between and 400 and 500
7726 if (type == 5) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 500), ImVec2(-1, FLT_MAX)); // Height at least 400
7727 if (type == 6) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::AspectRatio, (void*)&aspect_ratio); // Aspect ratio
7728 if (type == 7) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square
7729 if (type == 8) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)&fixed_step); // Fixed Step
7730
7731 // Submit window
7732 if (!window_padding)
7733 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));

Callers 1

ShowDemoWindowMethod · 0.85

Calls 4

ImVec2Function · 0.85
PushStyleVarFunction · 0.85
PopStyleVarFunction · 0.85
ImVec4Class · 0.85

Tested by

no test coverage detected