1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-12-01 02:37:24 +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; FontWindowScale = 1.0f;
if (ImLength(Size) < 0.001f) if (ImLength(Size) < 0.001f)
AutoFitFrames = 3; AutoFitFrames = 2;
DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList)); DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
new(DrawList) 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); 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); ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding);
if (window->AutoFitFrames > 0) if (window->AutoFitFrames > 0)
{ {
@ -2186,19 +2179,29 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
window->SizeFull = ImMax(window->SizeFull, size_auto_fit); window->SizeFull = ImMax(window->SizeFull, size_auto_fit);
MarkSettingsDirty(); MarkSettingsDirty();
} }
else if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0]) else if (!(window->Flags & ImGuiWindowFlags_NoResize))
{ {
// Manual auto-fit // Resize grip
window->SizeFull = size_auto_fit; const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
window->Size = window->SizeFull; const ImGuiID resize_id = window->GetID("#RESIZE");
MarkSettingsDirty(); bool hovered, held;
} ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
else if (held) resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
{
// Resize if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize); {
window->Size = window->SizeFull; // Manual auto-fit
MarkSettingsDirty(); window->SizeFull = size_auto_fit;
window->Size = window->SizeFull;
MarkSettingsDirty();
}
else if (held)
{
// Resize
window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
window->Size = window->SizeFull;
MarkSettingsDirty();
}
} }
// Update aabb immediately so that the rendering below isn't one frame late // Update aabb immediately so that the rendering below isn't one frame late
@ -2565,6 +2568,14 @@ ImVec2 GetWindowSize()
return window->Size; return window->Size;
} }
void SetWindowSize(const ImVec2& size)
{
ImGuiWindow* window = GetCurrentWindow();
window->SizeFull = size;
if (ImLength(size) < 0.001f)
window->AutoFitFrames = 3;
}
ImVec2 GetWindowContentRegionMin() ImVec2 GetWindowContentRegionMin()
{ {
ImGuiWindow* window = GetCurrentWindow(); ImGuiWindow* window = GetCurrentWindow();
@ -2601,14 +2612,14 @@ ImDrawList* GetWindowDrawList()
ImFont GetWindowFont() ImFont GetWindowFont()
{ {
ImGuiWindow* window = GetCurrentWindow(); ImGuiWindow* window = GetCurrentWindow();
return window->Font(); return window->Font();
} }
float GetWindowFontSize() float GetWindowFontSize()
{ {
ImGuiWindow* window = GetCurrentWindow(); ImGuiWindow* window = GetCurrentWindow();
return window->FontSize(); return window->FontSize();
} }
void SetWindowFontScale(float scale) void SetWindowFontScale(float scale)
@ -4666,7 +4677,7 @@ bool ColorEdit4(const char* label, float col[4], bool alpha)
while (*p == '#' || *p == ' ' || *p == '\t') while (*p == '#' || *p == ' ' || *p == '\t')
p++; p++;
// Treat at unsigned (%X is unsigned) // Treat at unsigned (%X is unsigned)
ix = iy = iz = iw = 0; ix = iy = iz = iw = 0;
if (alpha) if (alpha)
sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw); sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw);

View File

@ -146,13 +146,14 @@ namespace ImGui
bool GetWindowIsFocused(); bool GetWindowIsFocused();
ImVec2 GetWindowSize(); ImVec2 GetWindowSize();
float GetWindowWidth(); 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. 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. void SetWindowPos(const ImVec2& pos); // set current window pos.
ImVec2 GetWindowContentRegionMin(); ImVec2 GetWindowContentRegionMin();
ImVec2 GetWindowContentRegionMax(); ImVec2 GetWindowContentRegionMax();
ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives. ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
ImFont GetWindowFont(); ImFont GetWindowFont();
float GetWindowFontSize(); float GetWindowFontSize();
void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontBaseScale if you want to scale all windows together. void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontBaseScale if you want to scale all windows together.
void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position. void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position.
void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use 'offset' to access sub components of a multiple component widget. void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use 'offset' to access sub components of a multiple component widget.