mirror of
https://github.com/ocornut/imgui.git
synced 2026-05-20 20:47:03 +08:00
Tables: Reworked padding/spacing/width.
All widths are stored without padding. Decorelate padding from presence of border. Added ImGuiTableFlags_Pad/NoPad flags. Added demo. Merge StartXHeaders and StartXRows into StartX. Distinguish CellSpacingX1 and CellSpacingX2 for clarity and to avoid loss of width on non-even spacing values.
This commit is contained in:
@@ -1077,9 +1077,13 @@ enum ImGuiTableFlags_
|
||||
ImGuiTableFlags_NoHostExtendY = 1 << 17, // (FIXME-TABLE: Reword as SizingPolicy?) Disable extending past the limit set by outer_size.y, only meaningful when neither of ScrollX|ScrollY are set (data below the limit will be clipped and not visible)
|
||||
ImGuiTableFlags_NoKeepColumnsVisible = 1 << 18, // (FIXME-TABLE) Disable code that keeps column always minimally visible when table width gets too small and horizontal scrolling is off.
|
||||
ImGuiTableFlags_NoClip = 1 << 19, // Disable clipping rectangle for every individual columns (reduce draw command count, items will be able to overflow into other columns). Generally incompatible with TableSetupScrollFreeze().
|
||||
// Padding
|
||||
ImGuiTableFlags_PadOuterX = 1 << 20, // Default if BordersOuterV is on. Enable outer-most padding.
|
||||
ImGuiTableFlags_NoPadOuterX = 1 << 21, // Default if BordersOuterV is off. Disable outer-most padding.
|
||||
ImGuiTableFlags_NoPadInnerX = 1 << 22, // Disable inner padding between columns (double inner padding if BordersOuterV is on, single inner padding if BordersOuterV is off).
|
||||
// Scrolling
|
||||
ImGuiTableFlags_ScrollX = 1 << 20, // Enable horizontal scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size. Because this create a child window, ScrollY is currently generally recommended when using ScrollX.
|
||||
ImGuiTableFlags_ScrollY = 1 << 21, // Enable vertical scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size.
|
||||
ImGuiTableFlags_ScrollX = 1 << 23, // Enable horizontal scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size. Because this create a child window, ScrollY is currently generally recommended when using ScrollX.
|
||||
ImGuiTableFlags_ScrollY = 1 << 24, // Enable vertical scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size.
|
||||
ImGuiTableFlags_Scroll = ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY,
|
||||
|
||||
// [Internal] Combinations and masks
|
||||
@@ -1134,8 +1138,8 @@ enum ImGuiTableRowFlags_
|
||||
enum ImGuiTableBgTarget_
|
||||
{
|
||||
ImGuiTableBgTarget_None = 0,
|
||||
ImGuiTableBgTarget_ColumnBg0 = 1, // FIXME-TABLE: Todo. Set column background color 0 (generally used for background
|
||||
ImGuiTableBgTarget_ColumnBg1 = 2, // FIXME-TABLE: Todo. Set column background color 1 (generally used for selection marking)
|
||||
//ImGuiTableBgTarget_ColumnBg0 = 1, // FIXME-TABLE: Todo. Set column background color 0 (generally used for background
|
||||
//ImGuiTableBgTarget_ColumnBg1 = 2, // FIXME-TABLE: Todo. Set column background color 1 (generally used for selection marking)
|
||||
ImGuiTableBgTarget_RowBg0 = 3, // Set row background color 0 (generally used for background, automatically set when ImGuiTableFlags_RowBg is used)
|
||||
ImGuiTableBgTarget_RowBg1 = 4, // Set row background color 1 (generally used for selection marking)
|
||||
ImGuiTableBgTarget_CellBg = 5 // Set cell background color (top-most color)
|
||||
|
||||
+74
-32
@@ -3405,9 +3405,8 @@ static void ShowDemoWindowTables()
|
||||
{
|
||||
// Expose a few Borders related flags interactively
|
||||
enum ContentsType { CT_Text, CT_FillButton };
|
||||
static ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_RowBg;
|
||||
static ImGuiTableFlags flags = ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg;
|
||||
static bool display_headers = false;
|
||||
static bool display_width = false;
|
||||
static int contents_type = CT_Text;
|
||||
|
||||
PushStyleCompact();
|
||||
@@ -3438,7 +3437,6 @@ static void ShowDemoWindowTables()
|
||||
ImGui::SameLine(); ImGui::RadioButton("Text", &contents_type, CT_Text);
|
||||
ImGui::SameLine(); ImGui::RadioButton("FillButton", &contents_type, CT_FillButton);
|
||||
ImGui::Checkbox("Display headers", &display_headers);
|
||||
ImGui::Checkbox("Display debug width", &display_width);
|
||||
PopStyleCompact();
|
||||
|
||||
if (ImGui::BeginTable("##table1", 3, flags))
|
||||
@@ -3458,28 +3456,11 @@ static void ShowDemoWindowTables()
|
||||
ImGui::TableNextRow();
|
||||
for (int column = 0; column < 3; column++)
|
||||
{
|
||||
ImGui::TableSetColumnIndex(column);
|
||||
char buf[32];
|
||||
if (display_width)
|
||||
{
|
||||
// [DEBUG] Draw limits FIXME-TABLE: Move to Advanced section
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
float contents_x1 = p.x;
|
||||
float contents_x2 = ImGui::GetWindowPos().x + ImGui::GetContentRegionMax().x;
|
||||
float cliprect_x1 = ImGui::GetWindowDrawList()->GetClipRectMin().x;
|
||||
float cliprect_x2 = ImGui::GetWindowDrawList()->GetClipRectMax().x;
|
||||
float y1 = p.y;
|
||||
float y2 = p.y + ImGui::GetTextLineHeight() + 2.0f;
|
||||
ImDrawList* fg_draw_list = ImGui::GetForegroundDrawList();
|
||||
fg_draw_list->AddRect(ImVec2(contents_x1, y1 + 0.0f), ImVec2(contents_x2, y2 + 0.0f), IM_COL32(255, 0, 0, 255)); // Contents limit (e.g. Cell + Padding)
|
||||
fg_draw_list->AddLine(ImVec2(cliprect_x1, y2 + 1.0f), ImVec2(cliprect_x2, y2 + 1.0f), IM_COL32(255, 255, 0, 255)); // Hard clipping limit
|
||||
sprintf(buf, "w=%.2f", contents_x2 - contents_x1);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buf, "Hello %d,%d", row, column);
|
||||
}
|
||||
if (!ImGui::TableSetColumnIndex(column))
|
||||
continue;
|
||||
|
||||
char buf[32];
|
||||
sprintf(buf, "Hello %d,%d", row, column);
|
||||
if (contents_type == CT_Text)
|
||||
ImGui::TextUnformatted(buf);
|
||||
else if (contents_type)
|
||||
@@ -3650,25 +3631,82 @@ static void ShowDemoWindowTables()
|
||||
|
||||
if (open_action != -1)
|
||||
ImGui::SetNextItemOpen(open_action != 0);
|
||||
if (ImGui::TreeNode("Explicit widths"))
|
||||
if (ImGui::TreeNode("Padding"))
|
||||
{
|
||||
static ImGuiTableFlags flags = ImGuiTableFlags_None;
|
||||
static ImGuiTableFlags flags = ImGuiTableFlags_BordersV;
|
||||
|
||||
HelpMarker(
|
||||
"We often want outer padding activated when any using features which makes the edges of a column visible:\n"
|
||||
"e.g.:\n"
|
||||
"- BorderOuterV\n"
|
||||
"- any form of row selection\n"
|
||||
"Because of this, activating BorderOuterV sets the default to PadOuterX. Using PadOuterX or NoPadOuterX you can override the default.\n");
|
||||
|
||||
PushStyleCompact();
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_NoKeepColumnsVisible", (unsigned int*)&flags, ImGuiTableFlags_NoKeepColumnsVisible);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_PadOuterX", (unsigned int*)&flags, ImGuiTableFlags_PadOuterX);
|
||||
ImGui::SameLine(); HelpMarker("Enable outer-most padding (default if ImGuiTableFlags_BordersOuterV is set)");
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_NoPadOuterX", (unsigned int*)&flags, ImGuiTableFlags_NoPadOuterX);
|
||||
ImGui::SameLine(); HelpMarker("Disable outer-most padding (default if ImGuiTableFlags_BordersOuterV is not set)");
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_NoPadInnerX", (unsigned int*)&flags, ImGuiTableFlags_NoPadInnerX);
|
||||
ImGui::SameLine(); HelpMarker("Disable inner padding between columns (double inner padding if BordersOuterV is on, single inner padding if BordersOuterV is off)");
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_BordersOuterV", (unsigned int*)&flags, ImGuiTableFlags_BordersOuterV);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_BordersInnerV", (unsigned int*)&flags, ImGuiTableFlags_BordersInnerV);
|
||||
PopStyleCompact();
|
||||
|
||||
if (ImGui::BeginTable("##table1", 3, flags))
|
||||
{
|
||||
// We could also set ImGuiTableFlags_SizingPolicyFixedX on the table and all columns will default to ImGuiTableColumnFlags_WidthFixed.
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, TEXT_BASE_WIDTH * 15.0f);
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, TEXT_BASE_WIDTH * 30.0f);
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, TEXT_BASE_WIDTH * 15.0f);
|
||||
for (int row = 0; row < 5; row++)
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
for (int column = 0; column < 3; column++)
|
||||
{
|
||||
ImGui::TableSetColumnIndex(column);
|
||||
if (row == 0)
|
||||
{
|
||||
ImGui::Text("Avail %.2f", ImGui::GetContentRegionAvail().x);
|
||||
}
|
||||
else
|
||||
{
|
||||
char buf[32];
|
||||
sprintf(buf, "Hello %d,%d", row, column);
|
||||
ImGui::Button(buf, ImVec2(-FLT_MIN, 0.0f));
|
||||
}
|
||||
if (ImGui::TableGetHoveredColumn() == column)
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, IM_COL32(0, 100, 0, 255));
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
if (open_action != -1)
|
||||
ImGui::SetNextItemOpen(open_action != 0);
|
||||
if (ImGui::TreeNode("Explicit widths"))
|
||||
{
|
||||
static ImGuiTableFlags flags = ImGuiTableFlags_None;
|
||||
PushStyleCompact();
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_NoKeepColumnsVisible", (unsigned int*)&flags, ImGuiTableFlags_NoKeepColumnsVisible);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_BordersInnerV", (unsigned int*)&flags, ImGuiTableFlags_BordersInnerV);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_BordersOuterV", (unsigned int*)&flags, ImGuiTableFlags_BordersOuterV);
|
||||
PopStyleCompact();
|
||||
|
||||
if (ImGui::BeginTable("##table1", 4, flags))
|
||||
{
|
||||
// We could also set ImGuiTableFlags_SizingPolicyFixedX on the table and all columns will default to ImGuiTableColumnFlags_WidthFixed.
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 100.0f);
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, TEXT_BASE_WIDTH * 15.0f);
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, TEXT_BASE_WIDTH * 30.0f);
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, TEXT_BASE_WIDTH * 15.0f);
|
||||
for (int row = 0; row < 5; row++)
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
for (int column = 0; column < 4; column++)
|
||||
{
|
||||
ImGui::TableSetColumnIndex(column);
|
||||
if (row == 0)
|
||||
ImGui::Text("(%.2f)", ImGui::GetContentRegionAvail().x);
|
||||
ImGui::Text("Hello %d,%d", row, column);
|
||||
}
|
||||
}
|
||||
@@ -3679,7 +3717,7 @@ static void ShowDemoWindowTables()
|
||||
|
||||
if (open_action != -1)
|
||||
ImGui::SetNextItemOpen(open_action != 0);
|
||||
if (ImGui::TreeNode("Vertical scrolling, with clipping"))
|
||||
if (ImGui::TreeNode("Vertical scrolling"))
|
||||
{
|
||||
HelpMarker("Here we activate ScrollY, which will create a child window container to allow hosting scrollable contents.\n\nWe also demonstrate using ImGuiListClipper to virtualize the submission of many items.");
|
||||
static ImGuiTableFlags flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable;
|
||||
@@ -4356,6 +4394,7 @@ static void ShowDemoWindowTables()
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
//ImGui::SetNextItemOpen(true, ImGuiCond_Once); // [DEBUG]
|
||||
if (open_action != -1)
|
||||
ImGui::SetNextItemOpen(open_action != 0);
|
||||
if (ImGui::TreeNode("Advanced"))
|
||||
@@ -4415,6 +4454,9 @@ static void ShowDemoWindowTables()
|
||||
|
||||
if (ImGui::TreeNodeEx("Sizing, Padding:", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_PadOuterX", (unsigned int*)&flags, ImGuiTableFlags_PadOuterX);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_NoPadOuterX", (unsigned int*)&flags, ImGuiTableFlags_NoPadOuterX);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_NoPadInnerX", (unsigned int*)&flags, ImGuiTableFlags_NoPadInnerX);
|
||||
if (ImGui::CheckboxFlags("ImGuiTableFlags_SizingPolicyStretchX", (unsigned int*)&flags, ImGuiTableFlags_SizingPolicyStretchX))
|
||||
flags &= ~(ImGuiTableFlags_SizingPolicyMaskX_ ^ ImGuiTableFlags_SizingPolicyStretchX); // Can't specify both sizing polices so we clear the other
|
||||
ImGui::SameLine(); HelpMarker("[Default if ScrollX is off]\nFit all columns within available width (or specified inner_width). Fixed and Stretch columns allowed.");
|
||||
|
||||
+12
-10
@@ -1887,7 +1887,7 @@ struct ImGuiTabBar
|
||||
#define IMGUI_TABLE_MAX_COLUMNS 64 // sizeof(ImU64) * 8. This is solely because we frequently encode columns set in a ImU64.
|
||||
#define IMGUI_TABLE_MAX_DRAW_CHANNELS (2 + 64 * 2) // See TableUpdateDrawChannels()
|
||||
|
||||
// [Internal] sizeof() ~ 104
|
||||
// [Internal] sizeof() ~ 108
|
||||
// We use the terminology "Visible" to refer to a column that is not Hidden by user or settings. However it may still be out of view and clipped (see IsClipped).
|
||||
struct ImGuiTableColumn
|
||||
{
|
||||
@@ -1897,10 +1897,11 @@ struct ImGuiTableColumn
|
||||
ImGuiTableColumnFlags Flags; // Effective flags. See ImGuiTableColumnFlags_
|
||||
float MinX; // Absolute positions
|
||||
float MaxX;
|
||||
float WidthOrWeightInitValue; // Value passed to TableSetupColumn()
|
||||
float WidthStretchWeight; // Master width weight when (Flags & _WidthStretch). Often around ~1.0f initially.
|
||||
float WidthRequest; // Master width absolute value when !(Flags & _WidthStretch). When Stretch this is derived every frame from WidthStretchWeight in TableUpdateLayout()
|
||||
float WidthGiven; // Final/actual width visible == (MaxX - MinX), locked in TableUpdateLayout(). May be >WidthRequest to honor minimum width, may be <WidthRequest to honor shrinking columns down in tight space.
|
||||
float InitStretchWeightOrWidth; // Value passed to TableSetupColumn(). For Width it is a content width (_without padding_).
|
||||
float StretchWeight; // Master width weight when (Flags & _WidthStretch). Often around ~1.0f initially.
|
||||
float WidthAuto; // Automatic width
|
||||
float WidthRequest; // Master width absolute value when !(Flags & _WidthStretch). When Stretch this is derived every frame from StretchWeight in TableUpdateLayout()
|
||||
float WidthGiven; // Final/actual width visible == (MaxX - MinX), locked in TableUpdateLayout(). May be > WidthRequest to honor minimum width, may be < WidthRequest to honor shrinking columns down in tight space.
|
||||
float StartX; // Start position for the frame, currently ~(MinX + CellPaddingX)
|
||||
float ContentMaxPosFrozen; // Submitted contents absolute maximum position, from which we can infer width. Kept as float because we need to manipulate those between each cell change.
|
||||
float ContentMaxPosUnfrozen;
|
||||
@@ -1931,7 +1932,7 @@ struct ImGuiTableColumn
|
||||
ImGuiTableColumn()
|
||||
{
|
||||
memset(this, 0, sizeof(*this));
|
||||
WidthStretchWeight = WidthRequest = WidthGiven = -1.0f;
|
||||
StretchWeight = WidthRequest = -1.0f;
|
||||
NameOffset = -1;
|
||||
IsVisible = IsVisibleNextFrame = true;
|
||||
DisplayOrder = IndexWithinVisibleSet = -1;
|
||||
@@ -1985,10 +1986,11 @@ struct ImGuiTable
|
||||
float BorderX1;
|
||||
float BorderX2;
|
||||
float HostIndentX;
|
||||
float CellPaddingX1; // Padding from each borders
|
||||
float CellPaddingX2;
|
||||
float OuterPaddingX;
|
||||
float CellPaddingX; // Padding from each borders
|
||||
float CellPaddingY;
|
||||
float CellSpacingX; // Spacing between non-bordered cells
|
||||
float CellSpacingX1; // Spacing between non-bordered cells
|
||||
float CellSpacingX2;
|
||||
float LastOuterHeight; // Outer height from last frame
|
||||
float LastFirstRowHeight; // Height of first row from last frame
|
||||
float InnerWidth; // User value passed to BeginTable(), see comments at the top of BeginTable() for details.
|
||||
@@ -2285,7 +2287,7 @@ namespace ImGui
|
||||
IMGUI_API void TableEndRow(ImGuiTable* table);
|
||||
IMGUI_API void TableBeginCell(ImGuiTable* table, int column_n);
|
||||
IMGUI_API void TableEndCell(ImGuiTable* table);
|
||||
IMGUI_API ImRect TableGetCellBgRect();
|
||||
IMGUI_API ImRect TableGetCellBgRect(const ImGuiTable* table, int column_n);
|
||||
IMGUI_API const char* TableGetColumnName(const ImGuiTable* table, int column_n);
|
||||
IMGUI_API ImGuiID TableGetColumnResizeID(const ImGuiTable* table, int column_n, int instance_no = 0);
|
||||
IMGUI_API void TableSetColumnAutofit(ImGuiTable* table, int column_n);
|
||||
|
||||
+137
-95
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user