mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-14 17:07:01 +00:00
Made with the NoResize flag can still use auto-fitting. Added SetWindowSize().
This commit is contained in:
parent
fad5e45d2c
commit
3d84858755
63
imgui.cpp
63
imgui.cpp
@ -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,19 +2179,29 @@ 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))
|
||||
{
|
||||
// Manual auto-fit
|
||||
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();
|
||||
// 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;
|
||||
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
|
||||
@ -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();
|
||||
@ -2601,14 +2612,14 @@ ImDrawList* GetWindowDrawList()
|
||||
|
||||
ImFont GetWindowFont()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
return window->Font();
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
return window->Font();
|
||||
}
|
||||
|
||||
float GetWindowFontSize()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
return window->FontSize();
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
return window->FontSize();
|
||||
}
|
||||
|
||||
void SetWindowFontScale(float scale)
|
||||
@ -4666,7 +4677,7 @@ bool ColorEdit4(const char* label, float col[4], bool alpha)
|
||||
while (*p == '#' || *p == ' ' || *p == '\t')
|
||||
p++;
|
||||
|
||||
// Treat at unsigned (%X is unsigned)
|
||||
// Treat at unsigned (%X is unsigned)
|
||||
ix = iy = iz = iw = 0;
|
||||
if (alpha)
|
||||
sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw);
|
||||
|
5
imgui.h
5
imgui.h
@ -146,13 +146,14 @@ 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();
|
||||
ImVec2 GetWindowContentRegionMax();
|
||||
ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
|
||||
ImFont GetWindowFont();
|
||||
float GetWindowFontSize();
|
||||
ImFont GetWindowFont();
|
||||
float GetWindowFontSize();
|
||||
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 SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use 'offset' to access sub components of a multiple component widget.
|
||||
|
Loading…
Reference in New Issue
Block a user