1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-24 07:40:22 +01:00

Made with the NoResize flag can still use auto-fitting. Added SetWindowSize().

This commit is contained in:
ocornut 2014-10-26 20:07:15 +00:00
parent fad5e45d2c
commit 3d84858755
2 changed files with 40 additions and 28 deletions

View File

@ -1023,7 +1023,7 @@ ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_si
FontWindowScale = 1.0f;
if (ImLength(Size) < 0.001f)
AutoFitFrames = 3;
AutoFitFrames = 2;
DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
new(DrawList) ImDrawList();
@ -2170,15 +2170,8 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
window->SizeFull = window->SizeContentsFit + g.Style.WindowPadding - ImVec2(0.0f, g.Style.ItemSpacing.y);
}
}
else if (!(window->Flags & ImGuiWindowFlags_NoResize))
else
{
// Draw resize grip
const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
const ImGuiID resize_id = window->GetID("#RESIZE");
bool hovered, held;
ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding);
if (window->AutoFitFrames > 0)
{
@ -2186,7 +2179,16 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
window->SizeFull = ImMax(window->SizeFull, size_auto_fit);
MarkSettingsDirty();
}
else if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
else if (!(window->Flags & ImGuiWindowFlags_NoResize))
{
// Resize grip
const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
const ImGuiID resize_id = window->GetID("#RESIZE");
bool hovered, held;
ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
{
// Manual auto-fit
window->SizeFull = size_auto_fit;
@ -2200,6 +2202,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
window->Size = window->SizeFull;
MarkSettingsDirty();
}
}
// Update aabb immediately so that the rendering below isn't one frame late
title_bar_aabb = window->TitleBarAabb();
@ -2565,6 +2568,14 @@ ImVec2 GetWindowSize()
return window->Size;
}
void SetWindowSize(const ImVec2& size)
{
ImGuiWindow* window = GetCurrentWindow();
window->SizeFull = size;
if (ImLength(size) < 0.001f)
window->AutoFitFrames = 3;
}
ImVec2 GetWindowContentRegionMin()
{
ImGuiWindow* window = GetCurrentWindow();

View File

@ -146,6 +146,7 @@ namespace ImGui
bool GetWindowIsFocused();
ImVec2 GetWindowSize();
float GetWindowWidth();
void SetWindowSize(const ImVec2& size); // set to ImVec2(0,0) to force an auto-fit
ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing.
void SetWindowPos(const ImVec2& pos); // set current window pos.
ImVec2 GetWindowContentRegionMin();