Skip to content

Commit 17536f9

Browse files
committed
Tables: more consistent use of CellPadding.x*2 and clip-rect on right-most side of non-bordered column + fix cellbg for standalone TableHeader call.
Using CellPadding.x on both sides when BorderV is off, generally most consistent and with default value (4,2) promotes at-glance visible spacing between non-bordered columns. Effectively double horizontal padding on non-bordered columns. Made ClipRect.Max.x matches WorkMaxX which is where we'd like to go for windows themselves. TableHeader() submit single cell bg color if not already submitted as a full header row. Misc comments/docs updates.
1 parent 9874077 commit 17536f9

File tree

7 files changed

+25
-35
lines changed

7 files changed

+25
-35
lines changed

docs/FAQ.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ Button("OK"); // Label = "OK", ID = hash of ("MyOtherWindow", "OK")
214214
End();
215215
```
216216
217-
We used "..." above to signify whatever was already pushed to the ID stack previously:
218-
219217
- If you have a same ID twice in the same location, you'll have a conflict:
220218
```cpp
221219
Button("OK");

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas.
132132
### Upcoming Changes
133133

134134
Some of the goals for 2020 are:
135-
- Work on new Tables API (to replace Columns). (see [#2957](https://github.com/ocornut/imgui/issues/2957), in public [tables](https://github.com/ocornut/imgui/tree/tables) branch looking for feedback)
135+
- Work on Tables (see [#2957](https://github.com/ocornut/imgui/issues/2957), now merged in master.
136136
- Work on Docking (see [#2109](https://github.com/ocornut/imgui/issues/2109), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch)
137137
- Work on Multi-Viewport / Multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), in public [docking](https://github.com/ocornut/imgui/tree/docking) branch looking for feedback)
138138
- Work on gamepad/keyboard controls. (see [#787](https://github.com/ocornut/imgui/issues/787))

docs/TODO.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
129129
- group: IsHovered() after EndGroup() covers whole aabb rather than the intersection of individual items. Is that desirable?
130130
- group: merge deactivation/activation within same group (fwd WasEdited flag). (#2550)
131131

132-
- columns: sizing policy (e.g. for each column: fixed size, %, fill, distribute default size among fills) (#513, #125)
133-
- columns: add a conditional parameter to SetColumnOffset() (#513, #125)
134-
- columns: headers. re-orderable. (#513, #125)
135-
- columns: optional sorting modifiers (up/down), sort list so sorting can be done multi-criteria. notify user when sort order changed.
136-
- columns: option to alternate background colors on odd/even scanlines.
137-
- columns: allow columns to recurse.
138-
- columns: allow a same columns set to be interrupted by e.g. CollapsingHeader and resume with columns in sync when moving them.
139-
- columns: sizing is lossy when columns width is very small (default width may turn negative etc.)
140-
- columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (#125)
141-
- columns: flag to add horizontal separator above/below)
142-
- columns/layout: setup minimum line height (equivalent of automatically calling AlignFirstTextHeightToWidgets)
143-
144132
!- color: the color conversion helpers/types are a mess and needs sorting out.
145133
- color: (api breaking) ImGui::ColorConvertXXX functions should be loose ImColorConvertXX to match imgui_internals.h
146134

imgui.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ Index of this file:
2727
// ImVector<>
2828
// ImGuiStyle
2929
// ImGuiIO
30-
// Misc data structures (ImGuiInputTextCallbackData, ImGuiSizeCallbackData, ImGuiPayload)
30+
// Misc data structures (ImGuiInputTextCallbackData, ImGuiSizeCallbackData, ImGuiPayload, ImGuiTableSortSpecs, ImGuiTableColumnSortSpecs)
3131
// Obsolete functions
3232
// Helpers (ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, ImColor)
3333
// Draw List API (ImDrawCallback, ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawListFlags, ImDrawList, ImDrawData)
3434
// Font API (ImFontConfig, ImFontGlyph, ImFontGlyphRangesBuilder, ImFontAtlasFlags, ImFontAtlas, ImFont)
3535
36-
// FIXME-TABLE: Add ImGuiTableSortSpecs and ImGuiTableColumnSortSpecs in "Misc data structures" section above (we don't do it right now to facilitate merging various branches)
37-
3836
*/
3937

4038
#pragma once
@@ -64,6 +62,7 @@ Index of this file:
6462
#define IMGUI_VERSION "1.80 WIP"
6563
#define IMGUI_VERSION_NUM 17906
6664
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
65+
#define IMGUI_HAS_TABLE
6766

6867
// Define attributes of all API symbols declarations (e.g. for DLL under Windows)
6968
// IMGUI_API is used for core imgui functions, IMGUI_IMPL_API is used for the default backends files (imgui_impl_xxx.h)
@@ -680,7 +679,6 @@ namespace ImGui
680679
// TableNextRow() -> Text("Hello 0") // Not OK! Missing TableSetColumnIndex() or TableNextColumn()! Text will not appear!
681680
// ----------------------------------------------------------------------------------------------------------
682681
// - 5. Call EndTable()
683-
#define IMGUI_HAS_TABLE 1
684682
IMGUI_API bool BeginTable(const char* str_id, int columns_count, ImGuiTableFlags flags = 0, const ImVec2& outer_size = ImVec2(0, 0), float inner_width = 0.0f);
685683
IMGUI_API void EndTable(); // only call EndTable() if BeginTable() returns true!
686684
IMGUI_API void TableNextRow(ImGuiTableRowFlags row_flags = 0, float min_row_height = 0.0f); // append into the first cell of a new row.
@@ -1108,7 +1106,7 @@ enum ImGuiTableColumnFlags_
11081106
ImGuiTableColumnFlags_NoSort = 1 << 9, // Disable ability to sort on this field (even if ImGuiTableFlags_Sortable is set on the table).
11091107
ImGuiTableColumnFlags_NoSortAscending = 1 << 10, // Disable ability to sort in the ascending direction.
11101108
ImGuiTableColumnFlags_NoSortDescending = 1 << 11, // Disable ability to sort in the descending direction.
1111-
ImGuiTableColumnFlags_NoHeaderWidth = 1 << 12, // Header width don't contribute to automatic column width.
1109+
ImGuiTableColumnFlags_NoHeaderWidth = 1 << 12, // Disable header text width contribution to automatic column width.
11121110
ImGuiTableColumnFlags_PreferSortAscending = 1 << 13, // Make the initial sort direction Ascending when first sorting on this column (default).
11131111
ImGuiTableColumnFlags_PreferSortDescending = 1 << 14, // Make the initial sort direction Descending when first sorting on this column.
11141112
ImGuiTableColumnFlags_IndentEnable = 1 << 15, // Use current Indent value when entering cell (default for column 0).
@@ -1146,11 +1144,9 @@ enum ImGuiTableRowFlags_
11461144
enum ImGuiTableBgTarget_
11471145
{
11481146
ImGuiTableBgTarget_None = 0,
1149-
//ImGuiTableBgTarget_ColumnBg0 = 1, // FIXME-TABLE: Todo. Set column background color 0 (generally used for background
1150-
//ImGuiTableBgTarget_ColumnBg1 = 2, // FIXME-TABLE: Todo. Set column background color 1 (generally used for selection marking)
1151-
ImGuiTableBgTarget_RowBg0 = 3, // Set row background color 0 (generally used for background, automatically set when ImGuiTableFlags_RowBg is used)
1152-
ImGuiTableBgTarget_RowBg1 = 4, // Set row background color 1 (generally used for selection marking)
1153-
ImGuiTableBgTarget_CellBg = 5 // Set cell background color (top-most color)
1147+
ImGuiTableBgTarget_RowBg0 = 1, // Set row background color 0 (generally used for background, automatically set when ImGuiTableFlags_RowBg is used)
1148+
ImGuiTableBgTarget_RowBg1 = 2, // Set row background color 1 (generally used for selection marking)
1149+
ImGuiTableBgTarget_CellBg = 3 // Set cell background color (top-most color)
11541150
};
11551151

11561152
// Flags for ImGui::IsWindowFocused()

imgui_demo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,7 +3590,7 @@ static void ShowDemoWindowTables()
35903590
// If there is not enough available width to fit all columns, they will however be resized down.
35913591
// FIXME-TABLE: Providing a stretch-on-init would make sense especially for tables which don't have saved settings
35923592
HelpMarker(
3593-
"Using _Resizable + _ColumnsWidthFixedX flags.\n"
3593+
"Using _Resizable + _ColumnsWidthFixed flags.\n"
35943594
"Fixed-width columns generally makes more sense if you want to use horizontal scrolling.\n\n"
35953595
"Double-click a column border to auto-fit the column to its contents.");
35963596
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_ColumnsWidthFixed | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody;
@@ -3723,7 +3723,8 @@ static void ShowDemoWindowTables()
37233723
"e.g.:\n"
37243724
"- BorderOuterV\n"
37253725
"- any form of row selection\n"
3726-
"Because of this, activating BorderOuterV sets the default to PadOuterX. Using PadOuterX or NoPadOuterX you can override the default.\n");
3726+
"Because of this, activating BorderOuterV sets the default to PadOuterX. Using PadOuterX or NoPadOuterX you can override the default.\n\n"
3727+
"Actual padding values are using style.CellPadding.");
37273728

37283729
PushStyleCompact();
37293730
ImGui::CheckboxFlags("ImGuiTableFlags_PadOuterX", &flags, ImGuiTableFlags_PadOuterX);
@@ -4025,7 +4026,7 @@ static void ShowDemoWindowTables()
40254026
HelpMarker("This section allows you to interact and see the effect of StretchX vs FixedX sizing policies depending on whether Scroll is enabled and the contents of your columns.");
40264027
enum ContentsType { CT_ShortText, CT_LongText, CT_Button, CT_FillButton, CT_InputText };
40274028
static ImGuiTableFlags flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_RowBg;
4028-
static int contents_type = CT_Button;
4029+
static int contents_type = CT_LongText;
40294030
static int column_count = 3;
40304031

40314032
PushStyleCompact();

imgui_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ struct ImGuiTableCellData
19631963
ImGuiTableColumnIdx Column; // Column number
19641964
};
19651965

1966-
// FIXME-TABLES: transient data could be stored in a per-stacked table structure: DrawSplitter, SortSpecs, incoming RowData
1966+
// FIXME-TABLE: transient data could be stored in a per-stacked table structure: DrawSplitter, SortSpecs, incoming RowData
19671967
struct ImGuiTable
19681968
{
19691969
ImGuiID ID;

imgui_tables.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,8 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
350350
const float inner_spacing_for_border = (flags & ImGuiTableFlags_BordersInnerV) ? TABLE_BORDER_SIZE : 0.0f;
351351
const float inner_spacing_explicit = (pad_inner_x && (flags & ImGuiTableFlags_BordersInnerV) == 0) ? g.Style.CellPadding.x : 0.0f;
352352
const float inner_padding_explicit = (pad_inner_x && (flags & ImGuiTableFlags_BordersInnerV) != 0) ? g.Style.CellPadding.x : 0.0f;
353-
const float inner_spacing = inner_spacing_for_border + inner_spacing_explicit;
354-
table->CellSpacingX1 = ImCeil(inner_spacing * 0.5f);
355-
table->CellSpacingX2 = inner_spacing - table->CellSpacingX1;
353+
table->CellSpacingX1 = inner_spacing_explicit + inner_spacing_for_border;
354+
table->CellSpacingX2 = inner_spacing_explicit;
356355
table->CellPaddingX = inner_padding_explicit;
357356
table->CellPaddingY = g.Style.CellPadding.y;
358357

@@ -463,7 +462,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
463462
inner_window->SkipItems = true;
464463

465464
// Clear names
466-
// FIXME-TABLES: probably could be done differently...
465+
// FIXME-TABLE: probably could be done differently...
467466
if (table->ColumnsNames.Buf.Size > 0)
468467
{
469468
table->ColumnsNames.Buf.resize(0);
@@ -925,7 +924,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
925924

926925
// Lock all our positions
927926
// - ClipRect.Min.x: Because merging draw commands doesn't compare min boundaries, we make ClipRect.Min.x match left bounds to be consistent regardless of merging.
928-
// - ClipRect.Max.x: using WorkMaxX instead of MaxX (aka including padding) is detrimental to visibility in very-small column.
927+
// - ClipRect.Max.x: using WorkMaxX instead of MaxX (aka including padding) makes things more consistent when resizing down, tho slightly detrimental to visibility in very-small column.
929928
// - FIXME-TABLE: We want equal width columns to have equal (ClipRect.Max.x - WorkMinX) width, which means ClipRect.max.x cannot stray off host_clip_rect.Max.x else right-most column may appear shorter.
930929
column->MinX = offset_x;
931930
column->MaxX = offset_x + column->WidthGiven + table->CellSpacingX1 + table->CellSpacingX2 + table->CellPaddingX * 2.0f;
@@ -934,7 +933,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
934933
column->ItemWidth = ImFloor(column->WidthGiven * 0.65f);
935934
column->ClipRect.Min.x = column->MinX;
936935
column->ClipRect.Min.y = work_rect.Min.y;
937-
column->ClipRect.Max.x = column->MaxX; // column->WorkMaxX;
936+
column->ClipRect.Max.x = column->WorkMaxX; //column->MaxX;
938937
column->ClipRect.Max.y = FLT_MAX;
939938
column->ClipRect.ClipWithFull(host_clip_rect);
940939

@@ -2593,6 +2592,12 @@ void ImGui::TableHeader(const char* label)
25932592
TableSetBgColor(ImGuiTableBgTarget_CellBg, col, table->CurrentColumn);
25942593
RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding);
25952594
}
2595+
else
2596+
{
2597+
// Submit single cell bg color in the case we didn't submit a full header row
2598+
if ((table->RowFlags & ImGuiTableRowFlags_Headers) == 0)
2599+
TableSetBgColor(ImGuiTableBgTarget_CellBg, GetColorU32(ImGuiCol_TableHeaderBg), table->CurrentColumn);
2600+
}
25962601
if (held)
25972602
table->HeldHeaderColumn = (ImGuiTableColumnIdx)column_n;
25982603
window->DC.CursorPos.y -= g.Style.ItemSpacing.y * 0.5f;
@@ -3269,6 +3274,8 @@ void ImGui::DebugNodeTableSettings(ImGuiTableSettings*) {}
32693274
// [SECTION] Columns, BeginColumns, EndColumns, etc.
32703275
// (This is a legacy API, prefer using BeginTable/EndTable!)
32713276
//-------------------------------------------------------------------------
3277+
// FIXME: sizing is lossy when columns width is very small (default width may turn negative etc.)
3278+
//-------------------------------------------------------------------------
32723279
// - SetWindowClipRectBeforeSetChannel() [Internal]
32733280
// - GetColumnIndex()
32743281
// - GetColumnsCount()

0 commit comments

Comments
 (0)