1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-23 23:31:08 +01:00

Demo: fixed resizing while maintaining aspect constraint

in ShowExampleAppConstrainedResize
This commit is contained in:
imdongye 2024-09-30 02:42:18 +09:00 committed by GitHub
parent 29cff2be06
commit f59da1956e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9117,11 +9117,33 @@ static void ShowExampleAppConstrainedResize(bool* p_open)
static void AspectRatio(ImGuiSizeCallbackData* data)
{
float aspect_ratio = *(float*)data->UserData;
data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio);
int current_cursor = ImGui::GetMouseCursor();
if(current_cursor == ImGuiMouseCursor_ResizeNWSE || current_cursor == ImGuiMouseCursor_ResizeNESW)
{
if(aspect_ratio > data->DesiredSize.x / data->DesiredSize.y)
data->DesiredSize.x = aspect_ratio * data->DesiredSize.y;
else
data->DesiredSize.y = data->DesiredSize.x / aspect_ratio;
}
else if(current_cursor == ImGuiMouseCursor_ResizeNS)
data->DesiredSize.x = aspect_ratio * data->DesiredSize.y;
else if(current_cursor == ImGuiMouseCursor_ResizeEW)
data->DesiredSize.y = data->DesiredSize.x / aspect_ratio;
}
static void Square(ImGuiSizeCallbackData* data)
{
data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->DesiredSize.x, data->DesiredSize.y);
int current_cursor = ImGui::GetMouseCursor();
if(current_cursor == ImGuiMouseCursor_ResizeNWSE || current_cursor == ImGuiMouseCursor_ResizeNESW)
{
if(1.f > data->DesiredSize.x / data->DesiredSize.y)
data->DesiredSize.x = data->DesiredSize.y;
else
data->DesiredSize.y = data->DesiredSize.x;
}
else if(current_cursor == ImGuiMouseCursor_ResizeNS)
data->DesiredSize.x = data->DesiredSize.y;
else if(current_cursor == ImGuiMouseCursor_ResizeEW)
data->DesiredSize.y = data->DesiredSize.x;
}
static void Step(ImGuiSizeCallbackData* data)
{