mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-07 13:35:49 +02:00
Merge branch 'master' into viewport
# Conflicts: # examples/example_glfw_opengl3/main.cpp # examples/imgui_impl_opengl3.cpp # imgui.cpp # imgui_internal.h
This commit is contained in:
187
imgui.cpp
187
imgui.cpp
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.63 WIP
|
||||
// dear imgui, v1.63
|
||||
// (main code and documentation)
|
||||
|
||||
// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code.
|
||||
@ -839,7 +839,7 @@
|
||||
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
|
||||
#endif
|
||||
|
||||
// Clang warnings with -Weverything
|
||||
// Clang/GCC warnings with -Weverything
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic ignored "-Wunknown-pragmas" // warning : unknown warning group '-Wformat-pedantic *' // not all warnings are known by all clang versions.. so ignoring warnings triggers new warnings on some configuration. great!
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
|
||||
@ -889,11 +889,7 @@ static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time before the w
|
||||
// Forward Declarations
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
|
||||
|
||||
static void SetCurrentWindow(ImGuiWindow* window);
|
||||
static void SetWindowScrollX(ImGuiWindow* window, float new_scroll_x);
|
||||
static void SetWindowScrollY(ImGuiWindow* window, float new_scroll_y);
|
||||
static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond);
|
||||
static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond);
|
||||
static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond);
|
||||
@ -926,7 +922,6 @@ static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb
|
||||
static void UpdateMouseInputs();
|
||||
static void UpdateMouseWheel();
|
||||
static void UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]);
|
||||
static void FocusFrontMostActiveWindow(ImGuiWindow* ignore_window);
|
||||
|
||||
// Viewports
|
||||
const ImGuiID IMGUI_VIEWPORT_DEFAULT_ID = 0x11111111; // Using an arbitrary constant instead of e.g. ImHash("ViewportDefault", 0); so it's easier to spot in the debugger. The exact value doesn't matter.
|
||||
@ -1128,10 +1123,6 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
|
||||
// HELPERS
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1]
|
||||
#define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose
|
||||
#define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255
|
||||
|
||||
ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p)
|
||||
{
|
||||
ImVec2 ap = p - a;
|
||||
@ -2062,7 +2053,7 @@ static void SetCursorPosYAndSetupDummyPrevLine(float pos_y, float line_height)
|
||||
ImGui::SetCursorPosY(pos_y);
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y - line_height; // Setting those fields so that SetScrollHere() can properly function after the end of our clipper usage.
|
||||
window->DC.PrevLineHeight = (line_height - GImGui->Style.ItemSpacing.y); // If we end up needing more accurate data (to e.g. use SameLine) we may as well make the clipper have a fourth step to let user process and display the last item in their list.
|
||||
window->DC.PrevLineSize.y = (line_height - GImGui->Style.ItemSpacing.y); // If we end up needing more accurate data (to e.g. use SameLine) we may as well make the clipper have a fourth step to let user process and display the last item in their list.
|
||||
if (window->DC.ColumnsSet)
|
||||
window->DC.ColumnsSet->LineMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly
|
||||
}
|
||||
@ -2263,7 +2254,7 @@ static void SetCurrentWindow(ImGuiWindow* window)
|
||||
g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize();
|
||||
}
|
||||
|
||||
static void SetNavID(ImGuiID id, int nav_layer)
|
||||
void ImGui::SetNavID(ImGuiID id, int nav_layer)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(g.NavWindow);
|
||||
@ -2272,7 +2263,7 @@ static void SetNavID(ImGuiID id, int nav_layer)
|
||||
g.NavWindow->NavLastIds[nav_layer] = id;
|
||||
}
|
||||
|
||||
static void SetNavIDWithRectRel(ImGuiID id, int nav_layer, const ImRect& rect_rel)
|
||||
void ImGui::SetNavIDWithRectRel(ImGuiID id, int nav_layer, const ImRect& rect_rel)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
SetNavID(id, nav_layer);
|
||||
@ -2404,18 +2395,18 @@ void ImGui::ItemSize(const ImVec2& size, float text_offset_y)
|
||||
return;
|
||||
|
||||
// Always align ourselves on pixel boundaries
|
||||
const float line_height = ImMax(window->DC.CurrentLineHeight, size.y);
|
||||
const float line_height = ImMax(window->DC.CurrentLineSize.y, size.y);
|
||||
const float text_base_offset = ImMax(window->DC.CurrentLineTextBaseOffset, text_offset_y);
|
||||
//if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG]
|
||||
window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
|
||||
window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y));
|
||||
window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y));
|
||||
window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x);
|
||||
window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y);
|
||||
//if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG]
|
||||
|
||||
window->DC.PrevLineHeight = line_height;
|
||||
window->DC.PrevLineSize.y = line_height;
|
||||
window->DC.PrevLineTextBaseOffset = text_base_offset;
|
||||
window->DC.CurrentLineHeight = window->DC.CurrentLineTextBaseOffset = 0.0f;
|
||||
window->DC.CurrentLineSize.y = window->DC.CurrentLineTextBaseOffset = 0.0f;
|
||||
|
||||
// Horizontal layout mode
|
||||
if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
|
||||
@ -2611,7 +2602,7 @@ static void NavRestoreLayer(int layer)
|
||||
if (layer == 0)
|
||||
g.NavWindow = NavRestoreLastChildNavWindow(g.NavWindow);
|
||||
if (layer == 0 && g.NavWindow->NavLastIds[0] != 0)
|
||||
SetNavIDWithRectRel(g.NavWindow->NavLastIds[0], layer, g.NavWindow->NavRectRel[0]);
|
||||
ImGui::SetNavIDWithRectRel(g.NavWindow->NavLastIds[0], layer, g.NavWindow->NavRectRel[0]);
|
||||
else
|
||||
ImGui::NavInitWindow(g.NavWindow, true);
|
||||
}
|
||||
@ -2624,7 +2615,7 @@ static inline void NavUpdateAnyRequestFlag()
|
||||
IM_ASSERT(g.NavWindow != NULL);
|
||||
}
|
||||
|
||||
static bool NavMoveRequestButNoResultYet()
|
||||
bool ImGui::NavMoveRequestButNoResultYet()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
return g.NavMoveRequest && g.NavMoveResultLocal.ID == 0 && g.NavMoveResultOther.ID == 0;
|
||||
@ -3115,23 +3106,6 @@ float ImGui::GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode)
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// Equivalent of IsKeyDown() for NavInputs[]
|
||||
static bool IsNavInputDown(ImGuiNavInput n)
|
||||
{
|
||||
return GImGui->IO.NavInputs[n] > 0.0f;
|
||||
}
|
||||
|
||||
// Equivalent of IsKeyPressed() for NavInputs[]
|
||||
static bool IsNavInputPressed(ImGuiNavInput n, ImGuiInputReadMode mode)
|
||||
{
|
||||
return ImGui::GetNavInputAmount(n, mode) > 0.0f;
|
||||
}
|
||||
|
||||
static bool IsNavInputPressedAnyOfTwo(ImGuiNavInput n1, ImGuiNavInput n2, ImGuiInputReadMode mode)
|
||||
{
|
||||
return (ImGui::GetNavInputAmount(n1, mode) + ImGui::GetNavInputAmount(n2, mode)) > 0.0f;
|
||||
}
|
||||
|
||||
ImVec2 ImGui::GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor, float fast_factor)
|
||||
{
|
||||
ImVec2 delta(0.0f, 0.0f);
|
||||
@ -4348,7 +4322,7 @@ void ImGui::NewFrame()
|
||||
{
|
||||
if ((g.IO.BackendFlags & ImGuiBackendFlags_PlatformHasViewports) && (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasViewports))
|
||||
{
|
||||
IM_ASSERT(g.FrameCount == 0 || g.FrameCountPlatformEnded == g.FrameCount && "Forgot to call UpdatePlatformWindows() at the end of the previous frame?");
|
||||
IM_ASSERT((g.FrameCount == 0 || g.FrameCount == g.FrameCountPlatformEnded) && "Forgot to call UpdatePlatformWindows() at the end of the previous frame?");
|
||||
IM_ASSERT(g.PlatformIO.Platform_CreateWindow != NULL && "Platform init didn't install handlers?");
|
||||
IM_ASSERT(g.PlatformIO.Platform_DestroyWindow != NULL && "Platform init didn't install handlers?");
|
||||
IM_ASSERT(g.PlatformIO.Platform_GetWindowPos != NULL && "Platform init didn't install handlers?");
|
||||
@ -4515,7 +4489,7 @@ void ImGui::NewFrame()
|
||||
|
||||
// Closing the focused window restore focus to the first active root window in descending z-order
|
||||
if (g.NavWindow && !g.NavWindow->WasActive)
|
||||
FocusFrontMostActiveWindow(NULL);
|
||||
FocusFrontMostActiveWindowIgnoringOne(NULL);
|
||||
|
||||
// No window should be open at the beginning of the frame.
|
||||
// But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
|
||||
@ -5309,7 +5283,7 @@ void ImGui::LogText(const char* fmt, ...)
|
||||
|
||||
// Internal version that takes a position to decide on newline placement and pad items according to their depth.
|
||||
// We split text into individual lines to add current tree level padding
|
||||
static void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL)
|
||||
void ImGui::LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
@ -5701,12 +5675,6 @@ bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool c
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
|
||||
{
|
||||
const int key_index = GImGui->IO.KeyMap[key];
|
||||
return (key_index >= 0) ? ImGui::IsKeyPressed(key_index, repeat) : false;
|
||||
}
|
||||
|
||||
int ImGui::GetKeyIndex(ImGuiKey imgui_key)
|
||||
{
|
||||
IM_ASSERT(imgui_key >= 0 && imgui_key < ImGuiKey_COUNT);
|
||||
@ -6481,18 +6449,12 @@ static void CheckStacksSize(ImGuiWindow* window, bool write)
|
||||
IM_ASSERT(p_backup == window->DC.StackSizesBackup + IM_ARRAYSIZE(window->DC.StackSizesBackup));
|
||||
}
|
||||
|
||||
enum ImGuiPopupPositionPolicy
|
||||
{
|
||||
ImGuiPopupPositionPolicy_Default,
|
||||
ImGuiPopupPositionPolicy_ComboBox
|
||||
};
|
||||
|
||||
// r_avoid = the rectangle to avoid (e.g. for tooltip it is a rectangle around the mouse cursor which we want to avoid. for popups it's a small point around the cursor.)
|
||||
// r_outer = the visible area rectangle, minus safe area padding. If our popup size won't fit because of safe area padding we ignore it.
|
||||
// (r_outer is usually equivalent to the viewport rectangle minus padding, but when multi-viewports are enabled and monitor
|
||||
// information are available, it may represent the entire platform monitor from the frame of reference of the current viewport.
|
||||
// this allows us to have tooltips/popups displayed out of the parent viewport.)
|
||||
static ImVec2 FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_outer, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy = ImGuiPopupPositionPolicy_Default)
|
||||
ImVec2 ImGui::FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_outer, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy)
|
||||
{
|
||||
ImVec2 base_pos_clamped = ImClamp(ref_pos, r_outer.Min, r_outer.Max - size);
|
||||
//GImGui->OverlayDrawList.AddRect(r_avoid.Min, r_avoid.Max, IM_COL32(255,0,0,255));
|
||||
@ -6545,7 +6507,7 @@ static ImVec2 FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& s
|
||||
return pos;
|
||||
}
|
||||
|
||||
static ImRect FindAllowedExtentRectForWindow(ImGuiWindow* window)
|
||||
ImRect ImGui::GetWindowAllowedExtentRect(ImGuiWindow* window)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImRect r_screen;
|
||||
@ -6566,7 +6528,7 @@ static ImRect FindAllowedExtentRectForWindow(ImGuiWindow* window)
|
||||
return r_screen;
|
||||
}
|
||||
|
||||
static ImVec2 FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (window->Flags & ImGuiWindowFlags_ChildMenu)
|
||||
@ -6575,7 +6537,7 @@ static ImVec2 FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
// This is how we end up with child menus appearing (most-commonly) on the right of the parent menu.
|
||||
ImGuiWindow* parent_window = window->ParentWindow;
|
||||
float horizontal_overlap = g.Style.ItemSpacing.x; // We want some overlap to convey the relative depth of each menu (currently the amount of overlap is hard-coded to style.ItemSpacing.x).
|
||||
ImRect r_outer = FindAllowedExtentRectForWindow(window);
|
||||
ImRect r_outer = GetWindowAllowedExtentRect(window);
|
||||
ImRect r_avoid;
|
||||
if (parent_window->DC.MenuBarAppending)
|
||||
r_avoid = ImRect(-FLT_MAX, parent_window->Pos.y + parent_window->TitleBarHeight(), FLT_MAX, parent_window->Pos.y + parent_window->TitleBarHeight() + parent_window->MenuBarHeight());
|
||||
@ -6585,7 +6547,7 @@ static ImVec2 FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
}
|
||||
if (window->Flags & ImGuiWindowFlags_Popup)
|
||||
{
|
||||
ImRect r_outer = FindAllowedExtentRectForWindow(window);
|
||||
ImRect r_outer = GetWindowAllowedExtentRect(window);
|
||||
ImRect r_avoid = ImRect(window->Pos.x - 1, window->Pos.y - 1, window->Pos.x + 1, window->Pos.y + 1);
|
||||
return FindBestWindowPosForPopupEx(window->Pos, window->Size, &window->AutoPosLastDirection, r_outer, r_avoid);
|
||||
}
|
||||
@ -6594,7 +6556,7 @@ static ImVec2 FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
// Position tooltip (always follows mouse)
|
||||
float sc = g.Style.MouseCursorScale;
|
||||
ImVec2 ref_pos = NavCalcPreferredRefPos();
|
||||
ImRect r_outer = FindAllowedExtentRectForWindow(window);
|
||||
ImRect r_outer = GetWindowAllowedExtentRect(window);
|
||||
ImRect r_avoid;
|
||||
if (!g.NavDisableHighlight && g.NavDisableMouseHover && !(g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos))
|
||||
r_avoid = ImRect(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 16, ref_pos.y + 8);
|
||||
@ -6756,6 +6718,12 @@ static ImVec2 CalcSizeAutoFit(ImGuiWindow* window, const ImVec2& size_contents)
|
||||
}
|
||||
}
|
||||
|
||||
ImVec2 ImGui::CalcWindowExpectedSize(ImGuiWindow* window)
|
||||
{
|
||||
ImVec2 size_contents = CalcSizeContents(window);
|
||||
return CalcSizeAfterConstraint(window, CalcSizeAutoFit(window, size_contents));
|
||||
}
|
||||
|
||||
static float GetScrollMaxX(ImGuiWindow* window)
|
||||
{
|
||||
return ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x));
|
||||
@ -7641,14 +7609,14 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
|
||||
// Setup drawing context
|
||||
// (NB: That term "drawing context / DC" lost its meaning a long time ago. Initially was meant to hold transient data only. Nowadays difference between window-> and window->DC-> is dubious.)
|
||||
window->DC.IndentX = 0.0f + window->WindowPadding.x - window->Scroll.x;
|
||||
window->DC.GroupOffsetX = 0.0f;
|
||||
window->DC.ColumnsOffsetX = 0.0f;
|
||||
window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.IndentX + window->DC.ColumnsOffsetX, window->TitleBarHeight() + window->MenuBarHeight() + window->WindowPadding.y - window->Scroll.y);
|
||||
window->DC.Indent.x = 0.0f + window->WindowPadding.x - window->Scroll.x;
|
||||
window->DC.GroupOffset.x = 0.0f;
|
||||
window->DC.ColumnsOffset.x = 0.0f;
|
||||
window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.Indent.x + window->DC.ColumnsOffset.x, window->TitleBarHeight() + window->MenuBarHeight() + window->WindowPadding.y - window->Scroll.y);
|
||||
window->DC.CursorPos = window->DC.CursorStartPos;
|
||||
window->DC.CursorPosPrevLine = window->DC.CursorPos;
|
||||
window->DC.CursorMaxPos = window->DC.CursorStartPos;
|
||||
window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f;
|
||||
window->DC.CurrentLineSize = window->DC.PrevLineSize = ImVec2(0.0f, 0.0f);
|
||||
window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
|
||||
window->DC.NavHideHighlightOneFrame = false;
|
||||
window->DC.NavHasScroll = (GetScrollMaxY() > 0.0f);
|
||||
@ -8029,7 +7997,7 @@ void ImGui::FocusWindow(ImGuiWindow* window)
|
||||
BringWindowToFront(window);
|
||||
}
|
||||
|
||||
void ImGui::FocusFrontMostActiveWindow(ImGuiWindow* ignore_window)
|
||||
void ImGui::FocusFrontMostActiveWindowIgnoringOne(ImGuiWindow* ignore_window)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
for (int i = g.Windows.Size - 1; i >= 0; i--)
|
||||
@ -8437,14 +8405,14 @@ ImVec2 ImGui::GetWindowPos()
|
||||
return window->Pos;
|
||||
}
|
||||
|
||||
static void SetWindowScrollX(ImGuiWindow* window, float new_scroll_x)
|
||||
void ImGui::SetWindowScrollX(ImGuiWindow* window, float new_scroll_x)
|
||||
{
|
||||
window->DC.CursorMaxPos.x += window->Scroll.x; // SizeContents is generally computed based on CursorMaxPos which is affected by scroll position, so we need to apply our change to it.
|
||||
window->Scroll.x = new_scroll_x;
|
||||
window->DC.CursorMaxPos.x -= window->Scroll.x;
|
||||
}
|
||||
|
||||
static void SetWindowScrollY(ImGuiWindow* window, float new_scroll_y)
|
||||
void ImGui::SetWindowScrollY(ImGuiWindow* window, float new_scroll_y)
|
||||
{
|
||||
window->DC.CursorMaxPos.y += window->Scroll.y; // SizeContents is generally computed based on CursorMaxPos which is affected by scroll position, so we need to apply our change to it.
|
||||
window->Scroll.y = new_scroll_y;
|
||||
@ -8866,7 +8834,7 @@ void ImGui::SetScrollHere(float center_y_ratio)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
float target_y = window->DC.CursorPosPrevLine.y - window->Pos.y; // Top of last item, in window space
|
||||
target_y += (window->DC.PrevLineHeight * center_y_ratio) + (GImGui->Style.ItemSpacing.y * (center_y_ratio - 0.5f) * 2.0f); // Precisely aim above, in the middle or below the last line.
|
||||
target_y += (window->DC.PrevLineSize.y * center_y_ratio) + (GImGui->Style.ItemSpacing.y * (center_y_ratio - 0.5f) * 2.0f); // Precisely aim above, in the middle or below the last line.
|
||||
SetScrollFromPosY(target_y, center_y_ratio);
|
||||
}
|
||||
|
||||
@ -9091,7 +9059,7 @@ void ImGui::AlignTextToFramePadding()
|
||||
return;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
window->DC.CurrentLineHeight = ImMax(window->DC.CurrentLineHeight, g.FontSize + g.Style.FramePadding.y * 2);
|
||||
window->DC.CurrentLineSize.y = ImMax(window->DC.CurrentLineSize.y, g.FontSize + g.Style.FramePadding.y * 2);
|
||||
window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.CurrentLineTextBaseOffset, g.Style.FramePadding.y);
|
||||
}
|
||||
|
||||
@ -9682,7 +9650,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
|
||||
|
||||
// We vertically grow up to current line height up the typical widget height.
|
||||
const float text_base_offset_y = ImMax(padding.y, window->DC.CurrentLineTextBaseOffset); // Latch before ItemSize changes it
|
||||
const float frame_height = ImMax(ImMin(window->DC.CurrentLineHeight, g.FontSize + style.FramePadding.y*2), label_size.y + padding.y*2);
|
||||
const float frame_height = ImMax(ImMin(window->DC.CurrentLineSize.y, g.FontSize + style.FramePadding.y*2), label_size.y + padding.y*2);
|
||||
ImRect frame_bb = ImRect(window->DC.CursorPos, ImVec2(window->Pos.x + GetContentRegionMax().x, window->DC.CursorPos.y + frame_height));
|
||||
if (display_frame)
|
||||
{
|
||||
@ -10007,7 +9975,7 @@ void ImGui::Bullet()
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
const float line_height = ImMax(ImMin(window->DC.CurrentLineHeight, g.FontSize + g.Style.FramePadding.y*2), g.FontSize);
|
||||
const float line_height = ImMax(ImMin(window->DC.CurrentLineSize.y, g.FontSize + g.Style.FramePadding.y*2), g.FontSize);
|
||||
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize, line_height));
|
||||
ItemSize(bb);
|
||||
if (!ItemAdd(bb, 0))
|
||||
@ -10035,7 +10003,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args)
|
||||
const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
|
||||
const ImVec2 label_size = CalcTextSize(text_begin, text_end, false);
|
||||
const float text_base_offset_y = ImMax(0.0f, window->DC.CurrentLineTextBaseOffset); // Latch before ItemSize changes it
|
||||
const float line_height = ImMax(ImMin(window->DC.CurrentLineHeight, g.FontSize + g.Style.FramePadding.y*2), g.FontSize);
|
||||
const float line_height = ImMax(ImMin(window->DC.CurrentLineSize.y, g.FontSize + g.Style.FramePadding.y*2), g.FontSize);
|
||||
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize + (label_size.x > 0.0f ? (label_size.x + style.FramePadding.x*2) : 0.0f), ImMax(line_height, label_size.y))); // Empty text doesn't add padding
|
||||
ItemSize(bb);
|
||||
if (!ItemAdd(bb, 0))
|
||||
@ -12677,11 +12645,10 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF
|
||||
if (ImGuiWindow* popup_window = FindWindowByName(name))
|
||||
if (popup_window->WasActive)
|
||||
{
|
||||
ImVec2 size_contents = CalcSizeContents(popup_window);
|
||||
ImVec2 size_expected = CalcSizeAfterConstraint(popup_window, CalcSizeAutoFit(popup_window, size_contents));
|
||||
ImVec2 size_expected = CalcWindowExpectedSize(popup_window);
|
||||
if (flags & ImGuiComboFlags_PopupAlignLeft)
|
||||
popup_window->AutoPosLastDirection = ImGuiDir_Left;
|
||||
ImRect r_outer = FindAllowedExtentRectForWindow(popup_window);
|
||||
ImRect r_outer = GetWindowAllowedExtentRect(popup_window);
|
||||
ImVec2 pos = FindBestWindowPosForPopupEx(frame_bb.GetBL(), size_expected, &popup_window->AutoPosLastDirection, r_outer, frame_bb, ImGuiPopupPositionPolicy_ComboBox);
|
||||
SetNextWindowPos(pos);
|
||||
}
|
||||
@ -13083,7 +13050,7 @@ void ImGui::EndMainMenuBar()
|
||||
// When the user has left the menu layer (typically: closed menus through activation of an item), we restore focus to the previous window
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.CurrentWindow == g.NavWindow && g.NavLayer == 0)
|
||||
FocusFrontMostActiveWindow(g.NavWindow);
|
||||
FocusFrontMostActiveWindowIgnoringOne(g.NavWindow);
|
||||
|
||||
End();
|
||||
}
|
||||
@ -13522,7 +13489,7 @@ void ImGui::ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags)
|
||||
EndPopup();
|
||||
}
|
||||
|
||||
static void ColorPickerOptionsPopup(ImGuiColorEditFlags flags, const float* ref_col)
|
||||
void ImGui::ColorPickerOptionsPopup(const float* ref_col, ImGuiColorEditFlags flags)
|
||||
{
|
||||
bool allow_opt_picker = !(flags & ImGuiColorEditFlags__PickerMask);
|
||||
bool allow_opt_alpha_bar = !(flags & ImGuiColorEditFlags_NoAlpha) && !(flags & ImGuiColorEditFlags_AlphaBar);
|
||||
@ -13803,7 +13770,6 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
|
||||
|
||||
// Context menu: display and store options.
|
||||
if (!(flags & ImGuiColorEditFlags_NoOptions))
|
||||
ColorPickerOptionsPopup(flags, col);
|
||||
|
||||
// Read stored options
|
||||
if (!(flags & ImGuiColorEditFlags__PickerMask))
|
||||
@ -13957,13 +13923,20 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
|
||||
ColorConvertHSVtoRGB(H >= 1.0f ? H - 10 * 1e-6f : H, S > 0.0f ? S : 10*1e-6f, V > 0.0f ? V : 1e-6f, col[0], col[1], col[2]);
|
||||
|
||||
// R,G,B and H,S,V slider color editor
|
||||
bool value_changed_fix_hue_wrap = false;
|
||||
if ((flags & ImGuiColorEditFlags_NoInputs) == 0)
|
||||
{
|
||||
PushItemWidth((alpha_bar ? bar1_pos_x : bar0_pos_x) + bars_width - picker_pos.x);
|
||||
ImGuiColorEditFlags sub_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoOptions | ImGuiColorEditFlags_NoSmallPreview | ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_AlphaPreviewHalf;
|
||||
ImGuiColorEditFlags sub_flags = (flags & sub_flags_to_forward) | ImGuiColorEditFlags_NoPicker;
|
||||
if (flags & ImGuiColorEditFlags_RGB || (flags & ImGuiColorEditFlags__InputsMask) == 0)
|
||||
value_changed |= ColorEdit4("##rgb", col, sub_flags | ImGuiColorEditFlags_RGB);
|
||||
if (ColorEdit4("##rgb", col, sub_flags | ImGuiColorEditFlags_RGB))
|
||||
{
|
||||
// FIXME: Hackily differenciating using the DragInt (ActiveId != 0 && !ActiveIdAllowOverlap) vs. using the InputText or DropTarget.
|
||||
// For the later we don't want to run the hue-wrap canceling code. If you are well versed in HSV picker please provide your input! (See #2050)
|
||||
value_changed_fix_hue_wrap = (g.ActiveId != 0 && !g.ActiveIdAllowOverlap);
|
||||
value_changed = true;
|
||||
}
|
||||
if (flags & ImGuiColorEditFlags_HSV || (flags & ImGuiColorEditFlags__InputsMask) == 0)
|
||||
value_changed |= ColorEdit4("##hsv", col, sub_flags | ImGuiColorEditFlags_HSV);
|
||||
if (flags & ImGuiColorEditFlags_HEX || (flags & ImGuiColorEditFlags__InputsMask) == 0)
|
||||
@ -13971,8 +13944,8 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
|
||||
PopItemWidth();
|
||||
}
|
||||
|
||||
// Try to cancel hue wrap (after ColorEdit), if any
|
||||
if (value_changed)
|
||||
// Try to cancel hue wrap (after ColorEdit4 call), if any
|
||||
if (value_changed_fix_hue_wrap)
|
||||
{
|
||||
float new_H, new_S, new_V;
|
||||
ColorConvertRGBtoHSV(col[0], col[1], col[2], new_H, new_S, new_V);
|
||||
@ -14108,7 +14081,7 @@ void ImGui::Separator()
|
||||
float x1 = window->Pos.x;
|
||||
float x2 = window->Pos.x + window->Size.x;
|
||||
if (!window->DC.GroupStack.empty())
|
||||
x1 += window->DC.IndentX;
|
||||
x1 += window->DC.Indent.x;
|
||||
|
||||
const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y+1.0f));
|
||||
ItemSize(ImVec2(0.0f, 0.0f)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit, we don't provide height to not alter layout.
|
||||
@ -14139,7 +14112,7 @@ void ImGui::VerticalSeparator()
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
float y1 = window->DC.CursorPos.y;
|
||||
float y2 = window->DC.CursorPos.y + window->DC.CurrentLineHeight;
|
||||
float y2 = window->DC.CursorPos.y + window->DC.CurrentLineSize.y;
|
||||
const ImRect bb(ImVec2(window->DC.CursorPos.x, y1), ImVec2(window->DC.CursorPos.x + 1.0f, y2));
|
||||
ItemSize(ImVec2(bb.GetWidth(), 0.0f));
|
||||
if (!ItemAdd(bb, 0))
|
||||
@ -14249,19 +14222,19 @@ void ImGui::BeginGroup()
|
||||
ImGuiGroupData& group_data = window->DC.GroupStack.back();
|
||||
group_data.BackupCursorPos = window->DC.CursorPos;
|
||||
group_data.BackupCursorMaxPos = window->DC.CursorMaxPos;
|
||||
group_data.BackupIndentX = window->DC.IndentX;
|
||||
group_data.BackupGroupOffsetX = window->DC.GroupOffsetX;
|
||||
group_data.BackupCurrentLineHeight = window->DC.CurrentLineHeight;
|
||||
group_data.BackupIndent = window->DC.Indent;
|
||||
group_data.BackupGroupOffset = window->DC.GroupOffset;
|
||||
group_data.BackupCurrentLineSize = window->DC.CurrentLineSize;
|
||||
group_data.BackupCurrentLineTextBaseOffset = window->DC.CurrentLineTextBaseOffset;
|
||||
group_data.BackupLogLinePosY = window->DC.LogLinePosY;
|
||||
group_data.BackupActiveIdIsAlive = g.ActiveIdIsAlive;
|
||||
group_data.BackupActiveIdPreviousFrameIsAlive = g.ActiveIdPreviousFrameIsAlive;
|
||||
group_data.AdvanceCursor = true;
|
||||
|
||||
window->DC.GroupOffsetX = window->DC.CursorPos.x - window->Pos.x - window->DC.ColumnsOffsetX;
|
||||
window->DC.IndentX = window->DC.GroupOffsetX;
|
||||
window->DC.GroupOffset.x = window->DC.CursorPos.x - window->Pos.x - window->DC.ColumnsOffset.x;
|
||||
window->DC.Indent = window->DC.GroupOffset;
|
||||
window->DC.CursorMaxPos = window->DC.CursorPos;
|
||||
window->DC.CurrentLineHeight = 0.0f;
|
||||
window->DC.CurrentLineSize = ImVec2(0.0f, 0.0f);
|
||||
window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; // To enforce Log carriage return
|
||||
}
|
||||
|
||||
@ -14278,9 +14251,9 @@ void ImGui::EndGroup()
|
||||
|
||||
window->DC.CursorPos = group_data.BackupCursorPos;
|
||||
window->DC.CursorMaxPos = ImMax(group_data.BackupCursorMaxPos, window->DC.CursorMaxPos);
|
||||
window->DC.IndentX = group_data.BackupIndentX;
|
||||
window->DC.GroupOffsetX = group_data.BackupGroupOffsetX;
|
||||
window->DC.CurrentLineHeight = group_data.BackupCurrentLineHeight;
|
||||
window->DC.Indent = group_data.BackupIndent;
|
||||
window->DC.GroupOffset = group_data.BackupGroupOffset;
|
||||
window->DC.CurrentLineSize = group_data.BackupCurrentLineSize;
|
||||
window->DC.CurrentLineTextBaseOffset = group_data.BackupCurrentLineTextBaseOffset;
|
||||
window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; // To enforce Log carriage return
|
||||
|
||||
@ -14320,7 +14293,7 @@ void ImGui::SameLine(float pos_x, float spacing_w)
|
||||
if (pos_x != 0.0f)
|
||||
{
|
||||
if (spacing_w < 0.0f) spacing_w = 0.0f;
|
||||
window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + pos_x + spacing_w + window->DC.GroupOffsetX + window->DC.ColumnsOffsetX;
|
||||
window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + pos_x + spacing_w + window->DC.GroupOffset.x + window->DC.ColumnsOffset.x;
|
||||
window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y;
|
||||
}
|
||||
else
|
||||
@ -14329,7 +14302,7 @@ void ImGui::SameLine(float pos_x, float spacing_w)
|
||||
window->DC.CursorPos.x = window->DC.CursorPosPrevLine.x + spacing_w;
|
||||
window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y;
|
||||
}
|
||||
window->DC.CurrentLineHeight = window->DC.PrevLineHeight;
|
||||
window->DC.CurrentLineSize = window->DC.PrevLineSize;
|
||||
window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset;
|
||||
}
|
||||
|
||||
@ -14342,7 +14315,7 @@ void ImGui::NewLine()
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiLayoutType backup_layout_type = window->DC.LayoutType;
|
||||
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
||||
if (window->DC.CurrentLineHeight > 0.0f) // In the event that we are on a line with items that is smaller that FontSize high, we will preserve its height.
|
||||
if (window->DC.CurrentLineSize.y > 0.0f) // In the event that we are on a line with items that is smaller that FontSize high, we will preserve its height.
|
||||
ItemSize(ImVec2(0,0));
|
||||
else
|
||||
ItemSize(ImVec2(0.0f, g.FontSize));
|
||||
@ -14364,19 +14337,19 @@ void ImGui::NextColumn()
|
||||
if (++columns->Current < columns->Count)
|
||||
{
|
||||
// Columns 1+ cancel out IndentX
|
||||
window->DC.ColumnsOffsetX = GetColumnOffset(columns->Current) - window->DC.IndentX + g.Style.ItemSpacing.x;
|
||||
window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + g.Style.ItemSpacing.x;
|
||||
window->DrawList->ChannelsSetCurrent(columns->Current);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->DC.ColumnsOffsetX = 0.0f;
|
||||
window->DC.ColumnsOffset.x = 0.0f;
|
||||
window->DrawList->ChannelsSetCurrent(0);
|
||||
columns->Current = 0;
|
||||
columns->LineMinY = columns->LineMaxY;
|
||||
}
|
||||
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX);
|
||||
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
|
||||
window->DC.CursorPos.y = columns->LineMinY;
|
||||
window->DC.CurrentLineHeight = 0.0f;
|
||||
window->DC.CurrentLineSize = ImVec2(0.0f, 0.0f);
|
||||
window->DC.CurrentLineTextBaseOffset = 0.0f;
|
||||
|
||||
PushColumnClipRect();
|
||||
@ -14542,13 +14515,13 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
|
||||
|
||||
// Set state for first column
|
||||
const float content_region_width = (window->SizeContentsExplicit.x != 0.0f) ? (window->SizeContentsExplicit.x) : (window->InnerClipRect.Max.x - window->Pos.x);
|
||||
columns->MinX = window->DC.IndentX - g.Style.ItemSpacing.x; // Lock our horizontal range
|
||||
columns->MinX = window->DC.Indent.x - g.Style.ItemSpacing.x; // Lock our horizontal range
|
||||
columns->MaxX = ImMax(content_region_width - window->Scroll.x, columns->MinX + 1.0f);
|
||||
columns->StartPosY = window->DC.CursorPos.y;
|
||||
columns->StartMaxPosX = window->DC.CursorMaxPos.x;
|
||||
columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y;
|
||||
window->DC.ColumnsOffsetX = 0.0f;
|
||||
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX);
|
||||
window->DC.ColumnsOffset.x = 0.0f;
|
||||
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
|
||||
|
||||
// Clear data if columns count changed
|
||||
if (columns->Columns.Size != 0 && columns->Columns.Size != columns_count + 1)
|
||||
@ -14645,8 +14618,8 @@ void ImGui::EndColumns()
|
||||
columns->IsBeingResized = is_being_resized;
|
||||
|
||||
window->DC.ColumnsSet = NULL;
|
||||
window->DC.ColumnsOffsetX = 0.0f;
|
||||
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX);
|
||||
window->DC.ColumnsOffset.x = 0.0f;
|
||||
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
|
||||
}
|
||||
|
||||
// [2018-03: This is currently the only public API, while we are working on making BeginColumns/EndColumns user-facing]
|
||||
@ -14671,16 +14644,16 @@ void ImGui::Indent(float indent_w)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
window->DC.IndentX += (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing;
|
||||
window->DC.CursorPos.x = window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX;
|
||||
window->DC.Indent.x += (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing;
|
||||
window->DC.CursorPos.x = window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x;
|
||||
}
|
||||
|
||||
void ImGui::Unindent(float indent_w)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
window->DC.IndentX -= (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing;
|
||||
window->DC.CursorPos.x = window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX;
|
||||
window->DC.Indent.x -= (indent_w != 0.0f) ? indent_w : g.Style.IndentSpacing;
|
||||
window->DC.CursorPos.x = window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x;
|
||||
}
|
||||
|
||||
void ImGui::TreePush(const char* str_id)
|
||||
|
Reference in New Issue
Block a user