MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / ShowExampleAppConstrainedResize

Function ShowExampleAppConstrainedResize

Source/3rdParty/imgui/imgui_demo.cpp:9813–9904  ·  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

9811// Demonstrate creating a window with custom resize constraints.
9812// Note that size constraints currently don't work on a docked window (when in 'docking' branch)
9813static void ShowExampleAppConstrainedResize(bool* p_open)
9814{
9815 struct CustomConstraints
9816 {
9817 // Helper functions to demonstrate programmatic constraints
9818 // FIXME: This doesn't take account of decoration size (e.g. title bar), library should make this easier.
9819 // FIXME: None of the three demos works consistently when resizing from borders.
9820 static void AspectRatio(ImGuiSizeCallbackData* data)
9821 {
9822 float aspect_ratio = *(float*)data->UserData;
9823 data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio);
9824 }
9825 static void Square(ImGuiSizeCallbackData* data)
9826 {
9827 data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->DesiredSize.x, data->DesiredSize.y);
9828 }
9829 static void Step(ImGuiSizeCallbackData* data)
9830 {
9831 float step = *(float*)data->UserData;
9832 data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step);
9833 }
9834 };
9835
9836 const char* test_desc[] =
9837 {
9838 "Between 100x100 and 500x500",
9839 "At least 100x100",
9840 "Resize vertical + lock current width",
9841 "Resize horizontal + lock current height",
9842 "Width Between 400 and 500",
9843 "Height at least 400",
9844 "Custom: Aspect Ratio 16:9",
9845 "Custom: Always Square",
9846 "Custom: Fixed Steps (100)",
9847 };
9848
9849 // Options
9850 static bool auto_resize = false;
9851 static bool window_padding = true;
9852 static int type = 6; // Aspect Ratio
9853 static int display_lines = 10;
9854
9855 // Submit constraint
9856 float aspect_ratio = 16.0f / 9.0f;
9857 float fixed_step = 100.0f;
9858 if (type == 0) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(500, 500)); // Between 100x100 and 500x500
9859 if (type == 1) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100
9860 if (type == 2) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Resize vertical + lock current width
9861 if (type == 3) ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Resize horizontal + lock current height
9862 if (type == 4) ImGui::SetNextWindowSizeConstraints(ImVec2(400, -1), ImVec2(500, -1)); // Width Between and 400 and 500
9863 if (type == 5) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 400), ImVec2(-1, FLT_MAX)); // Height at least 400
9864 if (type == 6) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::AspectRatio, (void*)&aspect_ratio); // Aspect ratio
9865 if (type == 7) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square
9866 if (type == 8) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)&fixed_step); // Fixed Step
9867
9868 // Submit window
9869 if (!window_padding)
9870 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));

Callers 1

ShowDemoWindowMethod · 0.85

Calls 13

ImVec2Function · 0.85
PopStyleVarFunction · 0.85
ColorButtonFunction · 0.85
ImVec4Class · 0.85
SetWindowSizeFunction · 0.85
ComboFunction · 0.85
DragIntFunction · 0.85
CheckboxFunction · 0.85
EndFunction · 0.85
PushStyleVarFunction · 0.50
BeginFunction · 0.50
TextFunction · 0.50

Tested by

no test coverage detected