MCPcopy Create free account
hub / github.com/AlexandreRouma/SDRPlusPlus / ShowExampleAppConstrainedResize

Function ShowExampleAppConstrainedResize

core/src/imgui/imgui_demo.cpp:7032–7078  ·  view source on GitHub ↗

Demonstrate creating a window with custom resize constraints.

Source from the content-addressed store, hash-verified

7030
7031// Demonstrate creating a window with custom resize constraints.
7032static void ShowExampleAppConstrainedResize(bool* p_open)
7033{
7034 struct CustomConstraints
7035 {
7036 // Helper functions to demonstrate programmatic constraints
7037 static void Square(ImGuiSizeCallbackData* data) { data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->DesiredSize.x, data->DesiredSize.y); }
7038 static void Step(ImGuiSizeCallbackData* data) { float step = (float)(int)(intptr_t)data->UserData; data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); }
7039 };
7040
7041 const char* test_desc[] =
7042 {
7043 "Resize vertical only",
7044 "Resize horizontal only",
7045 "Width > 100, Height > 100",
7046 "Width 400-500",
7047 "Height 400-500",
7048 "Custom: Always Square",
7049 "Custom: Fixed Steps (100)",
7050 };
7051
7052 static bool auto_resize = false;
7053 static int type = 0;
7054 static int display_lines = 10;
7055 if (type == 0) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Vertical only
7056 if (type == 1) ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Horizontal only
7057 if (type == 2) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100
7058 if (type == 3) ImGui::SetNextWindowSizeConstraints(ImVec2(400, -1), ImVec2(500, -1)); // Width 400-500
7059 if (type == 4) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 400), ImVec2(-1, 500)); // Height 400-500
7060 if (type == 5) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square
7061 if (type == 6) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)(intptr_t)100); // Fixed Step
7062
7063 ImGuiWindowFlags flags = auto_resize ? ImGuiWindowFlags_AlwaysAutoResize : 0;
7064 if (ImGui::Begin("Example: Constrained Resize", p_open, flags))
7065 {
7066 if (ImGui::Button("200x200")) { ImGui::SetWindowSize(ImVec2(200, 200)); } ImGui::SameLine();
7067 if (ImGui::Button("500x500")) { ImGui::SetWindowSize(ImVec2(500, 500)); } ImGui::SameLine();
7068 if (ImGui::Button("800x200")) { ImGui::SetWindowSize(ImVec2(800, 200)); }
7069 ImGui::SetNextItemWidth(200);
7070 ImGui::Combo("Constraint", &type, test_desc, IM_ARRAYSIZE(test_desc));
7071 ImGui::SetNextItemWidth(200);
7072 ImGui::DragInt("Lines", &display_lines, 0.2f, 1, 100);
7073 ImGui::Checkbox("Auto-resize", &auto_resize);
7074 for (int i = 0; i < display_lines; i++)
7075 ImGui::Text("%*sHello, sailor! Making this line long enough for the example.", i * 4, "");
7076 }
7077 ImGui::End();
7078}
7079
7080//-----------------------------------------------------------------------------
7081// [SECTION] Example App: Simple overlay / ShowExampleAppSimpleOverlay()

Callers 1

ShowDemoWindowMethod · 0.85

Calls 3

ImVec2Function · 0.85
BeginFunction · 0.85
EndFunction · 0.85

Tested by

no test coverage detected