mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-21 15:16:35 +00:00
Merge branch 'master' into docking
# Conflicts: # imgui.cpp # imgui_internal.h
This commit is contained in:
commit
0bdc145343
@ -106,15 +106,27 @@ Other Changes:
|
||||
- ColorPicker: Made rendering aware of global style alpha of the picker can be faded out. (#2711)
|
||||
Note that some elements won't accurately fade down with the same intensity, and the color wheel
|
||||
when enabled will have small overlap glitches with (style.Alpha < 1.0).
|
||||
- ColorEdit: Disable Hue edit when Saturation==0 instead of letting Hue values jump around.
|
||||
- TabBar: fixed ScrollToBar request creating bouncing loop when tab is larger than available space.
|
||||
- TabBar: fixed single-tab not shrinking their width down.
|
||||
- TabBar: feed desired width (sum of unclipped tabs width) into layout system to allow for auto-resize. (#2768)
|
||||
(before 1.71 tab bars fed the sum of current width which created feedback loops in certain situations).
|
||||
- TabBar: improved shrinking for large number of tabs to avoid leaving extraneous space on the right side.
|
||||
Individuals tabs are given integer-rounded width and remainder is spread between tabs left-to-right.
|
||||
- SliderScalar: Improved assert when using U32 or U64 types with a large v_max value. (#2765) [@loicmouton]
|
||||
- DragInt, DragFloat, DragScalar: Using (v_min > v_max) allows locking any edit to the value.
|
||||
- ImDrawList: clarified the name of many parameters so reading the code is a little easier. (#2740)
|
||||
- Using offsetof() when available in C++11. Avoids Clang sanitizer complaining about old-style macros. (#94)
|
||||
- Added a mechanism to compact/free the larger allocations of unused windows (buffers are compacted when
|
||||
a window is unused for 60 seconds, as per io.ConfigWindowsMemoryCompactTimer = 60.0f). Note that memory
|
||||
usage has never been reported as a problem, so this is merely a touch of overzealous luxury. (#2636)
|
||||
- Backends: DX11: Fixed GSGetShader() call not passing an initialized instance count,
|
||||
would generally make the debug layer complain (Added in 1.72).
|
||||
- Backends: Vulkan: Added support for specifying multisample count.
|
||||
Set ImGui_ImplVulkan_InitInfo::MSAASamples to one of the VkSampleCountFlagBits values
|
||||
to use, default is non-multisampled as before. (#2705, #2706) [@vilya]
|
||||
- Misc: Updated stb_rect_pack from 0.99 to 1.00 (fixes by @rygorous: off-by-1 bug in best-fit heuristic,
|
||||
fix handling of rectangles too large to fit inside texture). (#2762) [@tido64]
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
|
51
imgui.cpp
51
imgui.cpp
@ -1283,6 +1283,7 @@ ImGuiIO::ImGuiIO()
|
||||
ConfigInputTextCursorBlink = true;
|
||||
ConfigWindowsResizeFromEdges = true;
|
||||
ConfigWindowsMoveFromTitleBarOnly = false;
|
||||
ConfigWindowsMemoryCompactTimer = 60.0f;
|
||||
|
||||
// Platform Functions
|
||||
BackendPlatformName = BackendRendererName = NULL;
|
||||
@ -2750,6 +2751,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
|
||||
|
||||
LastFrameActive = -1;
|
||||
LastFrameJustFocused = -1;
|
||||
LastTimeActive = -1.0f;
|
||||
ItemWidthDefault = 0.0f;
|
||||
FontWindowScale = FontDpiScale = 1.0f;
|
||||
SettingsIdx = -1;
|
||||
@ -2766,6 +2768,9 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
|
||||
NavRectRel[0] = NavRectRel[1] = ImRect();
|
||||
NavLastChildNavWindow = NULL;
|
||||
|
||||
MemoryCompacted = false;
|
||||
MemoryDrawListIdxCapacity = MemoryDrawListVtxCapacity = 0;
|
||||
|
||||
DockNode = DockNodeAsHost = NULL;
|
||||
DockId = 0;
|
||||
DockTabItemStatusFlags = ImGuiItemStatusFlags_None;
|
||||
@ -2841,6 +2846,36 @@ static void SetCurrentWindow(ImGuiWindow* window)
|
||||
g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize();
|
||||
}
|
||||
|
||||
// Free up/compact internal window buffers, we can use this when a window becomes unused.
|
||||
// This is currently unused by the library, but you may call this yourself for easy GC.
|
||||
// Not freed:
|
||||
// - ImGuiWindow, ImGuiWindowSettings, Name
|
||||
// - StateStorage, ColumnsStorage (may hold useful data)
|
||||
// This should have no noticeable visual effect. When the window reappear however, expect new allocation/buffer growth/copy cost.
|
||||
void ImGui::GcCompactTransientWindowBuffers(ImGuiWindow* window)
|
||||
{
|
||||
window->MemoryCompacted = true;
|
||||
window->MemoryDrawListIdxCapacity = window->DrawList->IdxBuffer.Capacity;
|
||||
window->MemoryDrawListVtxCapacity = window->DrawList->VtxBuffer.Capacity;
|
||||
window->IDStack.clear();
|
||||
window->DrawList->ClearFreeMemory();
|
||||
window->DC.ChildWindows.clear();
|
||||
window->DC.ItemFlagsStack.clear();
|
||||
window->DC.ItemWidthStack.clear();
|
||||
window->DC.TextWrapPosStack.clear();
|
||||
window->DC.GroupStack.clear();
|
||||
}
|
||||
|
||||
void ImGui::GcAwakeTransientWindowBuffers(ImGuiWindow* window)
|
||||
{
|
||||
// We stored capacity of the ImDrawList buffer to reduce growth-caused allocation/copy when awakening.
|
||||
// The other buffers tends to amortize much faster.
|
||||
window->MemoryCompacted = false;
|
||||
window->DrawList->IdxBuffer.reserve(window->MemoryDrawListIdxCapacity);
|
||||
window->DrawList->VtxBuffer.reserve(window->MemoryDrawListVtxCapacity);
|
||||
window->MemoryDrawListIdxCapacity = window->MemoryDrawListVtxCapacity = 0;
|
||||
}
|
||||
|
||||
void ImGui::SetNavID(ImGuiID id, int nav_layer)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -4032,8 +4067,9 @@ void ImGui::NewFrame()
|
||||
|
||||
g.NavIdTabCounter = INT_MAX;
|
||||
|
||||
// Mark all windows as not visible
|
||||
// Mark all windows as not visible and compact unused memory.
|
||||
IM_ASSERT(g.WindowsFocusOrder.Size == g.Windows.Size);
|
||||
const float memory_compact_start_time = (g.IO.ConfigWindowsMemoryCompactTimer >= 0.0f) ? (float)g.Time - g.IO.ConfigWindowsMemoryCompactTimer : FLT_MAX;
|
||||
for (int i = 0; i != g.Windows.Size; i++)
|
||||
{
|
||||
ImGuiWindow* window = g.Windows[i];
|
||||
@ -4041,6 +4077,10 @@ void ImGui::NewFrame()
|
||||
window->BeginCount = 0;
|
||||
window->Active = false;
|
||||
window->WriteAccessed = false;
|
||||
|
||||
// Garbage collect (this is totally functional but we may need decide if the side-effects are desirable)
|
||||
if (!window->WasActive && !window->MemoryCompacted && window->LastTimeActive < memory_compact_start_time)
|
||||
GcCompactTransientWindowBuffers(window);
|
||||
}
|
||||
|
||||
// Closing the focused window restore focus to the first active root window in descending z-order
|
||||
@ -5828,6 +5868,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
window->FlagsPreviousFrame = window->Flags;
|
||||
window->Flags = (ImGuiWindowFlags)flags;
|
||||
window->LastFrameActive = current_frame;
|
||||
window->LastTimeActive = (float)g.Time;
|
||||
window->BeginOrderWithinParent = 0;
|
||||
window->BeginOrderWithinContext = (short)(g.WindowsActiveCount++);
|
||||
}
|
||||
@ -5860,6 +5901,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
ImGuiWindow* parent_window = first_begin_of_the_frame ? ((flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup)) ? parent_window_in_stack : NULL) : window->ParentWindow;
|
||||
IM_ASSERT(parent_window != NULL || !(flags & ImGuiWindowFlags_ChildWindow));
|
||||
|
||||
// We allow window memory to be compacted so recreate the base stack when needed.
|
||||
if (window->IDStack.Size == 0)
|
||||
window->IDStack.push_back(window->ID);
|
||||
|
||||
// Add to stack
|
||||
// We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow()
|
||||
g.CurrentWindowStack.push_back(window);
|
||||
@ -5926,6 +5971,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
window->ClipRect = ImVec4(-FLT_MAX,-FLT_MAX,+FLT_MAX,+FLT_MAX);
|
||||
window->IDStack.resize(1);
|
||||
|
||||
// Restore buffer capacity when woken from a compacted state, to avoid
|
||||
if (window->MemoryCompacted)
|
||||
GcAwakeTransientWindowBuffers(window);
|
||||
|
||||
// Update stored window name when it changes (which can _only_ happen with the "###" operator, so the ID would stay unchanged).
|
||||
// The title bar always display the 'name' parameter, so we only update the string storage if it needs to be visible to the end-user elsewhere.
|
||||
bool window_title_visible_elsewhere = false;
|
||||
|
5
imgui.h
5
imgui.h
@ -438,6 +438,8 @@ namespace ImGui
|
||||
// - For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x
|
||||
// - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc.
|
||||
// - Speed are per-pixel of mouse movement (v_speed=0.2f: mouse needs to move by 5 pixels to increase value by 1). For gamepad/keyboard navigation, minimum speed is Max(v_speed, minimum_step_at_given_precision).
|
||||
// - Use v_min < v_max to clamp edits to given limits. Note that CTRL+Click manual input can override those limits.
|
||||
// - Use v_min > v_max to lock edits.
|
||||
IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound
|
||||
IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f);
|
||||
IMGUI_API bool DragFloat3(const char* label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f);
|
||||
@ -1444,6 +1446,7 @@ struct ImGuiIO
|
||||
bool ConfigInputTextCursorBlink; // = true // Set to false to disable blinking cursor, for users who consider it distracting. (was called: io.OptCursorBlink prior to 1.63)
|
||||
bool ConfigWindowsResizeFromEdges; // = true // Enable resizing of windows from their edges and from the lower-left corner. This requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback. (This used to be a per-window ImGuiWindowFlags_ResizeFromAnySide flag)
|
||||
bool ConfigWindowsMoveFromTitleBarOnly; // = false // [BETA] Set to true to only allow moving windows when clicked+dragged from the title bar. Windows without a title bar are not affected.
|
||||
float ConfigWindowsMemoryCompactTimer;// = 60.0f // [BETA] Compact window memory usage when unused. Set to -1.0f to disable.
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Platform Functions
|
||||
@ -1883,7 +1886,7 @@ struct ImDrawCmd
|
||||
ImDrawCallback UserCallback; // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally.
|
||||
void* UserCallbackData; // The draw callback code can access this.
|
||||
|
||||
ImDrawCmd() { ElemCount = 0; ClipRect.x = ClipRect.y = ClipRect.z = ClipRect.w = 0.0f; TextureId = (ImTextureID)NULL; VtxOffset = IdxOffset = 0; UserCallback = NULL; UserCallbackData = NULL; }
|
||||
ImDrawCmd() { ElemCount = 0; TextureId = (ImTextureID)NULL; VtxOffset = IdxOffset = 0; UserCallback = NULL; UserCallbackData = NULL; }
|
||||
};
|
||||
|
||||
// Vertex index
|
||||
|
@ -1098,6 +1098,8 @@ static void ShowDemoWindowWidgets()
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
// Plot/Graph widgets are currently fairly limited.
|
||||
// Consider writing your own plotting widget, or using a third-party one (see "Wiki->Useful Widgets", or github.com/ocornut/imgui/issues/2747)
|
||||
if (ImGui::TreeNode("Plots Widgets"))
|
||||
{
|
||||
static bool animate = true;
|
||||
@ -1121,7 +1123,18 @@ static void ShowDemoWindowWidgets()
|
||||
phase += 0.10f*values_offset;
|
||||
refresh_time += 1.0f/60.0f;
|
||||
}
|
||||
ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80));
|
||||
|
||||
// Plots can display overlay texts
|
||||
// (in this example, we will display an average value)
|
||||
{
|
||||
float average = 0.0f;
|
||||
for (int n = 0; n < IM_ARRAYSIZE(values); n++)
|
||||
average += values[n];
|
||||
average /= (float)IM_ARRAYSIZE(values);
|
||||
char overlay[32];
|
||||
sprintf(overlay, "avg %f", average);
|
||||
ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, overlay, -1.0f, 1.0f, ImVec2(0,80));
|
||||
}
|
||||
ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80));
|
||||
|
||||
// Use functions to generate output
|
||||
@ -3112,6 +3125,7 @@ void ImGui::ShowAboutWindow(bool* p_open)
|
||||
if (io.ConfigInputTextCursorBlink) ImGui::Text("io.ConfigInputTextCursorBlink");
|
||||
if (io.ConfigWindowsResizeFromEdges) ImGui::Text("io.ConfigWindowsResizeFromEdges");
|
||||
if (io.ConfigWindowsMoveFromTitleBarOnly) ImGui::Text("io.ConfigWindowsMoveFromTitleBarOnly");
|
||||
if (io.ConfigWindowsMemoryCompactTimer >= 0.0f) ImGui::Text("io.ConfigWindowsMemoryCompactTimer = %.1ff", io.ConfigWindowsMemoryCompactTimer);
|
||||
ImGui::Text("io.BackendFlags: 0x%08X", io.BackendFlags);
|
||||
if (io.BackendFlags & ImGuiBackendFlags_HasGamepad) ImGui::Text(" HasGamepad");
|
||||
if (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) ImGui::Text(" HasMouseCursors");
|
||||
@ -4356,7 +4370,6 @@ static void ShowExampleAppWindowTitles(bool*)
|
||||
// Demonstrate using the low-level ImDrawList to draw custom shapes.
|
||||
static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
{
|
||||
ImGui::SetNextWindowSize(ImVec2(350, 560), ImGuiCond_FirstUseEver);
|
||||
if (!ImGui::Begin("Example: Custom rendering", p_open))
|
||||
{
|
||||
ImGui::End();
|
||||
@ -4476,7 +4489,9 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
static bool draw_bg = true;
|
||||
static bool draw_fg = true;
|
||||
ImGui::Checkbox("Draw in Background draw list", &draw_bg);
|
||||
ImGui::SameLine(); HelpMarker("The Background draw list will be rendered below every Dear ImGui windows.");
|
||||
ImGui::Checkbox("Draw in Foreground draw list", &draw_fg);
|
||||
ImGui::SameLine(); HelpMarker("The Foreground draw list will be rendered over every Dear ImGui windows.");
|
||||
ImVec2 window_pos = ImGui::GetWindowPos();
|
||||
ImVec2 window_size = ImGui::GetWindowSize();
|
||||
ImVec2 window_center = ImVec2(window_pos.x + window_size.x * 0.5f, window_pos.y + window_size.y * 0.5f);
|
||||
|
@ -1495,8 +1495,8 @@ struct IMGUI_API ImGuiWindow
|
||||
ImVec2 SetWindowPosVal; // store window position when using a non-zero Pivot (position set needs to be processed when we know the window size)
|
||||
ImVec2 SetWindowPosPivot; // store window pivot for positioning. ImVec2(0,0) when positioning from top-left corner; ImVec2(0.5f,0.5f) for centering; ImVec2(1,1) for bottom right.
|
||||
|
||||
ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack. (In theory this should be in the TempData structure)
|
||||
ImGuiWindowTempData DC; // Temporary per-window data, reset at the beginning of the frame. This used to be called ImGuiDrawContext, hence the "DC" variable name.
|
||||
ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack
|
||||
|
||||
// The best way to understand what those rectangles are is to use the 'Metrics -> Tools -> Show windows rectangles' viewer.
|
||||
// The main 'OuterRect', omitted as a field, is window->Rect().
|
||||
@ -1510,6 +1510,7 @@ struct IMGUI_API ImGuiWindow
|
||||
|
||||
int LastFrameActive; // Last frame number the window was Active.
|
||||
int LastFrameJustFocused; // Last frame number the window was made Focused.
|
||||
float LastTimeActive;
|
||||
float ItemWidthDefault;
|
||||
ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items
|
||||
ImGuiStorage StateStorage;
|
||||
@ -1530,6 +1531,10 @@ struct IMGUI_API ImGuiWindow
|
||||
ImGuiID NavLastIds[ImGuiNavLayer_COUNT]; // Last known NavId for this window, per layer (0/1)
|
||||
ImRect NavRectRel[ImGuiNavLayer_COUNT]; // Reference rectangle, in window relative space
|
||||
|
||||
bool MemoryCompacted;
|
||||
int MemoryDrawListIdxCapacity;
|
||||
int MemoryDrawListVtxCapacity;
|
||||
|
||||
// Docking
|
||||
ImGuiDockNode* DockNode; // Which node are we docked into
|
||||
ImGuiDockNode* DockNodeAsHost; // Which node are we owning (for parent windows)
|
||||
@ -1622,8 +1627,9 @@ struct ImGuiTabBar
|
||||
int CurrFrameVisible;
|
||||
int PrevFrameVisible;
|
||||
ImRect BarRect;
|
||||
float ContentsHeight;
|
||||
float LastTabContentHeight; // Record the height of contents submitted below the tab bar
|
||||
float OffsetMax; // Distance from BarRect.Min.x, locked during layout
|
||||
float OffsetMaxIdeal; // Ideal offset if all tabs were visible and not clipped
|
||||
float OffsetNextTab; // Distance from BarRect.Min.x, incremented with each BeginTabItem() call, not used if ImGuiTabBarFlags_Reorderable if set.
|
||||
float ScrollingAnim;
|
||||
float ScrollingTarget;
|
||||
@ -1677,6 +1683,8 @@ namespace ImGui
|
||||
IMGUI_API void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond = 0);
|
||||
IMGUI_API void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond = 0);
|
||||
IMGUI_API void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond = 0);
|
||||
IMGUI_API void GcCompactTransientWindowBuffers(ImGuiWindow* window);
|
||||
IMGUI_API void GcAwakeTransientWindowBuffers(ImGuiWindow* window);
|
||||
|
||||
IMGUI_API void SetCurrentFont(ImFont* font);
|
||||
inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; }
|
||||
|
@ -1377,14 +1377,28 @@ void ImGui::ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_exc
|
||||
int count_same_width = 1;
|
||||
while (width_excess > 0.0f && count_same_width < count)
|
||||
{
|
||||
while (count_same_width < count && items[0].Width == items[count_same_width].Width)
|
||||
while (count_same_width < count && items[0].Width <= items[count_same_width].Width)
|
||||
count_same_width++;
|
||||
float width_to_remove_per_item_max = (count_same_width < count) ? (items[0].Width - items[count_same_width].Width) : (items[0].Width - 1.0f);
|
||||
float width_to_remove_per_item = ImMin(width_excess / count_same_width, width_to_remove_per_item_max);
|
||||
float max_width_to_remove_per_item = (count_same_width < count) ? (items[0].Width - items[count_same_width].Width) : (items[0].Width - 1.0f);
|
||||
float width_to_remove_per_item = ImMin(width_excess / count_same_width, max_width_to_remove_per_item);
|
||||
for (int item_n = 0; item_n < count_same_width; item_n++)
|
||||
items[item_n].Width -= width_to_remove_per_item;
|
||||
width_excess -= width_to_remove_per_item * count_same_width;
|
||||
}
|
||||
|
||||
// Round width and redistribute remainder left-to-right (could make it an option of the function?)
|
||||
// Ensure that e.g. the right-most tab of a shrunk tab-bar always reaches exactly at the same distance from the right-most edge of the tab bar separator.
|
||||
width_excess = 0.0f;
|
||||
for (int n = 0; n < count; n++)
|
||||
{
|
||||
float width_rounded = ImFloor(items[n].Width);
|
||||
width_excess += items[n].Width - width_rounded;
|
||||
items[n].Width = width_rounded;
|
||||
}
|
||||
if (width_excess > 0.0f)
|
||||
for (int n = 0; n < count; n++)
|
||||
if (items[n].Index < (int)(width_excess + 0.01f))
|
||||
items[n].Width += 1.0f;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -1909,11 +1923,14 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiAxis axis = (flags & ImGuiDragFlags_Vertical) ? ImGuiAxis_Y : ImGuiAxis_X;
|
||||
const bool is_decimal = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double);
|
||||
const bool has_min_max = (v_min != v_max);
|
||||
const bool is_power = (power != 1.0f && is_decimal && has_min_max && (v_max - v_min < FLT_MAX));
|
||||
const bool is_clamped = (v_min < v_max);
|
||||
const bool is_power = (power != 1.0f && is_decimal && is_clamped && (v_max - v_min < FLT_MAX));
|
||||
const bool is_locked = (v_min > v_max);
|
||||
if (is_locked)
|
||||
return false;
|
||||
|
||||
// Default tweak speed
|
||||
if (v_speed == 0.0f && has_min_max && (v_max - v_min < FLT_MAX))
|
||||
if (v_speed == 0.0f && is_clamped && (v_max - v_min < FLT_MAX))
|
||||
v_speed = (float)((v_max - v_min) * g.DragSpeedDefaultRatio);
|
||||
|
||||
// Inputs accumulates into g.DragCurrentAccum, which is flushed into the current value as soon as it makes a difference with our precision settings
|
||||
@ -1941,7 +1958,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
||||
// Clear current value on activation
|
||||
// Avoid altering values and clamping when we are _already_ past the limits and heading in the same direction, so e.g. if range is 0..255, current value is 300 and we are pushing to the right side, keep the 300.
|
||||
bool is_just_activated = g.ActiveIdIsJustActivated;
|
||||
bool is_already_past_limits_and_pushing_outward = has_min_max && ((*v >= v_max && adjust_delta > 0.0f) || (*v <= v_min && adjust_delta < 0.0f));
|
||||
bool is_already_past_limits_and_pushing_outward = is_clamped && ((*v >= v_max && adjust_delta > 0.0f) || (*v <= v_min && adjust_delta < 0.0f));
|
||||
bool is_drag_direction_change_with_power = is_power && ((adjust_delta < 0 && g.DragCurrentAccum > 0) || (adjust_delta > 0 && g.DragCurrentAccum < 0));
|
||||
if (is_just_activated || is_already_past_limits_and_pushing_outward || is_drag_direction_change_with_power)
|
||||
{
|
||||
@ -1993,7 +2010,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
||||
v_cur = (TYPE)0;
|
||||
|
||||
// Clamp values (+ handle overflow/wrap-around for integer types)
|
||||
if (*v != v_cur && has_min_max)
|
||||
if (*v != v_cur && is_clamped)
|
||||
{
|
||||
if (v_cur < v_min || (v_cur > *v && adjust_delta < 0.0f && !is_decimal))
|
||||
v_cur = v_min;
|
||||
@ -2471,13 +2488,13 @@ bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type
|
||||
IM_ASSERT(*(const ImS32*)v_min >= IM_S32_MIN/2 && *(const ImS32*)v_max <= IM_S32_MAX/2);
|
||||
return SliderBehaviorT<ImS32, ImS32, float >(bb, id, data_type, (ImS32*)v, *(const ImS32*)v_min, *(const ImS32*)v_max, format, power, flags, out_grab_bb);
|
||||
case ImGuiDataType_U32:
|
||||
IM_ASSERT(*(const ImU32*)v_min <= IM_U32_MAX/2);
|
||||
IM_ASSERT(*(const ImU32*)v_max <= IM_U32_MAX/2);
|
||||
return SliderBehaviorT<ImU32, ImS32, float >(bb, id, data_type, (ImU32*)v, *(const ImU32*)v_min, *(const ImU32*)v_max, format, power, flags, out_grab_bb);
|
||||
case ImGuiDataType_S64:
|
||||
IM_ASSERT(*(const ImS64*)v_min >= IM_S64_MIN/2 && *(const ImS64*)v_max <= IM_S64_MAX/2);
|
||||
return SliderBehaviorT<ImS64, ImS64, double>(bb, id, data_type, (ImS64*)v, *(const ImS64*)v_min, *(const ImS64*)v_max, format, power, flags, out_grab_bb);
|
||||
case ImGuiDataType_U64:
|
||||
IM_ASSERT(*(const ImU64*)v_min <= IM_U64_MAX/2);
|
||||
IM_ASSERT(*(const ImU64*)v_max <= IM_U64_MAX/2);
|
||||
return SliderBehaviorT<ImU64, ImS64, double>(bb, id, data_type, (ImU64*)v, *(const ImU64*)v_min, *(const ImU64*)v_max, format, power, flags, out_grab_bb);
|
||||
case ImGuiDataType_Float:
|
||||
IM_ASSERT(*(const float*)v_min >= -FLT_MAX/2.0f && *(const float*)v_max <= FLT_MAX/2.0f);
|
||||
@ -3391,7 +3408,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
BeginGroup();
|
||||
const ImGuiID id = window->GetID(label);
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? GetTextLineHeight() * 8.0f : label_size.y) + style.FramePadding.y*2.0f); // Arbitrary default of 8 lines high for multi-line
|
||||
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? g.FontSize * 8.0f : label_size.y) + style.FramePadding.y*2.0f); // Arbitrary default of 8 lines high for multi-line
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
|
||||
const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
|
||||
|
||||
@ -4227,14 +4244,17 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
||||
if (n > 0)
|
||||
SameLine(0, style.ItemInnerSpacing.x);
|
||||
SetNextItemWidth((n + 1 < components) ? w_item_one : w_item_last);
|
||||
|
||||
// Disable Hue edit when Saturation is zero
|
||||
const bool disable_hue_edit = (n == 0 && (flags & ImGuiColorEditFlags_DisplayHSV) && i[1] == 0);
|
||||
if (flags & ImGuiColorEditFlags_Float)
|
||||
{
|
||||
value_changed |= DragFloat(ids[n], &f[n], 1.0f/255.0f, 0.0f, hdr ? 0.0f : 1.0f, fmt_table_float[fmt_idx][n]);
|
||||
value_changed |= DragFloat(ids[n], &f[n], 1.0f/255.0f, disable_hue_edit ? +FLT_MAX : 0.0f, disable_hue_edit ? -FLT_MAX : hdr ? 0.0f : 1.0f, fmt_table_float[fmt_idx][n]);
|
||||
value_changed_as_float |= value_changed;
|
||||
}
|
||||
else
|
||||
{
|
||||
value_changed |= DragInt(ids[n], &i[n], 1.0f, 0, hdr ? 0 : 255, fmt_table_int[fmt_idx][n]);
|
||||
value_changed |= DragInt(ids[n], &i[n], 1.0f, disable_hue_edit ? INT_MAX : 0, disable_hue_edit ? INT_MIN : hdr ? 0 : 255, fmt_table_int[fmt_idx][n]);
|
||||
}
|
||||
if (!(flags & ImGuiColorEditFlags_NoOptions))
|
||||
OpenPopupOnItemClick("context");
|
||||
@ -6288,8 +6308,8 @@ ImGuiTabBar::ImGuiTabBar()
|
||||
ID = 0;
|
||||
SelectedTabId = NextSelectedTabId = VisibleTabId = 0;
|
||||
CurrFrameVisible = PrevFrameVisible = -1;
|
||||
ContentsHeight = 0.0f;
|
||||
OffsetMax = OffsetNextTab = 0.0f;
|
||||
LastTabContentHeight = 0.0f;
|
||||
OffsetMax = OffsetMaxIdeal = OffsetNextTab = 0.0f;
|
||||
ScrollingAnim = ScrollingTarget = ScrollingTargetDistToVisibility = ScrollingSpeed = 0.0f;
|
||||
Flags = ImGuiTabBarFlags_None;
|
||||
ReorderRequestTabId = 0;
|
||||
@ -6371,7 +6391,7 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG
|
||||
tab_bar->FramePadding = g.Style.FramePadding;
|
||||
|
||||
// Layout
|
||||
ItemSize(ImVec2(0.0f /*tab_bar->OffsetMax*/, tab_bar->BarRect.GetHeight())); // Don't feed width back
|
||||
ItemSize(ImVec2(tab_bar->OffsetMaxIdeal, tab_bar->BarRect.GetHeight()));
|
||||
window->DC.CursorPos.x = tab_bar->BarRect.Min.x;
|
||||
|
||||
// Draw separator
|
||||
@ -6411,9 +6431,9 @@ void ImGui::EndTabBar()
|
||||
// Restore the last visible height if no tab is visible, this reduce vertical flicker/movement when a tabs gets removed without calling SetTabItemClosed().
|
||||
const bool tab_bar_appearing = (tab_bar->PrevFrameVisible + 1 < g.FrameCount);
|
||||
if (tab_bar->VisibleTabWasSubmitted || tab_bar->VisibleTabId == 0 || tab_bar_appearing)
|
||||
tab_bar->ContentsHeight = ImMax(window->DC.CursorPos.y - tab_bar->BarRect.Max.y, 0.0f);
|
||||
tab_bar->LastTabContentHeight = ImMax(window->DC.CursorPos.y - tab_bar->BarRect.Max.y, 0.0f);
|
||||
else
|
||||
window->DC.CursorPos.y = tab_bar->BarRect.Max.y + tab_bar->ContentsHeight;
|
||||
window->DC.CursorPos.y = tab_bar->BarRect.Max.y + tab_bar->LastTabContentHeight;
|
||||
|
||||
if ((tab_bar->Flags & ImGuiTabBarFlags_DockNode) == 0)
|
||||
PopID();
|
||||
@ -6537,6 +6557,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
|
||||
|
||||
// Layout all active tabs
|
||||
float offset_x = initial_offset_x;
|
||||
float offset_x_ideal = offset_x;
|
||||
tab_bar->OffsetNextTab = offset_x; // This is used by non-reorderable tab bar where the submission order is always honored.
|
||||
for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
|
||||
{
|
||||
@ -6545,8 +6566,10 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
|
||||
if (scroll_track_selected_tab_id == 0 && g.NavJustMovedToId == tab->ID)
|
||||
scroll_track_selected_tab_id = tab->ID;
|
||||
offset_x += tab->Width + g.Style.ItemInnerSpacing.x;
|
||||
offset_x_ideal += tab->WidthContents + g.Style.ItemInnerSpacing.x;
|
||||
}
|
||||
tab_bar->OffsetMax = ImMax(offset_x - g.Style.ItemInnerSpacing.x, 0.0f);
|
||||
tab_bar->OffsetMaxIdeal = ImMax(offset_x_ideal - g.Style.ItemInnerSpacing.x, 0.0f);
|
||||
|
||||
// Horizontal scrolling buttons
|
||||
const bool scrolling_buttons = (tab_bar->OffsetMax > tab_bar->BarRect.GetWidth() && tab_bar->Tabs.Size > 1) && !(tab_bar->Flags & ImGuiTabBarFlags_NoTabListScrollingButtons) && (tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyScroll);
|
||||
|
@ -1,10 +1,10 @@
|
||||
// [DEAR IMGUI]
|
||||
// This is a slightly modified version of stb_rect_pack.h 0.99.
|
||||
// [DEAR IMGUI]
|
||||
// This is a slightly modified version of stb_rect_pack.h 1.00.
|
||||
// Those changes would need to be pushed into nothings/stb:
|
||||
// - Added STBRP__CDECL
|
||||
// Grep for [DEAR IMGUI] to find the changes.
|
||||
|
||||
// stb_rect_pack.h - v0.99 - public domain - rectangle packing
|
||||
// stb_rect_pack.h - v1.00 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
@ -37,9 +37,11 @@
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
// Fabian Giesen
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
@ -357,6 +359,13 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
// if it can't possibly fit, bail immediately
|
||||
if (width > c->width || height > c->height) {
|
||||
fr.prev_link = NULL;
|
||||
fr.x = fr.y = 0;
|
||||
return fr;
|
||||
}
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while (node->x + width <= c->width) {
|
||||
@ -420,7 +429,7 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if (y + height < c->height) {
|
||||
if (y + height <= c->height) {
|
||||
if (y <= best_y) {
|
||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
|
Loading…
Reference in New Issue
Block a user