mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Merge branch 'master' into navigation
# Conflicts: # imgui_internal.h
This commit is contained in:
275
imgui.cpp
275
imgui.cpp
@ -240,8 +240,10 @@
|
||||
Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
|
||||
Also read releases logs https://github.com/ocornut/imgui/releases for more details.
|
||||
|
||||
- 2016/08/20 (1.51) - renamed GetStyleColName() to GetStyleColorName() for consistency.
|
||||
- 2016/08/20 (1.51) - added PushStyleColor(ImGuiCol idx, ImU32 col) overload, which _might_ cause an "ambiguous call" compilation error if you are using ImColor() with implicit cast. Cast to ImU32 or ImVec4 explicily to fix.
|
||||
- 2017/08/15 (1.51) - marked the weird IMGUI_ONCE_UPON_A_FRAME helper macro as obsolete. prefer using the more explicit ImGuiOnceUponAFrame.
|
||||
- 2017/08/15 (1.51) - changed parameter order for BeginPopupContextWindow(), note that most uses relied on default parameters completely.
|
||||
- 2017/08/15 (1.51) - changed parameter order for BeginPopupContextWindow() from (const char*,int buttons,bool also_over_items) to (const char*,int buttons,bool also_over_items). Note that most calls relied on default parameters completely.
|
||||
- 2017/08/13 (1.51) - renamed ImGuiCol_Columns_*** to ImGuiCol_Separator_***
|
||||
- 2017/08/11 (1.51) - renamed ImGuiSetCond_*** types and flags to ImGuiCond_***. Kept redirection enums (will obsolete).
|
||||
- 2017/08/09 (1.51) - removed ValueColor() helpers, they are equivalent to calling Text(label) + SameLine() + ColorButton().
|
||||
@ -614,6 +616,8 @@
|
||||
#pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function
|
||||
#pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual" // warning: cast from type 'xxxx' to type 'xxxx' casts away qualifiers
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked
|
||||
#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -653,7 +657,6 @@ static void LoadIniSettingsFromDisk(const char* ini_filename);
|
||||
static void SaveIniSettingsToDisk(const char* ini_filename);
|
||||
static void MarkIniSettingsDirty(ImGuiWindow* window);
|
||||
|
||||
static void PushColumnClipRect(int column_index = -1);
|
||||
static ImRect GetVisibleRect();
|
||||
|
||||
static bool BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags);
|
||||
@ -1258,6 +1261,12 @@ ImU32 ImGui::GetColorU32(const ImVec4& col)
|
||||
return ColorConvertFloat4ToU32(c);
|
||||
}
|
||||
|
||||
const ImVec4& ImGui::GetStyleColorVec4(ImGuiCol idx)
|
||||
{
|
||||
ImGuiStyle& style = GImGui->Style;
|
||||
return style.Colors[idx];
|
||||
}
|
||||
|
||||
ImU32 ImGui::GetColorU32(ImU32 col)
|
||||
{
|
||||
float style_alpha = GImGui->Style.Alpha;
|
||||
@ -4271,7 +4280,7 @@ static bool BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags)
|
||||
bool ImGui::BeginPopup(const char* str_id)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.OpenPopupStack.Size <= g.CurrentPopupStack.Size) // Early out for performance
|
||||
if (g.OpenPopupStack.Size <= g.CurrentPopupStack.Size) // Early out for performance
|
||||
{
|
||||
ClearSetNextWindowData(); // We behave like Begin() and need to consume those values
|
||||
return false;
|
||||
@ -5127,6 +5136,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
window->DC.ColumnsCurrent = 0;
|
||||
window->DC.ColumnsCount = 1;
|
||||
window->DC.ColumnsStartPosY = window->DC.CursorPos.y;
|
||||
window->DC.ColumnsStartMaxPosX = window->DC.CursorMaxPos.x;
|
||||
window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPosY;
|
||||
window->DC.TreeDepth = 0;
|
||||
window->DC.StateStorage = &window->StateStorage;
|
||||
@ -5267,7 +5277,7 @@ void ImGui::End()
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
|
||||
if (window->DC.ColumnsCount != 1) // close columns set if any is open
|
||||
Columns(1, "#CLOSECOLUMNS");
|
||||
EndColumns();
|
||||
PopClipRect(); // inner window clip rectangle
|
||||
|
||||
// Stop logging
|
||||
@ -5316,15 +5326,17 @@ static void Scrollbar(ImGuiWindow* window, bool horizontal)
|
||||
window->DrawList->AddRectFilled(bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_ScrollbarBg), window_rounding, window_rounding_corners);
|
||||
bb.Expand(ImVec2(-ImClamp((float)(int)((bb.Max.x - bb.Min.x - 2.0f) * 0.5f), 0.0f, 3.0f), -ImClamp((float)(int)((bb.Max.y - bb.Min.y - 2.0f) * 0.5f), 0.0f, 3.0f)));
|
||||
|
||||
// V denote the main axis of the scrollbar
|
||||
// V denote the main, longer axis of the scrollbar (= height for a vertical scrollbar)
|
||||
float scrollbar_size_v = horizontal ? bb.GetWidth() : bb.GetHeight();
|
||||
float scroll_v = horizontal ? window->Scroll.x : window->Scroll.y;
|
||||
float win_size_avail_v = (horizontal ? window->SizeFull.x : window->SizeFull.y) - other_scrollbar_size_w;
|
||||
float win_size_contents_v = horizontal ? window->SizeContents.x : window->SizeContents.y;
|
||||
|
||||
// The grabbable box size generally represent the amount visible (vs the total scrollable amount)
|
||||
// Calculate the height of our grabbable box. It generally represent the amount visible (vs the total scrollable amount)
|
||||
// But we maintain a minimum size in pixel to allow for the user to still aim inside.
|
||||
const float grab_h_pixels = ImMin(ImMax(scrollbar_size_v * ImSaturate(win_size_avail_v / ImMax(win_size_contents_v, win_size_avail_v)), style.GrabMinSize), scrollbar_size_v);
|
||||
IM_ASSERT(ImMax(win_size_contents_v, win_size_avail_v) > 0.0f); // Adding this assert to check if the ImMax(XXX,1.0f) is still needed. PLEASE CONTACT ME if this triggers.
|
||||
const float win_size_v = ImMax(ImMax(win_size_contents_v, win_size_avail_v), 1.0f);
|
||||
const float grab_h_pixels = ImClamp(scrollbar_size_v * (win_size_avail_v / win_size_v), style.GrabMinSize, scrollbar_size_v);
|
||||
const float grab_h_norm = grab_h_pixels / scrollbar_size_v;
|
||||
|
||||
// Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar().
|
||||
@ -5556,6 +5568,17 @@ void ImGui::PopTextWrapPos()
|
||||
window->DC.TextWrapPos = window->DC.TextWrapPosStack.empty() ? -1.0f : window->DC.TextWrapPosStack.back();
|
||||
}
|
||||
|
||||
// FIXME: This may incur a round-trip (if the end user got their data from a float4) but eventually we aim to store the in-flight colors as ImU32
|
||||
void ImGui::PushStyleColor(ImGuiCol idx, ImU32 col)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiColMod backup;
|
||||
backup.Col = idx;
|
||||
backup.BackupValue = g.Style.Colors[idx];
|
||||
g.ColorModifiers.push_back(backup);
|
||||
g.Style.Colors[idx] = ColorConvertU32ToFloat4(col);
|
||||
}
|
||||
|
||||
void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -5648,7 +5671,7 @@ void ImGui::PopStyleVar(int count)
|
||||
}
|
||||
}
|
||||
|
||||
const char* ImGui::GetStyleColName(ImGuiCol idx)
|
||||
const char* ImGui::GetStyleColorName(ImGuiCol idx)
|
||||
{
|
||||
// Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
|
||||
switch (idx)
|
||||
@ -9539,7 +9562,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiStyle& style = g.Style;
|
||||
|
||||
if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsCount > 1)
|
||||
if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsCount > 1) // FIXME-OPT: Avoid if vertically clipped.
|
||||
PopClipRect();
|
||||
|
||||
ImGuiID id = window->GetID(label);
|
||||
@ -10775,7 +10798,7 @@ void ImGui::EndGroup()
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
|
||||
IM_ASSERT(!window->DC.GroupStack.empty()); // Mismatched BeginGroup()/EndGroup() calls
|
||||
IM_ASSERT(!window->DC.GroupStack.empty()); // Mismatched BeginGroup()/EndGroup() calls
|
||||
|
||||
ImGuiGroupData& group_data = window->DC.GroupStack.back();
|
||||
|
||||
@ -10895,6 +10918,16 @@ int ImGui::GetColumnsCount()
|
||||
return window->DC.ColumnsCount;
|
||||
}
|
||||
|
||||
static float OffsetNormToPixels(ImGuiWindow* window, float offset_norm)
|
||||
{
|
||||
return offset_norm * (window->DC.ColumnsMaxX - window->DC.ColumnsMinX);
|
||||
}
|
||||
|
||||
static float PixelsToOffsetNorm(ImGuiWindow* window, float offset)
|
||||
{
|
||||
return (offset - window->DC.ColumnsMinX) / (window->DC.ColumnsMaxX - window->DC.ColumnsMinX);
|
||||
}
|
||||
|
||||
static float GetDraggedColumnOffset(int column_index)
|
||||
{
|
||||
// Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing
|
||||
@ -10905,43 +10938,57 @@ static float GetDraggedColumnOffset(int column_index)
|
||||
IM_ASSERT(g.ActiveId == window->DC.ColumnsSetId + ImGuiID(column_index));
|
||||
|
||||
float x = g.IO.MousePos.x - g.ActiveIdClickOffset.x - window->Pos.x;
|
||||
x = ImClamp(x, ImGui::GetColumnOffset(column_index-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(column_index+1)-g.Style.ColumnsMinSpacing);
|
||||
x = ImMax(x, ImGui::GetColumnOffset(column_index-1) + g.Style.ColumnsMinSpacing);
|
||||
if ((window->DC.ColumnsFlags & ImGuiColumnsFlags_NoPreserveWidths))
|
||||
x = ImMin(x, ImGui::GetColumnOffset(column_index+1) - g.Style.ColumnsMinSpacing);
|
||||
|
||||
return (float)(int)x;
|
||||
return x;
|
||||
}
|
||||
|
||||
float ImGui::GetColumnOffset(int column_index)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
if (column_index < 0)
|
||||
column_index = window->DC.ColumnsCurrent;
|
||||
|
||||
/*
|
||||
if (g.ActiveId)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(column_index);
|
||||
if (g.ActiveId == column_id)
|
||||
return GetDraggedColumnOffset(column_index);
|
||||
}
|
||||
*/
|
||||
|
||||
IM_ASSERT(column_index < window->DC.ColumnsData.Size);
|
||||
const float t = window->DC.ColumnsData[column_index].OffsetNorm;
|
||||
const float x_offset = ImLerp(window->DC.ColumnsMinX, window->DC.ColumnsMaxX, t);
|
||||
return (float)(int)x_offset;
|
||||
return x_offset;
|
||||
}
|
||||
|
||||
void ImGui::SetColumnOffset(int column_index, float offset)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (column_index < 0)
|
||||
column_index = window->DC.ColumnsCurrent;
|
||||
|
||||
IM_ASSERT(column_index < window->DC.ColumnsData.Size);
|
||||
const float t = (offset - window->DC.ColumnsMinX) / (window->DC.ColumnsMaxX - window->DC.ColumnsMinX);
|
||||
window->DC.ColumnsData[column_index].OffsetNorm = t;
|
||||
|
||||
const bool preserve_width = !(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoPreserveWidths) && (column_index < window->DC.ColumnsCount-1);
|
||||
const float width = preserve_width ? GetColumnWidth(column_index) : 0.0f;
|
||||
|
||||
if (!(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoForceWithinWindow))
|
||||
offset = ImMin(offset, window->DC.ColumnsMaxX - g.Style.ColumnsMinSpacing * (window->DC.ColumnsCount - column_index));
|
||||
const float offset_norm = PixelsToOffsetNorm(window, offset);
|
||||
|
||||
const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(column_index);
|
||||
window->DC.StateStorage->SetFloat(column_id, t);
|
||||
window->DC.StateStorage->SetFloat(column_id, offset_norm);
|
||||
window->DC.ColumnsData[column_index].OffsetNorm = offset_norm;
|
||||
|
||||
if (preserve_width)
|
||||
SetColumnOffset(column_index + 1, offset + ImMax(g.Style.ColumnsMinSpacing, width));
|
||||
}
|
||||
|
||||
float ImGui::GetColumnWidth(int column_index)
|
||||
@ -10950,72 +10997,34 @@ float ImGui::GetColumnWidth(int column_index)
|
||||
if (column_index < 0)
|
||||
column_index = window->DC.ColumnsCurrent;
|
||||
|
||||
float w = GetColumnOffset(column_index+1) - GetColumnOffset(column_index);
|
||||
return w;
|
||||
return OffsetNormToPixels(window, window->DC.ColumnsData[column_index+1].OffsetNorm - window->DC.ColumnsData[column_index].OffsetNorm);
|
||||
}
|
||||
|
||||
static void PushColumnClipRect(int column_index)
|
||||
void ImGui::SetColumnWidth(int column_index, float width)
|
||||
{
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
if (column_index < 0)
|
||||
column_index = window->DC.ColumnsCurrent;
|
||||
|
||||
float x1 = ImFloor(0.5f + window->Pos.x + ImGui::GetColumnOffset(column_index) - 1.0f);
|
||||
float x2 = ImFloor(0.5f + window->Pos.x + ImGui::GetColumnOffset(column_index+1) - 1.0f);
|
||||
ImGui::PushClipRect(ImVec2(x1,-FLT_MAX), ImVec2(x2,+FLT_MAX), true);
|
||||
SetColumnOffset(column_index+1, GetColumnOffset(column_index) + width);
|
||||
}
|
||||
|
||||
void ImGui::Columns(int columns_count, const char* id, bool border)
|
||||
void ImGui::PushColumnClipRect(int column_index)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
if (column_index < 0)
|
||||
column_index = window->DC.ColumnsCurrent;
|
||||
|
||||
PushClipRect(window->DC.ColumnsData[column_index].ClipRect.Min, window->DC.ColumnsData[column_index].ClipRect.Max, false);
|
||||
}
|
||||
|
||||
void ImGui::BeginColumns(const char* id, int columns_count, ImGuiColumnsFlags flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
IM_ASSERT(columns_count >= 1);
|
||||
|
||||
if (window->DC.ColumnsCount != 1)
|
||||
{
|
||||
if (window->DC.ColumnsCurrent != 0)
|
||||
ItemSize(ImVec2(0,0)); // Advance to column 0
|
||||
PopItemWidth();
|
||||
PopClipRect();
|
||||
window->DrawList->ChannelsMerge();
|
||||
|
||||
window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
|
||||
window->DC.CursorPos.y = window->DC.ColumnsCellMaxY;
|
||||
}
|
||||
|
||||
// Draw columns borders and handle resize at the time of "closing" a columns set
|
||||
if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders && !window->SkipItems)
|
||||
{
|
||||
const float y1 = window->DC.ColumnsStartPosY;
|
||||
const float y2 = window->DC.CursorPos.y;
|
||||
for (int i = 1; i < window->DC.ColumnsCount; i++)
|
||||
{
|
||||
float x = window->Pos.x + GetColumnOffset(i);
|
||||
const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(i);
|
||||
const float column_w = 4.0f;
|
||||
const ImRect column_rect(ImVec2(x - column_w, y1), ImVec2(x + column_w, y2));
|
||||
if (IsClippedEx(column_rect, &column_id, false))
|
||||
continue;
|
||||
|
||||
bool hovered, held;
|
||||
ButtonBehavior(column_rect, column_id, &hovered, &held);
|
||||
if (hovered || held)
|
||||
g.MouseCursor = ImGuiMouseCursor_ResizeEW;
|
||||
|
||||
// Draw before resize so our items positioning are in sync with the line being drawn
|
||||
const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator);
|
||||
const float xi = (float)(int)x;
|
||||
window->DrawList->AddLine(ImVec2(xi, y1+1.0f), ImVec2(xi, y2), col);
|
||||
|
||||
if (held)
|
||||
{
|
||||
if (g.ActiveIdIsJustActivated)
|
||||
g.ActiveIdClickOffset.x -= column_w; // Store from center of column line (we used a 8 wide rect for columns clicking)
|
||||
x = GetDraggedColumnOffset(i);
|
||||
SetColumnOffset(i, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
IM_ASSERT(columns_count > 1);
|
||||
IM_ASSERT(window->DC.ColumnsCount == 1); // Nested columns are currently not supported
|
||||
|
||||
// Differentiate column ID with an arbitrary prefix for cases where users name their columns set the same as another widget.
|
||||
// In addition, when an identifier isn't explicitly provided we include the number of columns in the hash to make it uniquer.
|
||||
@ -11026,36 +11035,122 @@ void ImGui::Columns(int columns_count, const char* id, bool border)
|
||||
// Set state for first column
|
||||
window->DC.ColumnsCurrent = 0;
|
||||
window->DC.ColumnsCount = columns_count;
|
||||
window->DC.ColumnsShowBorders = border;
|
||||
window->DC.ColumnsFlags = flags;
|
||||
|
||||
const float content_region_width = (window->SizeContentsExplicit.x != 0.0f) ? window->SizeContentsExplicit.x : window->Size.x;
|
||||
const float content_region_width = (window->SizeContentsExplicit.x != 0.0f) ? (window->SizeContentsExplicit.x) : (window->Size.x -window->ScrollbarSizes.x);
|
||||
window->DC.ColumnsMinX = window->DC.IndentX - g.Style.ItemSpacing.x; // Lock our horizontal range
|
||||
window->DC.ColumnsMaxX = content_region_width - window->Scroll.x - ((window->Flags & ImGuiWindowFlags_NoScrollbar) ? 0 : g.Style.ScrollbarSize);// - window->WindowPadding().x;
|
||||
//window->DC.ColumnsMaxX = content_region_width - window->Scroll.x -((window->Flags & ImGuiWindowFlags_NoScrollbar) ? 0 : g.Style.ScrollbarSize);// - window->WindowPadding().x;
|
||||
window->DC.ColumnsMaxX = content_region_width - window->Scroll.x;
|
||||
window->DC.ColumnsStartPosY = window->DC.CursorPos.y;
|
||||
window->DC.ColumnsStartMaxPosX = window->DC.CursorMaxPos.x;
|
||||
window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.CursorPos.y;
|
||||
window->DC.ColumnsOffsetX = 0.0f;
|
||||
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX);
|
||||
|
||||
if (window->DC.ColumnsCount != 1)
|
||||
// Cache column offsets
|
||||
window->DC.ColumnsData.resize(columns_count + 1);
|
||||
for (int column_index = 0; column_index < columns_count + 1; column_index++)
|
||||
{
|
||||
// Cache column offsets
|
||||
window->DC.ColumnsData.resize(columns_count + 1);
|
||||
for (int column_index = 0; column_index < columns_count + 1; column_index++)
|
||||
const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(column_index);
|
||||
KeepAliveID(column_id);
|
||||
const float default_t = column_index / (float)window->DC.ColumnsCount;
|
||||
float t = window->DC.StateStorage->GetFloat(column_id, default_t);
|
||||
if (!(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoForceWithinWindow))
|
||||
t = ImMin(t, PixelsToOffsetNorm(window, window->DC.ColumnsMaxX - g.Style.ColumnsMinSpacing * (window->DC.ColumnsCount - column_index)));
|
||||
window->DC.ColumnsData[column_index].OffsetNorm = t;
|
||||
}
|
||||
|
||||
// Cache clipping rectangles
|
||||
for (int column_index = 0; column_index < columns_count; column_index++)
|
||||
{
|
||||
float clip_x1 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(column_index) - 1.0f);
|
||||
float clip_x2 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(column_index + 1) - 1.0f);
|
||||
window->DC.ColumnsData[column_index].ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX);
|
||||
window->DC.ColumnsData[column_index].ClipRect.Clip(window->ClipRect);
|
||||
}
|
||||
|
||||
window->DrawList->ChannelsSplit(window->DC.ColumnsCount);
|
||||
PushColumnClipRect();
|
||||
PushItemWidth(GetColumnWidth() * 0.65f);
|
||||
}
|
||||
|
||||
void ImGui::EndColumns()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
IM_ASSERT(window->DC.ColumnsCount > 1);
|
||||
|
||||
PopItemWidth();
|
||||
PopClipRect();
|
||||
window->DrawList->ChannelsMerge();
|
||||
|
||||
window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
|
||||
window->DC.CursorPos.y = window->DC.ColumnsCellMaxY;
|
||||
window->DC.CursorMaxPos.x = ImMax(window->DC.ColumnsStartMaxPosX, window->DC.ColumnsMaxX); // Columns don't grow parent
|
||||
|
||||
// Draw columns borders and handle resize
|
||||
if (!(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoBorder) && !window->SkipItems)
|
||||
{
|
||||
const float y1 = window->DC.ColumnsStartPosY;
|
||||
const float y2 = window->DC.CursorPos.y;
|
||||
int dragging_column = -1;
|
||||
for (int i = 1; i < window->DC.ColumnsCount; i++)
|
||||
{
|
||||
const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(column_index);
|
||||
KeepAliveID(column_id);
|
||||
const float default_t = column_index / (float)window->DC.ColumnsCount;
|
||||
const float t = window->DC.StateStorage->GetFloat(column_id, default_t); // Cheaply store our floating point value inside the integer (could store a union into the map?)
|
||||
window->DC.ColumnsData[column_index].OffsetNorm = t;
|
||||
float x = window->Pos.x + GetColumnOffset(i);
|
||||
const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(i);
|
||||
const float column_w = 4.0f; // Width for interaction
|
||||
const ImRect column_rect(ImVec2(x - column_w, y1), ImVec2(x + column_w, y2));
|
||||
if (IsClippedEx(column_rect, &column_id, false))
|
||||
continue;
|
||||
|
||||
bool hovered = false, held = false;
|
||||
if (!(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoResize))
|
||||
{
|
||||
ButtonBehavior(column_rect, column_id, &hovered, &held);
|
||||
if (hovered || held)
|
||||
g.MouseCursor = ImGuiMouseCursor_ResizeEW;
|
||||
if (held && g.ActiveIdIsJustActivated)
|
||||
g.ActiveIdClickOffset.x -= column_w; // Store from center of column line (we used a 8 wide rect for columns clicking). This is used by GetDraggedColumnOffset().
|
||||
if (held)
|
||||
dragging_column = i;
|
||||
}
|
||||
|
||||
// Draw column
|
||||
const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator);
|
||||
const float xi = (float)(int)x;
|
||||
window->DrawList->AddLine(ImVec2(xi, y1 + 1.0f), ImVec2(xi, y2), col);
|
||||
}
|
||||
|
||||
// Apply dragging after drawing the column lines, so our rendered lines are in sync with how items were displayed during the frame.
|
||||
if (dragging_column != -1)
|
||||
{
|
||||
float x = GetDraggedColumnOffset(dragging_column);
|
||||
SetColumnOffset(dragging_column, x);
|
||||
}
|
||||
window->DrawList->ChannelsSplit(window->DC.ColumnsCount);
|
||||
PushColumnClipRect();
|
||||
PushItemWidth(GetColumnWidth() * 0.65f);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->DC.ColumnsData.resize(0);
|
||||
}
|
||||
|
||||
window->DC.ColumnsSetId = 0;
|
||||
window->DC.ColumnsCurrent = 0;
|
||||
window->DC.ColumnsCount = 1;
|
||||
window->DC.ColumnsFlags = 0;
|
||||
window->DC.ColumnsData.resize(0);
|
||||
window->DC.ColumnsOffsetX = 0.0f;
|
||||
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX);
|
||||
}
|
||||
|
||||
// [2017/08: This is currently the only public API, while we are working on making BeginColumns/EndColumns user-facing]
|
||||
void ImGui::Columns(int columns_count, const char* id, bool border)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
IM_ASSERT(columns_count >= 1);
|
||||
|
||||
if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1)
|
||||
EndColumns();
|
||||
|
||||
ImGuiColumnsFlags flags = (border ? 0 : ImGuiColumnsFlags_NoBorder);
|
||||
//flags |= ImGuiColumnsFlags_NoPreserveWidths; // NB: Legacy behavior
|
||||
if (columns_count != 1)
|
||||
BeginColumns(id, columns_count, flags);
|
||||
}
|
||||
|
||||
void ImGui::Indent(float indent_w)
|
||||
|
Reference in New Issue
Block a user