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:
parent
29cff2be06
commit
f59da1956e
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user