MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / ShowExampleAppConstrainedResize

Function ShowExampleAppConstrainedResize

lib/imgui/imgui_demo.cpp:4320–4364  ·  view source on GitHub ↗

Demonstrate creating a window with custom resize constraints.

Source from the content-addressed store, hash-verified

4318
4319// Demonstrate creating a window with custom resize constraints.
4320static void ShowExampleAppConstrainedResize(bool* p_open)
4321{
4322 struct CustomConstraints // Helper functions to demonstrate programmatic constraints
4323 {
4324 static void Square(ImGuiSizeCallbackData* data) { data->DesiredSize.x = data->DesiredSize.y = (data->DesiredSize.x > data->DesiredSize.y ? data->DesiredSize.x : data->DesiredSize.y); }
4325 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); }
4326 };
4327
4328 static bool auto_resize = false;
4329 static int type = 0;
4330 static int display_lines = 10;
4331 if (type == 0) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 0), ImVec2(-1, FLT_MAX)); // Vertical only
4332 if (type == 1) ImGui::SetNextWindowSizeConstraints(ImVec2(0, -1), ImVec2(FLT_MAX, -1)); // Horizontal only
4333 if (type == 2) ImGui::SetNextWindowSizeConstraints(ImVec2(100, 100), ImVec2(FLT_MAX, FLT_MAX)); // Width > 100, Height > 100
4334 if (type == 3) ImGui::SetNextWindowSizeConstraints(ImVec2(400, -1), ImVec2(500, -1)); // Width 400-500
4335 if (type == 4) ImGui::SetNextWindowSizeConstraints(ImVec2(-1, 400), ImVec2(-1, 500)); // Height 400-500
4336 if (type == 5) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Square); // Always Square
4337 if (type == 6) ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(FLT_MAX, FLT_MAX), CustomConstraints::Step, (void*)(intptr_t)100); // Fixed Step
4338
4339 ImGuiWindowFlags flags = auto_resize ? ImGuiWindowFlags_AlwaysAutoResize : 0;
4340 if (ImGui::Begin("Example: Constrained Resize", p_open, flags))
4341 {
4342 const char* desc[] =
4343 {
4344 "Resize vertical only",
4345 "Resize horizontal only",
4346 "Width > 100, Height > 100",
4347 "Width 400-500",
4348 "Height 400-500",
4349 "Custom: Always Square",
4350 "Custom: Fixed Steps (100)",
4351 };
4352 if (ImGui::Button("200x200")) { ImGui::SetWindowSize(ImVec2(200, 200)); } ImGui::SameLine();
4353 if (ImGui::Button("500x500")) { ImGui::SetWindowSize(ImVec2(500, 500)); } ImGui::SameLine();
4354 if (ImGui::Button("800x200")) { ImGui::SetWindowSize(ImVec2(800, 200)); }
4355 ImGui::SetNextItemWidth(200);
4356 ImGui::Combo("Constraint", &type, desc, IM_ARRAYSIZE(desc));
4357 ImGui::SetNextItemWidth(200);
4358 ImGui::DragInt("Lines", &display_lines, 0.2f, 1, 100);
4359 ImGui::Checkbox("Auto-resize", &auto_resize);
4360 for (int i = 0; i < display_lines; i++)
4361 ImGui::Text("%*sHello, sailor! Making this line long enough for the example.", i * 4, "");
4362 }
4363 ImGui::End();
4364}
4365
4366//-----------------------------------------------------------------------------
4367// [SECTION] Example App: Simple Overlay / ShowExampleAppSimpleOverlay()

Callers 1

ShowDemoWindowMethod · 0.85

Calls 1

ImVec2Class · 0.85

Tested by

no test coverage detected