| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1 |
// dear imgui, v1.91.4 |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2 |
// (tables and columns code) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4 |
/* |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
5 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
6 |
Index of this file: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
7 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
8 |
// [SECTION] Commentary |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
9 |
// [SECTION] Header mess |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
10 |
// [SECTION] Tables: Main code |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
11 |
// [SECTION] Tables: Simple accessors |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
12 |
// [SECTION] Tables: Row changes |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
13 |
// [SECTION] Tables: Columns changes |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
14 |
// [SECTION] Tables: Columns width management |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
15 |
// [SECTION] Tables: Drawing |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
16 |
// [SECTION] Tables: Sorting |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
17 |
// [SECTION] Tables: Headers |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
18 |
// [SECTION] Tables: Context Menu |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
19 |
// [SECTION] Tables: Settings (.ini data) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
20 |
// [SECTION] Tables: Garbage Collection |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
21 |
// [SECTION] Tables: Debugging |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
22 |
// [SECTION] Columns, BeginColumns, EndColumns, etc. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
23 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
24 |
*/ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
25 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
26 |
// Navigating this file: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
27 |
// - In Visual Studio: CTRL+comma ("Edit.GoToAll") can follow symbols inside comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
28 |
// - In Visual Studio w/ Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols inside comments. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
29 |
// - In VS Code, CLion, etc.: CTRL+click can follow symbols inside comments. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
30 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
31 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
32 |
// [SECTION] Commentary |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
33 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
34 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
35 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
36 |
// Typical tables call flow: (root level is generally public API): |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
37 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
38 |
// - BeginTable() user begin into a table |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
39 |
// | BeginChild() - (if ScrollX/ScrollY is set) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
40 |
// | TableBeginInitMemory() - first time table is used |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
41 |
// | TableResetSettings() - on settings reset |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
42 |
// | TableLoadSettings() - on settings load |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
43 |
// | TableBeginApplyRequests() - apply queued resizing/reordering/hiding requests |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
44 |
// | - TableSetColumnWidth() - apply resizing width (for mouse resize, often requested by previous frame) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
45 |
// | - TableUpdateColumnsWeightFromWidth()- recompute columns weights (of stretch columns) from their respective width |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
46 |
// - TableSetupColumn() user submit columns details (optional) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
47 |
// - TableSetupScrollFreeze() user submit scroll freeze information (optional) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
48 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
49 |
// - TableUpdateLayout() [Internal] followup to BeginTable(): setup everything: widths, columns positions, clipping rectangles. Automatically called by the FIRST call to TableNextRow() or TableHeadersRow(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
50 |
// | TableSetupDrawChannels() - setup ImDrawList channels |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
51 |
// | TableUpdateBorders() - detect hovering columns for resize, ahead of contents submission |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
52 |
// | TableBeginContextMenuPopup() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
53 |
// | - TableDrawDefaultContextMenu() - draw right-click context menu contents |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
54 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
55 |
// - TableHeadersRow() or TableHeader() user submit a headers row (optional) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
56 |
// | TableSortSpecsClickColumn() - when left-clicked: alter sort order and sort direction |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
57 |
// | TableOpenContextMenu() - when right-clicked: trigger opening of the default context menu |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
58 |
// - TableGetSortSpecs() user queries updated sort specs (optional, generally after submitting headers) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
59 |
// - TableNextRow() user begin into a new row (also automatically called by TableHeadersRow()) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
60 |
// | TableEndRow() - finish existing row |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
61 |
// | TableBeginRow() - add a new row |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
62 |
// - TableSetColumnIndex() / TableNextColumn() user begin into a cell |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
63 |
// | TableEndCell() - close existing column/cell |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
64 |
// | TableBeginCell() - enter into current column/cell |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
65 |
// - [...] user emit contents |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
66 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
67 |
// - EndTable() user ends the table |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
68 |
// | TableDrawBorders() - draw outer borders, inner vertical borders |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
69 |
// | TableMergeDrawChannels() - merge draw channels if clipping isn't required |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
70 |
// | EndChild() - (if ScrollX/ScrollY is set) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
71 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
72 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
73 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
74 |
// TABLE SIZING |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
75 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
76 |
// (Read carefully because this is subtle but it does make sense!) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
77 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
78 |
// About 'outer_size': |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
79 |
// Its meaning needs to differ slightly depending on if we are using ScrollX/ScrollY flags. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
80 |
// Default value is ImVec2(0.0f, 0.0f). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
81 |
// X |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
82 |
// - outer_size.x <= 0.0f -> Right-align from window/work-rect right-most edge. With -FLT_MIN or 0.0f will align exactly on right-most edge. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
83 |
// - outer_size.x > 0.0f -> Set Fixed width. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
84 |
// Y with ScrollX/ScrollY disabled: we output table directly in current window |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
85 |
// - outer_size.y < 0.0f -> Bottom-align (but will auto extend, unless _NoHostExtendY is set). Not meaningful if parent window can vertically scroll. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
86 |
// - outer_size.y = 0.0f -> No minimum height (but will auto extend, unless _NoHostExtendY is set) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
87 |
// - outer_size.y > 0.0f -> Set Minimum height (but will auto extend, unless _NoHostExtendY is set) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
88 |
// Y with ScrollX/ScrollY enabled: using a child window for scrolling |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
89 |
// - outer_size.y < 0.0f -> Bottom-align. Not meaningful if parent window can vertically scroll. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
90 |
// - outer_size.y = 0.0f -> Bottom-align, consistent with BeginChild(). Not recommended unless table is last item in parent window. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
91 |
// - outer_size.y > 0.0f -> Set Exact height. Recommended when using Scrolling on any axis. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
92 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
93 |
// Outer size is also affected by the NoHostExtendX/NoHostExtendY flags. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
94 |
// Important to note how the two flags have slightly different behaviors! |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
95 |
// - ImGuiTableFlags_NoHostExtendX -> Make outer width auto-fit to columns (overriding outer_size.x value). Only available when ScrollX/ScrollY are disabled and Stretch columns are not used. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
96 |
// - ImGuiTableFlags_NoHostExtendY -> Make outer height stop exactly at outer_size.y (prevent auto-extending table past the limit). Only available when ScrollX/ScrollY is disabled. Data below the limit will be clipped and not visible. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
97 |
// In theory ImGuiTableFlags_NoHostExtendY could be the default and any non-scrolling tables with outer_size.y != 0.0f would use exact height. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
98 |
// This would be consistent but perhaps less useful and more confusing (as vertically clipped items are not useful and not easily noticeable). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
99 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
100 |
// About 'inner_width': |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
101 |
// With ScrollX disabled: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
102 |
// - inner_width -> *ignored* |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
103 |
// With ScrollX enabled: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
104 |
// - inner_width < 0.0f -> *illegal* fit in known width (right align from outer_size.x) <-- weird |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
105 |
// - inner_width = 0.0f -> fit in outer_width: Fixed size columns will take space they need (if avail, otherwise shrink down), Stretch columns becomes Fixed columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
106 |
// - inner_width > 0.0f -> override scrolling width, generally to be larger than outer_size.x. Fixed column take space they need (if avail, otherwise shrink down), Stretch columns share remaining space! |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
107 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
108 |
// Details: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
109 |
// - If you want to use Stretch columns with ScrollX, you generally need to specify 'inner_width' otherwise the concept |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
110 |
// of "available space" doesn't make sense. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
111 |
// - Even if not really useful, we allow 'inner_width < outer_size.x' for consistency and to facilitate understanding |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
112 |
// of what the value does. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
113 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
114 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
115 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
116 |
// COLUMNS SIZING POLICIES |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
117 |
// (Reference: ImGuiTableFlags_SizingXXX flags and ImGuiTableColumnFlags_WidthXXX flags) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
118 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
119 |
// About overriding column sizing policy and width/weight with TableSetupColumn(): |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
120 |
// We use a default parameter of -1 for 'init_width'/'init_weight'. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
121 |
// - with ImGuiTableColumnFlags_WidthFixed, init_width <= 0 (default) --> width is automatic |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
122 |
// - with ImGuiTableColumnFlags_WidthFixed, init_width > 0 (explicit) --> width is custom |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
123 |
// - with ImGuiTableColumnFlags_WidthStretch, init_weight <= 0 (default) --> weight is 1.0f |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
124 |
// - with ImGuiTableColumnFlags_WidthStretch, init_weight > 0 (explicit) --> weight is custom |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
125 |
// Widths are specified _without_ CellPadding. If you specify a width of 100.0f, the column will be cover (100.0f + Padding * 2.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
126 |
// and you can fit a 100.0f wide item in it without clipping and with padding honored. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
127 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
128 |
// About default sizing policy (if you don't specify a ImGuiTableColumnFlags_WidthXXXX flag) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
129 |
// - with Table policy ImGuiTableFlags_SizingFixedFit --> default Column policy is ImGuiTableColumnFlags_WidthFixed, default Width is equal to contents width |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
130 |
// - with Table policy ImGuiTableFlags_SizingFixedSame --> default Column policy is ImGuiTableColumnFlags_WidthFixed, default Width is max of all contents width |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
131 |
// - with Table policy ImGuiTableFlags_SizingStretchSame --> default Column policy is ImGuiTableColumnFlags_WidthStretch, default Weight is 1.0f |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
132 |
// - with Table policy ImGuiTableFlags_SizingStretchWeight --> default Column policy is ImGuiTableColumnFlags_WidthStretch, default Weight is proportional to contents |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
133 |
// Default Width and default Weight can be overridden when calling TableSetupColumn(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
134 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
135 |
// About mixing Fixed/Auto and Stretch columns together: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
136 |
// - the typical use of mixing sizing policies is: any number of LEADING Fixed columns, followed by one or two TRAILING Stretch columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
137 |
// - using mixed policies with ScrollX does not make much sense, as using Stretch columns with ScrollX does not make much sense in the first place! |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
138 |
// that is, unless 'inner_width' is passed to BeginTable() to explicitly provide a total width to layout columns in. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
139 |
// - when using ImGuiTableFlags_SizingFixedSame with mixed columns, only the Fixed/Auto columns will match their widths to the width of the maximum contents. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
140 |
// - when using ImGuiTableFlags_SizingStretchSame with mixed columns, only the Stretch columns will match their weights/widths. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
141 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
142 |
// About using column width: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
143 |
// If a column is manually resizable or has a width specified with TableSetupColumn(): |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
144 |
// - you may use GetContentRegionAvail().x to query the width available in a given column. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
145 |
// - right-side alignment features such as SetNextItemWidth(-x) or PushItemWidth(-x) will rely on this width. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
146 |
// If the column is not resizable and has no width specified with TableSetupColumn(): |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
147 |
// - its width will be automatic and be set to the max of items submitted. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
148 |
// - therefore you generally cannot have ALL items of the columns use e.g. SetNextItemWidth(-FLT_MIN). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
149 |
// - but if the column has one or more items of known/fixed size, this will become the reference width used by SetNextItemWidth(-FLT_MIN). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
150 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
151 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
152 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
153 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
154 |
// TABLES CLIPPING/CULLING |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
155 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
156 |
// About clipping/culling of Rows in Tables: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
157 |
// - For large numbers of rows, it is recommended you use ImGuiListClipper to submit only visible rows. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
158 |
// ImGuiListClipper is reliant on the fact that rows are of equal height. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
159 |
// See 'Demo->Tables->Vertical Scrolling' or 'Demo->Tables->Advanced' for a demo of using the clipper. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
160 |
// - Note that auto-resizing columns don't play well with using the clipper. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
161 |
// By default a table with _ScrollX but without _Resizable will have column auto-resize. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
162 |
// So, if you want to use the clipper, make sure to either enable _Resizable, either setup columns width explicitly with _WidthFixed. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
163 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
164 |
// About clipping/culling of Columns in Tables: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
165 |
// - Both TableSetColumnIndex() and TableNextColumn() return true when the column is visible or performing |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
166 |
// width measurements. Otherwise, you may skip submitting the contents of a cell/column, BUT ONLY if you know |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
167 |
// it is not going to contribute to row height. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
168 |
// In many situations, you may skip submitting contents for every column but one (e.g. the first one). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
169 |
// - Case A: column is not hidden by user, and at least partially in sight (most common case). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
170 |
// - Case B: column is clipped / out of sight (because of scrolling or parent ClipRect): TableNextColumn() return false as a hint but we still allow layout output. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
171 |
// - Case C: column is hidden explicitly by the user (e.g. via the context menu, or _DefaultHide column flag, etc.). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
172 |
// |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
173 |
// [A] [B] [C] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
174 |
// TableNextColumn(): true false false -> [userland] when TableNextColumn() / TableSetColumnIndex() returns false, user can skip submitting items but only if the column doesn't contribute to row height. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
175 |
// SkipItems: false false true -> [internal] when SkipItems is true, most widgets will early out if submitted, resulting is no layout output. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
176 |
// ClipRect: normal zero-width zero-width -> [internal] when ClipRect is zero, ItemAdd() will return false and most widgets will early out mid-way. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
177 |
// ImDrawList output: normal dummy dummy -> [internal] when using the dummy channel, ImDrawList submissions (if any) will be wasted (because cliprect is zero-width anyway). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
178 |
// |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
179 |
// - We need to distinguish those cases because non-hidden columns that are clipped outside of scrolling bounds should still contribute their height to the row. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
180 |
// However, in the majority of cases, the contribution to row height is the same for all columns, or the tallest cells are known by the programmer. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
181 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
182 |
// About clipping/culling of whole Tables: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
183 |
// - Scrolling tables with a known outer size can be clipped earlier as BeginTable() will return false. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
184 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
185 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
186 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
187 |
// [SECTION] Header mess |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
188 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
189 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
190 |
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
191 |
#define _CRT_SECURE_NO_WARNINGS |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
192 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
193 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
194 |
#ifndef IMGUI_DEFINE_MATH_OPERATORS |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
195 |
#define IMGUI_DEFINE_MATH_OPERATORS |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
196 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
197 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
198 |
#include "imgui.h" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
199 |
#ifndef IMGUI_DISABLE |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
200 |
#include "imgui_internal.h" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
201 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
202 |
// System includes |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
203 |
#include <stdint.h> // intptr_t |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
204 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
205 |
// Visual Studio warnings |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
206 |
#ifdef _MSC_VER |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
207 |
#pragma warning (disable: 4127) // condition expression is constant |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
208 |
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
209 |
#if defined(_MSC_VER) && _MSC_VER >= 1922 // MSVC 2019 16.2 or later |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
210 |
#pragma warning (disable: 5054) // operator '|': deprecated between enumerations of different types |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
211 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
212 |
#pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
213 |
#pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
214 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
215 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
216 |
// Clang/GCC warnings with -Weverything |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
217 |
#if defined(__clang__) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
218 |
#if __has_warning("-Wunknown-warning-option") |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
219 |
#pragma clang diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx' // not all warnings are known by all Clang versions and they tend to be rename-happy.. so ignoring warnings triggers new warnings on some configuration. Great! |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
220 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
221 |
#pragma clang diagnostic ignored "-Wunknown-pragmas" // warning: unknown warning group 'xxx' |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
222 |
#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast // yes, they are more terse. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
223 |
#pragma clang diagnostic ignored "-Wfloat-equal" // warning: comparing floating point with == or != is unsafe // storing and comparing against same constants (typically 0.0f) is ok. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
224 |
#pragma clang diagnostic ignored "-Wformat-nonliteral" // warning: format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
225 |
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
226 |
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning: zero as null pointer constant // some standard header variations use #define NULL 0 |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
227 |
#pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
228 |
#pragma clang diagnostic ignored "-Wenum-enum-conversion" // warning: bitwise operation between different enumeration types ('XXXFlags_' and 'XXXFlagsPrivate_') |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
229 |
#pragma clang diagnostic ignored "-Wdeprecated-enum-enum-conversion"// warning: bitwise operation between different enumeration types ('XXXFlags_' and 'XXXFlagsPrivate_') is deprecated |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
230 |
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
231 |
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // warning: 'xxx' is an unsafe pointer used for buffer access |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
232 |
#elif defined(__GNUC__) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
233 |
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
234 |
#pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
235 |
#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
236 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
237 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
238 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
239 |
// [SECTION] Tables: Main code |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
240 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
241 |
// - TableFixFlags() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
242 |
// - TableFindByID() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
243 |
// - BeginTable() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
244 |
// - BeginTableEx() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
245 |
// - TableBeginInitMemory() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
246 |
// - TableBeginApplyRequests() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
247 |
// - TableSetupColumnFlags() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
248 |
// - TableUpdateLayout() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
249 |
// - TableUpdateBorders() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
250 |
// - EndTable() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
251 |
// - TableSetupColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
252 |
// - TableSetupScrollFreeze() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
253 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
254 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
255 |
// Configuration |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
256 |
static const int TABLE_DRAW_CHANNEL_BG0 = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
257 |
static const int TABLE_DRAW_CHANNEL_BG2_FROZEN = 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
258 |
static const int TABLE_DRAW_CHANNEL_NOCLIP = 2; // When using ImGuiTableFlags_NoClip (this becomes the last visible channel) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
259 |
static const float TABLE_BORDER_SIZE = 1.0f; // FIXME-TABLE: Currently hard-coded because of clipping assumptions with outer borders rendering. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
260 |
static const float TABLE_RESIZE_SEPARATOR_HALF_THICKNESS = 4.0f; // Extend outside inner borders. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
261 |
static const float TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER = 0.06f; // Delay/timer before making the hover feedback (color+cursor) visible because tables/columns tends to be more cramped. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
262 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
263 |
// Helper |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
264 |
inline ImGuiTableFlags TableFixFlags(ImGuiTableFlags flags, ImGuiWindow* outer_window) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
265 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
266 |
// Adjust flags: set default sizing policy |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
267 |
if ((flags & ImGuiTableFlags_SizingMask_) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
268 |
flags |= ((flags & ImGuiTableFlags_ScrollX) || (outer_window->Flags & ImGuiWindowFlags_AlwaysAutoResize)) ? ImGuiTableFlags_SizingFixedFit : ImGuiTableFlags_SizingStretchSame; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
269 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
270 |
// Adjust flags: enable NoKeepColumnsVisible when using ImGuiTableFlags_SizingFixedSame |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
271 |
if ((flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedSame) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
272 |
flags |= ImGuiTableFlags_NoKeepColumnsVisible; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
273 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
274 |
// Adjust flags: enforce borders when resizable |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
275 |
if (flags & ImGuiTableFlags_Resizable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
276 |
flags |= ImGuiTableFlags_BordersInnerV; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
277 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
278 |
// Adjust flags: disable NoHostExtendX/NoHostExtendY if we have any scrolling going on |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
279 |
if (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
280 |
flags &= ~(ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_NoHostExtendY); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
281 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
282 |
// Adjust flags: NoBordersInBodyUntilResize takes priority over NoBordersInBody |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
283 |
if (flags & ImGuiTableFlags_NoBordersInBodyUntilResize) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
284 |
flags &= ~ImGuiTableFlags_NoBordersInBody; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
285 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
286 |
// Adjust flags: disable saved settings if there's nothing to save |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
287 |
if ((flags & (ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Sortable)) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
288 |
flags |= ImGuiTableFlags_NoSavedSettings; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
289 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
290 |
// Inherit _NoSavedSettings from top-level window (child windows always have _NoSavedSettings set) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
291 |
if (outer_window->RootWindow->Flags & ImGuiWindowFlags_NoSavedSettings) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
292 |
flags |= ImGuiTableFlags_NoSavedSettings; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
293 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
294 |
return flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
295 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
296 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
297 |
ImGuiTable* ImGui::TableFindByID(ImGuiID id) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
298 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
299 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
300 |
return g.Tables.GetByKey(id); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
301 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
302 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
303 |
// Read about "TABLE SIZING" at the top of this file. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
304 |
bool ImGui::BeginTable(const char* str_id, int columns_count, ImGuiTableFlags flags, const ImVec2& outer_size, float inner_width) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
305 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
306 |
ImGuiID id = GetID(str_id); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
307 |
return BeginTableEx(str_id, id, columns_count, flags, outer_size, inner_width); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
308 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
309 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
310 |
bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImGuiTableFlags flags, const ImVec2& outer_size, float inner_width) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
311 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
312 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
313 |
ImGuiWindow* outer_window = GetCurrentWindow(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
314 |
if (outer_window->SkipItems) // Consistent with other tables + beneficial side effect that assert on miscalling EndTable() will be more visible. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
315 |
return false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
316 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
317 |
// Sanity checks |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
318 |
IM_ASSERT(columns_count > 0 && columns_count < IMGUI_TABLE_MAX_COLUMNS); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
319 |
if (flags & ImGuiTableFlags_ScrollX) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
320 |
IM_ASSERT(inner_width >= 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
321 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
322 |
// If an outer size is specified ahead we will be able to early out when not visible. Exact clipping criteria may evolve. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
323 |
// FIXME: coarse clipping because access to table data causes two issues: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
324 |
// - instance numbers varying/unstable. may not be a direct problem for users, but could make outside access broken or confusing, e.g. TestEngine. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
325 |
// - can't implement support for ImGuiChildFlags_ResizeY as we need to somehow pull the height data from somewhere. this also needs stable instance numbers. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
326 |
// The side-effects of accessing table data on coarse clip would be: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
327 |
// - always reserving the pooled ImGuiTable data ahead for a fully clipped table (minor IMHO). Also the 'outer_window_is_measuring_size' criteria may already be defeating this in some situations. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
328 |
// - always performing the GetOrAddByKey() O(log N) query in g.Tables.Map[]. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
329 |
const bool use_child_window = (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) != 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
330 |
const ImVec2 avail_size = GetContentRegionAvail(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
331 |
const ImVec2 actual_outer_size = ImTrunc(CalcItemSize(outer_size, ImMax(avail_size.x, 1.0f), use_child_window ? ImMax(avail_size.y, 1.0f) : 0.0f)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
332 |
const ImRect outer_rect(outer_window->DC.CursorPos, outer_window->DC.CursorPos + actual_outer_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
333 |
const bool outer_window_is_measuring_size = (outer_window->AutoFitFramesX > 0) || (outer_window->AutoFitFramesY > 0); // Doesn't apply to AlwaysAutoResize windows! |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
334 |
if (use_child_window && IsClippedEx(outer_rect, 0) && !outer_window_is_measuring_size) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
335 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
336 |
ItemSize(outer_rect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
337 |
ItemAdd(outer_rect, id); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
338 |
return false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
339 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
340 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
341 |
// [DEBUG] Debug break requested by user |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
342 |
if (g.DebugBreakInTable == id) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
343 |
IM_DEBUG_BREAK(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
344 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
345 |
// Acquire storage for the table |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
346 |
ImGuiTable* table = g.Tables.GetOrAddByKey(id); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
347 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
348 |
// Acquire temporary buffers |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
349 |
const int table_idx = g.Tables.GetIndex(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
350 |
if (++g.TablesTempDataStacked > g.TablesTempData.Size) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
351 |
g.TablesTempData.resize(g.TablesTempDataStacked, ImGuiTableTempData()); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
352 |
ImGuiTableTempData* temp_data = table->TempData = &g.TablesTempData[g.TablesTempDataStacked - 1]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
353 |
temp_data->TableIndex = table_idx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
354 |
table->DrawSplitter = &table->TempData->DrawSplitter; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
355 |
table->DrawSplitter->Clear(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
356 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
357 |
// Fix flags |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
358 |
table->IsDefaultSizingPolicy = (flags & ImGuiTableFlags_SizingMask_) == 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
359 |
flags = TableFixFlags(flags, outer_window); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
360 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
361 |
// Initialize |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
362 |
const int previous_frame_active = table->LastFrameActive; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
363 |
const int instance_no = (previous_frame_active != g.FrameCount) ? 0 : table->InstanceCurrent + 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
364 |
const ImGuiTableFlags previous_flags = table->Flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
365 |
table->ID = id; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
366 |
table->Flags = flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
367 |
table->LastFrameActive = g.FrameCount; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
368 |
table->OuterWindow = table->InnerWindow = outer_window; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
369 |
table->ColumnsCount = columns_count; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
370 |
table->IsLayoutLocked = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
371 |
table->InnerWidth = inner_width; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
372 |
temp_data->UserOuterSize = outer_size; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
373 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
374 |
// Instance data (for instance 0, TableID == TableInstanceID) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
375 |
ImGuiID instance_id; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
376 |
table->InstanceCurrent = (ImS16)instance_no; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
377 |
if (instance_no > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
378 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
379 |
IM_ASSERT(table->ColumnsCount == columns_count && "BeginTable(): Cannot change columns count mid-frame while preserving same ID"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
380 |
if (table->InstanceDataExtra.Size < instance_no) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
381 |
table->InstanceDataExtra.push_back(ImGuiTableInstanceData()); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
382 |
instance_id = GetIDWithSeed(instance_no, GetIDWithSeed("##Instances", NULL, id)); // Push "##Instances" followed by (int)instance_no in ID stack. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
383 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
384 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
385 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
386 |
instance_id = id; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
387 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
388 |
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
389 |
table_instance->TableInstanceID = instance_id; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
390 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
391 |
// When not using a child window, WorkRect.Max will grow as we append contents. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
392 |
if (use_child_window) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
393 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
394 |
// Ensure no vertical scrollbar appears if we only want horizontal one, to make flag consistent |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
395 |
// (we have no other way to disable vertical scrollbar of a window while keeping the horizontal one showing) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
396 |
ImVec2 override_content_size(FLT_MAX, FLT_MAX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
397 |
if ((flags & ImGuiTableFlags_ScrollX) && !(flags & ImGuiTableFlags_ScrollY)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
398 |
override_content_size.y = FLT_MIN; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
399 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
400 |
// Ensure specified width (when not specified, Stretched columns will act as if the width == OuterWidth and |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
401 |
// never lead to any scrolling). We don't handle inner_width < 0.0f, we could potentially use it to right-align |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
402 |
// based on the right side of the child window work rect, which would require knowing ahead if we are going to |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
403 |
// have decoration taking horizontal spaces (typically a vertical scrollbar). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
404 |
if ((flags & ImGuiTableFlags_ScrollX) && inner_width > 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
405 |
override_content_size.x = inner_width; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
406 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
407 |
if (override_content_size.x != FLT_MAX || override_content_size.y != FLT_MAX) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
408 |
SetNextWindowContentSize(ImVec2(override_content_size.x != FLT_MAX ? override_content_size.x : 0.0f, override_content_size.y != FLT_MAX ? override_content_size.y : 0.0f)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
409 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
410 |
// Reset scroll if we are reactivating it |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
411 |
if ((previous_flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
412 |
SetNextWindowScroll(ImVec2(0.0f, 0.0f)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
413 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
414 |
// Create scrolling region (without border and zero window padding) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
415 |
ImGuiWindowFlags child_window_flags = (flags & ImGuiTableFlags_ScrollX) ? ImGuiWindowFlags_HorizontalScrollbar : ImGuiWindowFlags_None; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
416 |
BeginChildEx(name, instance_id, outer_rect.GetSize(), ImGuiChildFlags_None, child_window_flags); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
417 |
table->InnerWindow = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
418 |
table->WorkRect = table->InnerWindow->WorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
419 |
table->OuterRect = table->InnerWindow->Rect(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
420 |
table->InnerRect = table->InnerWindow->InnerRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
421 |
IM_ASSERT(table->InnerWindow->WindowPadding.x == 0.0f && table->InnerWindow->WindowPadding.y == 0.0f && table->InnerWindow->WindowBorderSize == 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
422 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
423 |
// Allow submitting when host is measuring |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
424 |
if (table->InnerWindow->SkipItems && outer_window_is_measuring_size) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
425 |
table->InnerWindow->SkipItems = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
426 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
427 |
// When using multiple instances, ensure they have the same amount of horizontal decorations (aka vertical scrollbar) so stretched columns can be aligned) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
428 |
if (instance_no == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
429 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
430 |
table->HasScrollbarYPrev = table->HasScrollbarYCurr; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
431 |
table->HasScrollbarYCurr = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
432 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
433 |
table->HasScrollbarYCurr |= table->InnerWindow->ScrollbarY; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
434 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
435 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
436 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
437 |
// For non-scrolling tables, WorkRect == OuterRect == InnerRect. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
438 |
// But at this point we do NOT have a correct value for .Max.y (unless a height has been explicitly passed in). It will only be updated in EndTable(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
439 |
table->WorkRect = table->OuterRect = table->InnerRect = outer_rect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
440 |
table->HasScrollbarYPrev = table->HasScrollbarYCurr = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
441 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
442 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
443 |
// Push a standardized ID for both child-using and not-child-using tables |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
444 |
PushOverrideID(id); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
445 |
if (instance_no > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
446 |
PushOverrideID(instance_id); // FIXME: Somehow this is not resolved by stack-tool, even tho GetIDWithSeed() submitted the symbol. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
447 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
448 |
// Backup a copy of host window members we will modify |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
449 |
ImGuiWindow* inner_window = table->InnerWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
450 |
table->HostIndentX = inner_window->DC.Indent.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
451 |
table->HostClipRect = inner_window->ClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
452 |
table->HostSkipItems = inner_window->SkipItems; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
453 |
temp_data->HostBackupWorkRect = inner_window->WorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
454 |
temp_data->HostBackupParentWorkRect = inner_window->ParentWorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
455 |
temp_data->HostBackupColumnsOffset = outer_window->DC.ColumnsOffset; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
456 |
temp_data->HostBackupPrevLineSize = inner_window->DC.PrevLineSize; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
457 |
temp_data->HostBackupCurrLineSize = inner_window->DC.CurrLineSize; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
458 |
temp_data->HostBackupCursorMaxPos = inner_window->DC.CursorMaxPos; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
459 |
temp_data->HostBackupItemWidth = outer_window->DC.ItemWidth; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
460 |
temp_data->HostBackupItemWidthStackSize = outer_window->DC.ItemWidthStack.Size; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
461 |
inner_window->DC.PrevLineSize = inner_window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
462 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
463 |
// Make borders not overlap our contents by offsetting HostClipRect (#6765, #7428, #3752) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
464 |
// (we normally shouldn't alter HostClipRect as we rely on TableMergeDrawChannels() expanding non-clipped column toward the |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
465 |
// limits of that rectangle, in order for ImDrawListSplitter::Merge() to merge the draw commands. However since the overlap |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
466 |
// problem only affect scrolling tables in this case we can get away with doing it without extra cost). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
467 |
if (inner_window != outer_window) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
468 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
469 |
// FIXME: Because inner_window's Scrollbar doesn't know about border size, since it's not encoded in window->WindowBorderSize, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
470 |
// it already overlaps it and doesn't need an extra offset. Ideally we should be able to pass custom border size with |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
471 |
// different x/y values to BeginChild(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
472 |
if (flags & ImGuiTableFlags_BordersOuterV) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
473 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
474 |
table->HostClipRect.Min.x = ImMin(table->HostClipRect.Min.x + TABLE_BORDER_SIZE, table->HostClipRect.Max.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
475 |
if (inner_window->DecoOuterSizeX2 == 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
476 |
table->HostClipRect.Max.x = ImMax(table->HostClipRect.Max.x - TABLE_BORDER_SIZE, table->HostClipRect.Min.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
477 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
478 |
if (flags & ImGuiTableFlags_BordersOuterH) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
479 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
480 |
table->HostClipRect.Min.y = ImMin(table->HostClipRect.Min.y + TABLE_BORDER_SIZE, table->HostClipRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
481 |
if (inner_window->DecoOuterSizeY2 == 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
482 |
table->HostClipRect.Max.y = ImMax(table->HostClipRect.Max.y - TABLE_BORDER_SIZE, table->HostClipRect.Min.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
483 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
484 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
485 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
486 |
// Padding and Spacing |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
487 |
// - None ........Content..... Pad .....Content........ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
488 |
// - PadOuter | Pad ..Content..... Pad .....Content.. Pad | |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
489 |
// - PadInner ........Content.. Pad | Pad ..Content........ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
490 |
// - PadOuter+PadInner | Pad ..Content.. Pad | Pad ..Content.. Pad | |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
491 |
const bool pad_outer_x = (flags & ImGuiTableFlags_NoPadOuterX) ? false : (flags & ImGuiTableFlags_PadOuterX) ? true : (flags & ImGuiTableFlags_BordersOuterV) != 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
492 |
const bool pad_inner_x = (flags & ImGuiTableFlags_NoPadInnerX) ? false : true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
493 |
const float inner_spacing_for_border = (flags & ImGuiTableFlags_BordersInnerV) ? TABLE_BORDER_SIZE : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
494 |
const float inner_spacing_explicit = (pad_inner_x && (flags & ImGuiTableFlags_BordersInnerV) == 0) ? g.Style.CellPadding.x : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
495 |
const float inner_padding_explicit = (pad_inner_x && (flags & ImGuiTableFlags_BordersInnerV) != 0) ? g.Style.CellPadding.x : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
496 |
table->CellSpacingX1 = inner_spacing_explicit + inner_spacing_for_border; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
497 |
table->CellSpacingX2 = inner_spacing_explicit; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
498 |
table->CellPaddingX = inner_padding_explicit; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
499 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
500 |
const float outer_padding_for_border = (flags & ImGuiTableFlags_BordersOuterV) ? TABLE_BORDER_SIZE : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
501 |
const float outer_padding_explicit = pad_outer_x ? g.Style.CellPadding.x : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
502 |
table->OuterPaddingX = (outer_padding_for_border + outer_padding_explicit) - table->CellPaddingX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
503 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
504 |
table->CurrentColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
505 |
table->CurrentRow = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
506 |
table->RowBgColorCounter = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
507 |
table->LastRowFlags = ImGuiTableRowFlags_None; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
508 |
table->InnerClipRect = (inner_window == outer_window) ? table->WorkRect : inner_window->ClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
509 |
table->InnerClipRect.ClipWith(table->WorkRect); // We need this to honor inner_width |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
510 |
table->InnerClipRect.ClipWithFull(table->HostClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
511 |
table->InnerClipRect.Max.y = (flags & ImGuiTableFlags_NoHostExtendY) ? ImMin(table->InnerClipRect.Max.y, inner_window->WorkRect.Max.y) : table->HostClipRect.Max.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
512 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
513 |
table->RowPosY1 = table->RowPosY2 = table->WorkRect.Min.y; // This is needed somehow |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
514 |
table->RowTextBaseline = 0.0f; // This will be cleared again by TableBeginRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
515 |
table->RowCellPaddingY = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
516 |
table->FreezeRowsRequest = table->FreezeRowsCount = 0; // This will be setup by TableSetupScrollFreeze(), if any |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
517 |
table->FreezeColumnsRequest = table->FreezeColumnsCount = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
518 |
table->IsUnfrozenRows = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
519 |
table->DeclColumnsCount = table->AngledHeadersCount = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
520 |
if (previous_frame_active + 1 < g.FrameCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
521 |
table->IsActiveIdInTable = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
522 |
table->AngledHeadersHeight = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
523 |
temp_data->AngledHeadersExtraWidth = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
524 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
525 |
// Using opaque colors facilitate overlapping lines of the grid, otherwise we'd need to improve TableDrawBorders() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
526 |
table->BorderColorStrong = GetColorU32(ImGuiCol_TableBorderStrong); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
527 |
table->BorderColorLight = GetColorU32(ImGuiCol_TableBorderLight); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
528 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
529 |
// Make table current |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
530 |
g.CurrentTable = table; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
531 |
outer_window->DC.NavIsScrollPushableX = false; // Shortcut for NavUpdateCurrentWindowIsScrollPushableX(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
532 |
outer_window->DC.CurrentTableIdx = table_idx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
533 |
if (inner_window != outer_window) // So EndChild() within the inner window can restore the table properly. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
534 |
inner_window->DC.CurrentTableIdx = table_idx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
535 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
536 |
if ((previous_flags & ImGuiTableFlags_Reorderable) && (flags & ImGuiTableFlags_Reorderable) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
537 |
table->IsResetDisplayOrderRequest = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
538 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
539 |
// Mark as used to avoid GC |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
540 |
if (table_idx >= g.TablesLastTimeActive.Size) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
541 |
g.TablesLastTimeActive.resize(table_idx + 1, -1.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
542 |
g.TablesLastTimeActive[table_idx] = (float)g.Time; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
543 |
temp_data->LastTimeActive = (float)g.Time; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
544 |
table->MemoryCompacted = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
545 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
546 |
// Setup memory buffer (clear data if columns count changed) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
547 |
ImGuiTableColumn* old_columns_to_preserve = NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
548 |
void* old_columns_raw_data = NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
549 |
const int old_columns_count = table->Columns.size(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
550 |
if (old_columns_count != 0 && old_columns_count != columns_count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
551 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
552 |
// Attempt to preserve width on column count change (#4046) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
553 |
old_columns_to_preserve = table->Columns.Data; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
554 |
old_columns_raw_data = table->RawData; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
555 |
table->RawData = NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
556 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
557 |
if (table->RawData == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
558 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
559 |
TableBeginInitMemory(table, columns_count); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
560 |
table->IsInitializing = table->IsSettingsRequestLoad = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
561 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
562 |
if (table->IsResetAllRequest) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
563 |
TableResetSettings(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
564 |
if (table->IsInitializing) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
565 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
566 |
// Initialize |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
567 |
table->SettingsOffset = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
568 |
table->IsSortSpecsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
569 |
table->InstanceInteracted = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
570 |
table->ContextPopupColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
571 |
table->ReorderColumn = table->ResizedColumn = table->LastResizedColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
572 |
table->AutoFitSingleColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
573 |
table->HoveredColumnBody = table->HoveredColumnBorder = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
574 |
for (int n = 0; n < columns_count; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
575 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
576 |
ImGuiTableColumn* column = &table->Columns[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
577 |
if (old_columns_to_preserve && n < old_columns_count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
578 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
579 |
// FIXME: We don't attempt to preserve column order in this path. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
580 |
*column = old_columns_to_preserve[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
581 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
582 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
583 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
584 |
float width_auto = column->WidthAuto; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
585 |
*column = ImGuiTableColumn(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
586 |
column->WidthAuto = width_auto; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
587 |
column->IsPreserveWidthAuto = true; // Preserve WidthAuto when reinitializing a live table: not technically necessary but remove a visible flicker |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
588 |
column->IsEnabled = column->IsUserEnabled = column->IsUserEnabledNextFrame = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
589 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
590 |
column->DisplayOrder = table->DisplayOrderToIndex[n] = (ImGuiTableColumnIdx)n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
591 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
592 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
593 |
if (old_columns_raw_data) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
594 |
IM_FREE(old_columns_raw_data); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
595 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
596 |
// Load settings |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
597 |
if (table->IsSettingsRequestLoad) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
598 |
TableLoadSettings(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
599 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
600 |
// Handle DPI/font resize |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
601 |
// This is designed to facilitate DPI changes with the assumption that e.g. style.CellPadding has been scaled as well. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
602 |
// It will also react to changing fonts with mixed results. It doesn't need to be perfect but merely provide a decent transition. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
603 |
// FIXME-DPI: Provide consistent standards for reference size. Perhaps using g.CurrentDpiScale would be more self explanatory. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
604 |
// This is will lead us to non-rounded WidthRequest in columns, which should work but is a poorly tested path. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
605 |
const float new_ref_scale_unit = g.FontSize; // g.Font->GetCharAdvance('A') ? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
606 |
if (table->RefScale != 0.0f && table->RefScale != new_ref_scale_unit) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
607 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
608 |
const float scale_factor = new_ref_scale_unit / table->RefScale; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
609 |
//IMGUI_DEBUG_PRINT("[table] %08X RefScaleUnit %.3f -> %.3f, scaling width by %.3f\n", table->ID, table->RefScaleUnit, new_ref_scale_unit, scale_factor); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
610 |
for (int n = 0; n < columns_count; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
611 |
table->Columns[n].WidthRequest = table->Columns[n].WidthRequest * scale_factor; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
612 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
613 |
table->RefScale = new_ref_scale_unit; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
614 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
615 |
// Disable output until user calls TableNextRow() or TableNextColumn() leading to the TableUpdateLayout() call.. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
616 |
// This is not strictly necessary but will reduce cases were "out of table" output will be misleading to the user. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
617 |
// Because we cannot safely assert in EndTable() when no rows have been created, this seems like our best option. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
618 |
inner_window->SkipItems = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
619 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
620 |
// Clear names |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
621 |
// At this point the ->NameOffset field of each column will be invalid until TableUpdateLayout() or the first call to TableSetupColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
622 |
if (table->ColumnsNames.Buf.Size > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
623 |
table->ColumnsNames.Buf.resize(0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
624 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
625 |
// Apply queued resizing/reordering/hiding requests |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
626 |
TableBeginApplyRequests(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
627 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
628 |
return true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
629 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
630 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
631 |
// For reference, the average total _allocation count_ for a table is: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
632 |
// + 0 (for ImGuiTable instance, we are pooling allocations in g.Tables[]) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
633 |
// + 1 (for table->RawData allocated below) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
634 |
// + 1 (for table->ColumnsNames, if names are used) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
635 |
// Shared allocations for the maximum number of simultaneously nested tables (generally a very small number) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
636 |
// + 1 (for table->Splitter._Channels) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
637 |
// + 2 * active_channels_count (for ImDrawCmd and ImDrawIdx buffers inside channels) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
638 |
// Where active_channels_count is variable but often == columns_count or == columns_count + 1, see TableSetupDrawChannels() for details. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
639 |
// Unused channels don't perform their +2 allocations. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
640 |
void ImGui::TableBeginInitMemory(ImGuiTable* table, int columns_count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
641 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
642 |
// Allocate single buffer for our arrays |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
643 |
const int columns_bit_array_size = (int)ImBitArrayGetStorageSizeInBytes(columns_count); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
644 |
ImSpanAllocator<6> span_allocator; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
645 |
span_allocator.Reserve(0, columns_count * sizeof(ImGuiTableColumn)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
646 |
span_allocator.Reserve(1, columns_count * sizeof(ImGuiTableColumnIdx)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
647 |
span_allocator.Reserve(2, columns_count * sizeof(ImGuiTableCellData), 4); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
648 |
for (int n = 3; n < 6; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
649 |
span_allocator.Reserve(n, columns_bit_array_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
650 |
table->RawData = IM_ALLOC(span_allocator.GetArenaSizeInBytes()); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
651 |
memset(table->RawData, 0, span_allocator.GetArenaSizeInBytes()); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
652 |
span_allocator.SetArenaBasePtr(table->RawData); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
653 |
span_allocator.GetSpan(0, &table->Columns); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
654 |
span_allocator.GetSpan(1, &table->DisplayOrderToIndex); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
655 |
span_allocator.GetSpan(2, &table->RowCellData); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
656 |
table->EnabledMaskByDisplayOrder = (ImU32*)span_allocator.GetSpanPtrBegin(3); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
657 |
table->EnabledMaskByIndex = (ImU32*)span_allocator.GetSpanPtrBegin(4); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
658 |
table->VisibleMaskByIndex = (ImU32*)span_allocator.GetSpanPtrBegin(5); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
659 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
660 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
661 |
// Apply queued resizing/reordering/hiding requests |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
662 |
void ImGui::TableBeginApplyRequests(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
663 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
664 |
// Handle resizing request |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
665 |
// (We process this in the TableBegin() of the first instance of each table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
666 |
// FIXME-TABLE: Contains columns if our work area doesn't allow for scrolling? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
667 |
if (table->InstanceCurrent == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
668 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
669 |
if (table->ResizedColumn != -1 && table->ResizedColumnNextWidth != FLT_MAX) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
670 |
TableSetColumnWidth(table->ResizedColumn, table->ResizedColumnNextWidth); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
671 |
table->LastResizedColumn = table->ResizedColumn; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
672 |
table->ResizedColumnNextWidth = FLT_MAX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
673 |
table->ResizedColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
674 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
675 |
// Process auto-fit for single column, which is a special case for stretch columns and fixed columns with FixedSame policy. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
676 |
// FIXME-TABLE: Would be nice to redistribute available stretch space accordingly to other weights, instead of giving it all to siblings. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
677 |
if (table->AutoFitSingleColumn != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
678 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
679 |
TableSetColumnWidth(table->AutoFitSingleColumn, table->Columns[table->AutoFitSingleColumn].WidthAuto); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
680 |
table->AutoFitSingleColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
681 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
682 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
683 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
684 |
// Handle reordering request |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
685 |
// Note: we don't clear ReorderColumn after handling the request. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
686 |
if (table->InstanceCurrent == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
687 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
688 |
if (table->HeldHeaderColumn == -1 && table->ReorderColumn != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
689 |
table->ReorderColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
690 |
table->HeldHeaderColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
691 |
if (table->ReorderColumn != -1 && table->ReorderColumnDir != 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
692 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
693 |
// We need to handle reordering across hidden columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
694 |
// In the configuration below, moving C to the right of E will lead to: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
695 |
// ... C [D] E ---> ... [D] E C (Column name/index) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
696 |
// ... 2 3 4 ... 2 3 4 (Display order) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
697 |
const int reorder_dir = table->ReorderColumnDir; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
698 |
IM_ASSERT(reorder_dir == -1 || reorder_dir == +1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
699 |
IM_ASSERT(table->Flags & ImGuiTableFlags_Reorderable); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
700 |
ImGuiTableColumn* src_column = &table->Columns[table->ReorderColumn]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
701 |
ImGuiTableColumn* dst_column = &table->Columns[(reorder_dir == -1) ? src_column->PrevEnabledColumn : src_column->NextEnabledColumn]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
702 |
IM_UNUSED(dst_column); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
703 |
const int src_order = src_column->DisplayOrder; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
704 |
const int dst_order = dst_column->DisplayOrder; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
705 |
src_column->DisplayOrder = (ImGuiTableColumnIdx)dst_order; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
706 |
for (int order_n = src_order + reorder_dir; order_n != dst_order + reorder_dir; order_n += reorder_dir) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
707 |
table->Columns[table->DisplayOrderToIndex[order_n]].DisplayOrder -= (ImGuiTableColumnIdx)reorder_dir; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
708 |
IM_ASSERT(dst_column->DisplayOrder == dst_order - reorder_dir); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
709 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
710 |
// Display order is stored in both columns->IndexDisplayOrder and table->DisplayOrder[]. Rebuild later from the former. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
711 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
712 |
table->DisplayOrderToIndex[table->Columns[column_n].DisplayOrder] = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
713 |
table->ReorderColumnDir = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
714 |
table->IsSettingsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
715 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
716 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
717 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
718 |
// Handle display order reset request |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
719 |
if (table->IsResetDisplayOrderRequest) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
720 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
721 |
for (int n = 0; n < table->ColumnsCount; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
722 |
table->DisplayOrderToIndex[n] = table->Columns[n].DisplayOrder = (ImGuiTableColumnIdx)n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
723 |
table->IsResetDisplayOrderRequest = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
724 |
table->IsSettingsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
725 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
726 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
727 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
728 |
// Adjust flags: default width mode + stretch columns are not allowed when auto extending |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
729 |
static void TableSetupColumnFlags(ImGuiTable* table, ImGuiTableColumn* column, ImGuiTableColumnFlags flags_in) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
730 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
731 |
ImGuiTableColumnFlags flags = flags_in; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
732 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
733 |
// Sizing Policy |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
734 |
if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
735 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
736 |
const ImGuiTableFlags table_sizing_policy = (table->Flags & ImGuiTableFlags_SizingMask_); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
737 |
if (table_sizing_policy == ImGuiTableFlags_SizingFixedFit || table_sizing_policy == ImGuiTableFlags_SizingFixedSame) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
738 |
flags |= ImGuiTableColumnFlags_WidthFixed; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
739 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
740 |
flags |= ImGuiTableColumnFlags_WidthStretch; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
741 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
742 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
743 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
744 |
IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiTableColumnFlags_WidthMask_)); // Check that only 1 of each set is used. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
745 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
746 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
747 |
// Resize |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
748 |
if ((table->Flags & ImGuiTableFlags_Resizable) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
749 |
flags |= ImGuiTableColumnFlags_NoResize; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
750 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
751 |
// Sorting |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
752 |
if ((flags & ImGuiTableColumnFlags_NoSortAscending) && (flags & ImGuiTableColumnFlags_NoSortDescending)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
753 |
flags |= ImGuiTableColumnFlags_NoSort; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
754 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
755 |
// Indentation |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
756 |
if ((flags & ImGuiTableColumnFlags_IndentMask_) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
757 |
flags |= (table->Columns.index_from_ptr(column) == 0) ? ImGuiTableColumnFlags_IndentEnable : ImGuiTableColumnFlags_IndentDisable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
758 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
759 |
// Alignment |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
760 |
//if ((flags & ImGuiTableColumnFlags_AlignMask_) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
761 |
// flags |= ImGuiTableColumnFlags_AlignCenter; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
762 |
//IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiTableColumnFlags_AlignMask_)); // Check that only 1 of each set is used. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
763 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
764 |
// Preserve status flags |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
765 |
column->Flags = flags | (column->Flags & ImGuiTableColumnFlags_StatusMask_); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
766 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
767 |
// Build an ordered list of available sort directions |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
768 |
column->SortDirectionsAvailCount = column->SortDirectionsAvailMask = column->SortDirectionsAvailList = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
769 |
if (table->Flags & ImGuiTableFlags_Sortable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
770 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
771 |
int count = 0, mask = 0, list = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
772 |
if ((flags & ImGuiTableColumnFlags_PreferSortAscending) != 0 && (flags & ImGuiTableColumnFlags_NoSortAscending) == 0) { mask |= 1 << ImGuiSortDirection_Ascending; list |= ImGuiSortDirection_Ascending << (count << 1); count++; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
773 |
if ((flags & ImGuiTableColumnFlags_PreferSortDescending) != 0 && (flags & ImGuiTableColumnFlags_NoSortDescending) == 0) { mask |= 1 << ImGuiSortDirection_Descending; list |= ImGuiSortDirection_Descending << (count << 1); count++; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
774 |
if ((flags & ImGuiTableColumnFlags_PreferSortAscending) == 0 && (flags & ImGuiTableColumnFlags_NoSortAscending) == 0) { mask |= 1 << ImGuiSortDirection_Ascending; list |= ImGuiSortDirection_Ascending << (count << 1); count++; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
775 |
if ((flags & ImGuiTableColumnFlags_PreferSortDescending) == 0 && (flags & ImGuiTableColumnFlags_NoSortDescending) == 0) { mask |= 1 << ImGuiSortDirection_Descending; list |= ImGuiSortDirection_Descending << (count << 1); count++; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
776 |
if ((table->Flags & ImGuiTableFlags_SortTristate) || count == 0) { mask |= 1 << ImGuiSortDirection_None; count++; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
777 |
column->SortDirectionsAvailList = (ImU8)list; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
778 |
column->SortDirectionsAvailMask = (ImU8)mask; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
779 |
column->SortDirectionsAvailCount = (ImU8)count; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
780 |
ImGui::TableFixColumnSortDirection(table, column); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
781 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
782 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
783 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
784 |
// Layout columns for the frame. This is in essence the followup to BeginTable() and this is our largest function. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
785 |
// Runs on the first call to TableNextRow(), to give a chance for TableSetupColumn() and other TableSetupXXXXX() functions to be called first. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
786 |
// FIXME-TABLE: Our width (and therefore our WorkRect) will be minimal in the first frame for _WidthAuto columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
787 |
// Increase feedback side-effect with widgets relying on WorkRect.Max.x... Maybe provide a default distribution for _WidthAuto columns? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
788 |
void ImGui::TableUpdateLayout(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
789 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
790 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
791 |
IM_ASSERT(table->IsLayoutLocked == false); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
792 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
793 |
const ImGuiTableFlags table_sizing_policy = (table->Flags & ImGuiTableFlags_SizingMask_); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
794 |
table->IsDefaultDisplayOrder = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
795 |
table->ColumnsEnabledCount = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
796 |
ImBitArrayClearAllBits(table->EnabledMaskByIndex, table->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
797 |
ImBitArrayClearAllBits(table->EnabledMaskByDisplayOrder, table->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
798 |
table->LeftMostEnabledColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
799 |
table->MinColumnWidth = ImMax(1.0f, g.Style.FramePadding.x * 1.0f); // g.Style.ColumnsMinSpacing; // FIXME-TABLE |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
800 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
801 |
// [Part 1] Apply/lock Enabled and Order states. Calculate auto/ideal width for columns. Count fixed/stretch columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
802 |
// Process columns in their visible orders as we are building the Prev/Next indices. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
803 |
int count_fixed = 0; // Number of columns that have fixed sizing policies |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
804 |
int count_stretch = 0; // Number of columns that have stretch sizing policies |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
805 |
int prev_visible_column_idx = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
806 |
bool has_auto_fit_request = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
807 |
bool has_resizable = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
808 |
float stretch_sum_width_auto = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
809 |
float fixed_max_width_auto = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
810 |
for (int order_n = 0; order_n < table->ColumnsCount; order_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
811 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
812 |
const int column_n = table->DisplayOrderToIndex[order_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
813 |
if (column_n != order_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
814 |
table->IsDefaultDisplayOrder = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
815 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
816 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
817 |
// Clear column setup if not submitted by user. Currently we make it mandatory to call TableSetupColumn() every frame. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
818 |
// It would easily work without but we're not ready to guarantee it since e.g. names need resubmission anyway. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
819 |
// We take a slight shortcut but in theory we could be calling TableSetupColumn() here with dummy values, it should yield the same effect. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
820 |
if (table->DeclColumnsCount <= column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
821 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
822 |
TableSetupColumnFlags(table, column, ImGuiTableColumnFlags_None); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
823 |
column->NameOffset = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
824 |
column->UserID = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
825 |
column->InitStretchWeightOrWidth = -1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
826 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
827 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
828 |
// Update Enabled state, mark settings and sort specs dirty |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
829 |
if (!(table->Flags & ImGuiTableFlags_Hideable) || (column->Flags & ImGuiTableColumnFlags_NoHide)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
830 |
column->IsUserEnabledNextFrame = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
831 |
if (column->IsUserEnabled != column->IsUserEnabledNextFrame) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
832 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
833 |
column->IsUserEnabled = column->IsUserEnabledNextFrame; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
834 |
table->IsSettingsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
835 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
836 |
column->IsEnabled = column->IsUserEnabled && (column->Flags & ImGuiTableColumnFlags_Disabled) == 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
837 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
838 |
if (column->SortOrder != -1 && !column->IsEnabled) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
839 |
table->IsSortSpecsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
840 |
if (column->SortOrder > 0 && !(table->Flags & ImGuiTableFlags_SortMulti)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
841 |
table->IsSortSpecsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
842 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
843 |
// Auto-fit unsized columns |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
844 |
const bool start_auto_fit = (column->Flags & ImGuiTableColumnFlags_WidthFixed) ? (column->WidthRequest < 0.0f) : (column->StretchWeight < 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
845 |
if (start_auto_fit) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
846 |
column->AutoFitQueue = column->CannotSkipItemsQueue = (1 << 3) - 1; // Fit for three frames |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
847 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
848 |
if (!column->IsEnabled) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
849 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
850 |
column->IndexWithinEnabledSet = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
851 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
852 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
853 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
854 |
// Mark as enabled and link to previous/next enabled column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
855 |
column->PrevEnabledColumn = (ImGuiTableColumnIdx)prev_visible_column_idx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
856 |
column->NextEnabledColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
857 |
if (prev_visible_column_idx != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
858 |
table->Columns[prev_visible_column_idx].NextEnabledColumn = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
859 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
860 |
table->LeftMostEnabledColumn = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
861 |
column->IndexWithinEnabledSet = table->ColumnsEnabledCount++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
862 |
ImBitArraySetBit(table->EnabledMaskByIndex, column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
863 |
ImBitArraySetBit(table->EnabledMaskByDisplayOrder, column->DisplayOrder); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
864 |
prev_visible_column_idx = column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
865 |
IM_ASSERT(column->IndexWithinEnabledSet <= column->DisplayOrder); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
866 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
867 |
// Calculate ideal/auto column width (that's the width required for all contents to be visible without clipping) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
868 |
// Combine width from regular rows + width from headers unless requested not to. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
869 |
if (!column->IsPreserveWidthAuto && table->InstanceCurrent == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
870 |
column->WidthAuto = TableGetColumnWidthAuto(table, column); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
871 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
872 |
// Non-resizable columns keep their requested width (apply user value regardless of IsPreserveWidthAuto) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
873 |
const bool column_is_resizable = (column->Flags & ImGuiTableColumnFlags_NoResize) == 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
874 |
if (column_is_resizable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
875 |
has_resizable = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
876 |
if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && column->InitStretchWeightOrWidth > 0.0f && !column_is_resizable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
877 |
column->WidthAuto = column->InitStretchWeightOrWidth; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
878 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
879 |
if (column->AutoFitQueue != 0x00) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
880 |
has_auto_fit_request = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
881 |
if (column->Flags & ImGuiTableColumnFlags_WidthStretch) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
882 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
883 |
stretch_sum_width_auto += column->WidthAuto; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
884 |
count_stretch++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
885 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
886 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
887 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
888 |
fixed_max_width_auto = ImMax(fixed_max_width_auto, column->WidthAuto); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
889 |
count_fixed++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
890 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
891 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
892 |
if ((table->Flags & ImGuiTableFlags_Sortable) && table->SortSpecsCount == 0 && !(table->Flags & ImGuiTableFlags_SortTristate)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
893 |
table->IsSortSpecsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
894 |
table->RightMostEnabledColumn = (ImGuiTableColumnIdx)prev_visible_column_idx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
895 |
IM_ASSERT(table->LeftMostEnabledColumn >= 0 && table->RightMostEnabledColumn >= 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
896 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
897 |
// [Part 2] Disable child window clipping while fitting columns. This is not strictly necessary but makes it possible to avoid |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
898 |
// the column fitting having to wait until the first visible frame of the child container (may or not be a good thing). Also see #6510. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
899 |
// FIXME-TABLE: for always auto-resizing columns may not want to do that all the time. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
900 |
if (has_auto_fit_request && table->OuterWindow != table->InnerWindow) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
901 |
table->InnerWindow->SkipItems = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
902 |
if (has_auto_fit_request) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
903 |
table->IsSettingsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
904 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
905 |
// [Part 3] Fix column flags and record a few extra information. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
906 |
float sum_width_requests = 0.0f; // Sum of all width for fixed and auto-resize columns, excluding width contributed by Stretch columns but including spacing/padding. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
907 |
float stretch_sum_weights = 0.0f; // Sum of all weights for stretch columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
908 |
table->LeftMostStretchedColumn = table->RightMostStretchedColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
909 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
910 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
911 |
if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
912 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
913 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
914 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
915 |
const bool column_is_resizable = (column->Flags & ImGuiTableColumnFlags_NoResize) == 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
916 |
if (column->Flags & ImGuiTableColumnFlags_WidthFixed) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
917 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
918 |
// Apply same widths policy |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
919 |
float width_auto = column->WidthAuto; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
920 |
if (table_sizing_policy == ImGuiTableFlags_SizingFixedSame && (column->AutoFitQueue != 0x00 || !column_is_resizable)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
921 |
width_auto = fixed_max_width_auto; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
922 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
923 |
// Apply automatic width |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
924 |
// Latch initial size for fixed columns and update it constantly for auto-resizing column (unless clipped!) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
925 |
if (column->AutoFitQueue != 0x00) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
926 |
column->WidthRequest = width_auto; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
927 |
else if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !column_is_resizable && column->IsRequestOutput) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
928 |
column->WidthRequest = width_auto; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
929 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
930 |
// FIXME-TABLE: Increase minimum size during init frame to avoid biasing auto-fitting widgets |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
931 |
// (e.g. TextWrapped) too much. Otherwise what tends to happen is that TextWrapped would output a very |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
932 |
// large height (= first frame scrollbar display very off + clipper would skip lots of items). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
933 |
// This is merely making the side-effect less extreme, but doesn't properly fixes it. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
934 |
// FIXME: Move this to ->WidthGiven to avoid temporary lossyless? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
935 |
// FIXME: This break IsPreserveWidthAuto from not flickering if the stored WidthAuto was smaller. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
936 |
if (column->AutoFitQueue > 0x01 && table->IsInitializing && !column->IsPreserveWidthAuto) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
937 |
column->WidthRequest = ImMax(column->WidthRequest, table->MinColumnWidth * 4.0f); // FIXME-TABLE: Another constant/scale? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
938 |
sum_width_requests += column->WidthRequest; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
939 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
940 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
941 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
942 |
// Initialize stretch weight |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
943 |
if (column->AutoFitQueue != 0x00 || column->StretchWeight < 0.0f || !column_is_resizable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
944 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
945 |
if (column->InitStretchWeightOrWidth > 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
946 |
column->StretchWeight = column->InitStretchWeightOrWidth; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
947 |
else if (table_sizing_policy == ImGuiTableFlags_SizingStretchProp) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
948 |
column->StretchWeight = (column->WidthAuto / stretch_sum_width_auto) * count_stretch; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
949 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
950 |
column->StretchWeight = 1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
951 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
952 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
953 |
stretch_sum_weights += column->StretchWeight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
954 |
if (table->LeftMostStretchedColumn == -1 || table->Columns[table->LeftMostStretchedColumn].DisplayOrder > column->DisplayOrder) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
955 |
table->LeftMostStretchedColumn = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
956 |
if (table->RightMostStretchedColumn == -1 || table->Columns[table->RightMostStretchedColumn].DisplayOrder < column->DisplayOrder) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
957 |
table->RightMostStretchedColumn = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
958 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
959 |
column->IsPreserveWidthAuto = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
960 |
sum_width_requests += table->CellPaddingX * 2.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
961 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
962 |
table->ColumnsEnabledFixedCount = (ImGuiTableColumnIdx)count_fixed; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
963 |
table->ColumnsStretchSumWeights = stretch_sum_weights; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
964 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
965 |
// [Part 4] Apply final widths based on requested widths |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
966 |
const ImRect work_rect = table->WorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
967 |
const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
968 |
const float width_removed = (table->HasScrollbarYPrev && !table->InnerWindow->ScrollbarY) ? g.Style.ScrollbarSize : 0.0f; // To synchronize decoration width of synched tables with mismatching scrollbar state (#5920) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
969 |
const float width_avail = ImMax(1.0f, (((table->Flags & ImGuiTableFlags_ScrollX) && table->InnerWidth == 0.0f) ? table->InnerClipRect.GetWidth() : work_rect.GetWidth()) - width_removed); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
970 |
const float width_avail_for_stretched_columns = width_avail - width_spacings - sum_width_requests; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
971 |
float width_remaining_for_stretched_columns = width_avail_for_stretched_columns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
972 |
table->ColumnsGivenWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
973 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
974 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
975 |
if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
976 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
977 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
978 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
979 |
// Allocate width for stretched/weighted columns (StretchWeight gets converted into WidthRequest) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
980 |
if (column->Flags & ImGuiTableColumnFlags_WidthStretch) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
981 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
982 |
float weight_ratio = column->StretchWeight / stretch_sum_weights; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
983 |
column->WidthRequest = IM_TRUNC(ImMax(width_avail_for_stretched_columns * weight_ratio, table->MinColumnWidth) + 0.01f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
984 |
width_remaining_for_stretched_columns -= column->WidthRequest; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
985 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
986 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
987 |
// [Resize Rule 1] The right-most Visible column is not resizable if there is at least one Stretch column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
988 |
// See additional comments in TableSetColumnWidth(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
989 |
if (column->NextEnabledColumn == -1 && table->LeftMostStretchedColumn != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
990 |
column->Flags |= ImGuiTableColumnFlags_NoDirectResize_; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
991 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
992 |
// Assign final width, record width in case we will need to shrink |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
993 |
column->WidthGiven = ImTrunc(ImMax(column->WidthRequest, table->MinColumnWidth)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
994 |
table->ColumnsGivenWidth += column->WidthGiven; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
995 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
996 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
997 |
// [Part 5] Redistribute stretch remainder width due to rounding (remainder width is < 1.0f * number of Stretch column). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
998 |
// Using right-to-left distribution (more likely to match resizing cursor). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
999 |
if (width_remaining_for_stretched_columns >= 1.0f && !(table->Flags & ImGuiTableFlags_PreciseWidths)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1000 |
for (int order_n = table->ColumnsCount - 1; stretch_sum_weights > 0.0f && width_remaining_for_stretched_columns >= 1.0f && order_n >= 0; order_n--) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1001 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1002 |
if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1003 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1004 |
ImGuiTableColumn* column = &table->Columns[table->DisplayOrderToIndex[order_n]]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1005 |
if (!(column->Flags & ImGuiTableColumnFlags_WidthStretch)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1006 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1007 |
column->WidthRequest += 1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1008 |
column->WidthGiven += 1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1009 |
width_remaining_for_stretched_columns -= 1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1010 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1011 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1012 |
// Determine if table is hovered which will be used to flag columns as hovered. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1013 |
// - In principle we'd like to use the equivalent of IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem), |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1014 |
// but because our item is partially submitted at this point we use ItemHoverable() and a workaround (temporarily |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1015 |
// clear ActiveId, which is equivalent to the change provided by _AllowWhenBLockedByActiveItem). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1016 |
// - This allows columns to be marked as hovered when e.g. clicking a button inside the column, or using drag and drop. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1017 |
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1018 |
table_instance->HoveredRowLast = table_instance->HoveredRowNext; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1019 |
table_instance->HoveredRowNext = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1020 |
table->HoveredColumnBody = table->HoveredColumnBorder = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1021 |
const ImRect mouse_hit_rect(table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.Max.x, ImMax(table->OuterRect.Max.y, table->OuterRect.Min.y + table_instance->LastOuterHeight)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1022 |
const ImGuiID backup_active_id = g.ActiveId; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1023 |
g.ActiveId = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1024 |
const bool is_hovering_table = ItemHoverable(mouse_hit_rect, 0, ImGuiItemFlags_None); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1025 |
g.ActiveId = backup_active_id; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1026 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1027 |
// Determine skewed MousePos.x to support angled headers. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1028 |
float mouse_skewed_x = g.IO.MousePos.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1029 |
if (table->AngledHeadersHeight > 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1030 |
if (g.IO.MousePos.y >= table->OuterRect.Min.y && g.IO.MousePos.y <= table->OuterRect.Min.y + table->AngledHeadersHeight) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1031 |
mouse_skewed_x += ImTrunc((table->OuterRect.Min.y + table->AngledHeadersHeight - g.IO.MousePos.y) * table->AngledHeadersSlope); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1032 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1033 |
// [Part 6] Setup final position, offset, skip/clip states and clipping rectangles, detect hovered column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1034 |
// Process columns in their visible orders as we are comparing the visible order and adjusting host_clip_rect while looping. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1035 |
int visible_n = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1036 |
bool has_at_least_one_column_requesting_output = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1037 |
bool offset_x_frozen = (table->FreezeColumnsCount > 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1038 |
float offset_x = ((table->FreezeColumnsCount > 0) ? table->OuterRect.Min.x : work_rect.Min.x) + table->OuterPaddingX - table->CellSpacingX1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1039 |
ImRect host_clip_rect = table->InnerClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1040 |
//host_clip_rect.Max.x += table->CellPaddingX + table->CellSpacingX2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1041 |
ImBitArrayClearAllBits(table->VisibleMaskByIndex, table->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1042 |
for (int order_n = 0; order_n < table->ColumnsCount; order_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1043 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1044 |
const int column_n = table->DisplayOrderToIndex[order_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1045 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1046 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1047 |
column->NavLayerCurrent = (ImS8)(table->FreezeRowsCount > 0 ? ImGuiNavLayer_Menu : ImGuiNavLayer_Main); // Use Count NOT request so Header line changes layer when frozen |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1048 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1049 |
if (offset_x_frozen && table->FreezeColumnsCount == visible_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1050 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1051 |
offset_x += work_rect.Min.x - table->OuterRect.Min.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1052 |
offset_x_frozen = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1053 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1054 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1055 |
// Clear status flags |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1056 |
column->Flags &= ~ImGuiTableColumnFlags_StatusMask_; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1057 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1058 |
if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1059 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1060 |
// Hidden column: clear a few fields and we are done with it for the remainder of the function. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1061 |
// We set a zero-width clip rect but set Min.y/Max.y properly to not interfere with the clipper. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1062 |
column->MinX = column->MaxX = column->WorkMinX = column->ClipRect.Min.x = column->ClipRect.Max.x = offset_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1063 |
column->WidthGiven = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1064 |
column->ClipRect.Min.y = work_rect.Min.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1065 |
column->ClipRect.Max.y = FLT_MAX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1066 |
column->ClipRect.ClipWithFull(host_clip_rect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1067 |
column->IsVisibleX = column->IsVisibleY = column->IsRequestOutput = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1068 |
column->IsSkipItems = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1069 |
column->ItemWidth = 1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1070 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1071 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1072 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1073 |
// Lock start position |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1074 |
column->MinX = offset_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1075 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1076 |
// Lock width based on start position and minimum/maximum width for this position |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1077 |
column->WidthMax = TableCalcMaxColumnWidth(table, column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1078 |
column->WidthGiven = ImMin(column->WidthGiven, column->WidthMax); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1079 |
column->WidthGiven = ImMax(column->WidthGiven, ImMin(column->WidthRequest, table->MinColumnWidth)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1080 |
column->MaxX = offset_x + column->WidthGiven + table->CellSpacingX1 + table->CellSpacingX2 + table->CellPaddingX * 2.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1081 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1082 |
// Lock other positions |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1083 |
// - 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. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1084 |
// - 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. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1085 |
// - ClipRect.Max.x: using MaxX makes it easier for header to receive hover highlight with no discontinuity and display sorting arrow. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1086 |
// - 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. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1087 |
const float previous_instance_work_min_x = column->WorkMinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1088 |
column->WorkMinX = column->MinX + table->CellPaddingX + table->CellSpacingX1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1089 |
column->WorkMaxX = column->MaxX - table->CellPaddingX - table->CellSpacingX2; // Expected max |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1090 |
column->ItemWidth = ImTrunc(column->WidthGiven * 0.65f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1091 |
column->ClipRect.Min.x = column->MinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1092 |
column->ClipRect.Min.y = work_rect.Min.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1093 |
column->ClipRect.Max.x = column->MaxX; //column->WorkMaxX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1094 |
column->ClipRect.Max.y = FLT_MAX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1095 |
column->ClipRect.ClipWithFull(host_clip_rect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1096 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1097 |
// Mark column as Clipped (not in sight) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1098 |
// Note that scrolling tables (where inner_window != outer_window) handle Y clipped earlier in BeginTable() so IsVisibleY really only applies to non-scrolling tables. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1099 |
// FIXME-TABLE: Because InnerClipRect.Max.y is conservatively ==outer_window->ClipRect.Max.y, we never can mark columns _Above_ the scroll line as not IsVisibleY. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1100 |
// Taking advantage of LastOuterHeight would yield good results there... |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1101 |
// FIXME-TABLE: Y clipping is disabled because it effectively means not submitting will reduce contents width which is fed to outer_window->DC.CursorMaxPos.x, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1102 |
// and this may be used (e.g. typically by outer_window using AlwaysAutoResize or outer_window's horizontal scrollbar, but could be something else). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1103 |
// Possible solution to preserve last known content width for clipped column. Test 'table_reported_size' fails when enabling Y clipping and window is resized small. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1104 |
column->IsVisibleX = (column->ClipRect.Max.x > column->ClipRect.Min.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1105 |
column->IsVisibleY = true; // (column->ClipRect.Max.y > column->ClipRect.Min.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1106 |
const bool is_visible = column->IsVisibleX; //&& column->IsVisibleY; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1107 |
if (is_visible) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1108 |
ImBitArraySetBit(table->VisibleMaskByIndex, column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1109 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1110 |
// Mark column as requesting output from user. Note that fixed + non-resizable sets are auto-fitting at all times and therefore always request output. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1111 |
column->IsRequestOutput = is_visible || column->AutoFitQueue != 0 || column->CannotSkipItemsQueue != 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1112 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1113 |
// Mark column as SkipItems (ignoring all items/layout) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1114 |
// (table->HostSkipItems is a copy of inner_window->SkipItems before we cleared it above in Part 2) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1115 |
column->IsSkipItems = !column->IsEnabled || table->HostSkipItems; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1116 |
if (column->IsSkipItems) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1117 |
IM_ASSERT(!is_visible); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1118 |
if (column->IsRequestOutput && !column->IsSkipItems) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1119 |
has_at_least_one_column_requesting_output = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1120 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1121 |
// Update status flags |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1122 |
column->Flags |= ImGuiTableColumnFlags_IsEnabled; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1123 |
if (is_visible) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1124 |
column->Flags |= ImGuiTableColumnFlags_IsVisible; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1125 |
if (column->SortOrder != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1126 |
column->Flags |= ImGuiTableColumnFlags_IsSorted; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1127 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1128 |
// Detect hovered column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1129 |
if (is_hovering_table && mouse_skewed_x >= column->ClipRect.Min.x && mouse_skewed_x < column->ClipRect.Max.x) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1130 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1131 |
column->Flags |= ImGuiTableColumnFlags_IsHovered; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1132 |
table->HoveredColumnBody = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1133 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1134 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1135 |
// Alignment |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1136 |
// FIXME-TABLE: This align based on the whole column width, not per-cell, and therefore isn't useful in |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1137 |
// many cases (to be able to honor this we might be able to store a log of cells width, per row, for |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1138 |
// visible rows, but nav/programmatic scroll would have visible artifacts.) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1139 |
//if (column->Flags & ImGuiTableColumnFlags_AlignRight) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1140 |
// column->WorkMinX = ImMax(column->WorkMinX, column->MaxX - column->ContentWidthRowsUnfrozen); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1141 |
//else if (column->Flags & ImGuiTableColumnFlags_AlignCenter) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1142 |
// column->WorkMinX = ImLerp(column->WorkMinX, ImMax(column->StartX, column->MaxX - column->ContentWidthRowsUnfrozen), 0.5f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1143 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1144 |
// Reset content width variables |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1145 |
if (table->InstanceCurrent == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1146 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1147 |
column->ContentMaxXFrozen = column->WorkMinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1148 |
column->ContentMaxXUnfrozen = column->WorkMinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1149 |
column->ContentMaxXHeadersUsed = column->WorkMinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1150 |
column->ContentMaxXHeadersIdeal = column->WorkMinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1151 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1152 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1153 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1154 |
// As we store an absolute value to make per-cell updates faster, we need to offset values used for width computation. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1155 |
const float offset_from_previous_instance = column->WorkMinX - previous_instance_work_min_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1156 |
column->ContentMaxXFrozen += offset_from_previous_instance; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1157 |
column->ContentMaxXUnfrozen += offset_from_previous_instance; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1158 |
column->ContentMaxXHeadersUsed += offset_from_previous_instance; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1159 |
column->ContentMaxXHeadersIdeal += offset_from_previous_instance; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1160 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1161 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1162 |
// Don't decrement auto-fit counters until container window got a chance to submit its items |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1163 |
if (table->HostSkipItems == false && table->InstanceCurrent == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1164 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1165 |
column->AutoFitQueue >>= 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1166 |
column->CannotSkipItemsQueue >>= 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1167 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1168 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1169 |
if (visible_n < table->FreezeColumnsCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1170 |
host_clip_rect.Min.x = ImClamp(column->MaxX + TABLE_BORDER_SIZE, host_clip_rect.Min.x, host_clip_rect.Max.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1171 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1172 |
offset_x += column->WidthGiven + table->CellSpacingX1 + table->CellSpacingX2 + table->CellPaddingX * 2.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1173 |
visible_n++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1174 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1175 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1176 |
// In case the table is visible (e.g. decorations) but all columns clipped, we keep a column visible. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1177 |
// Else if give no chance to a clipper-savy user to submit rows and therefore total contents height used by scrollbar. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1178 |
if (has_at_least_one_column_requesting_output == false) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1179 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1180 |
table->Columns[table->LeftMostEnabledColumn].IsRequestOutput = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1181 |
table->Columns[table->LeftMostEnabledColumn].IsSkipItems = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1182 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1183 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1184 |
// [Part 7] Detect/store when we are hovering the unused space after the right-most column (so e.g. context menus can react on it) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1185 |
// Clear Resizable flag if none of our column are actually resizable (either via an explicit _NoResize flag, either |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1186 |
// because of using _WidthAuto/_WidthStretch). This will hide the resizing option from the context menu. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1187 |
const float unused_x1 = ImMax(table->WorkRect.Min.x, table->Columns[table->RightMostEnabledColumn].ClipRect.Max.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1188 |
if (is_hovering_table && table->HoveredColumnBody == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1189 |
if (mouse_skewed_x >= unused_x1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1190 |
table->HoveredColumnBody = (ImGuiTableColumnIdx)table->ColumnsCount; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1191 |
if (has_resizable == false && (table->Flags & ImGuiTableFlags_Resizable)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1192 |
table->Flags &= ~ImGuiTableFlags_Resizable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1193 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1194 |
table->IsActiveIdAliveBeforeTable = (g.ActiveIdIsAlive != 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1195 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1196 |
// [Part 8] Lock actual OuterRect/WorkRect right-most position. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1197 |
// This is done late to handle the case of fixed-columns tables not claiming more widths that they need. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1198 |
// Because of this we are careful with uses of WorkRect and InnerClipRect before this point. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1199 |
if (table->RightMostStretchedColumn != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1200 |
table->Flags &= ~ImGuiTableFlags_NoHostExtendX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1201 |
if (table->Flags & ImGuiTableFlags_NoHostExtendX) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1202 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1203 |
table->OuterRect.Max.x = table->WorkRect.Max.x = unused_x1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1204 |
table->InnerClipRect.Max.x = ImMin(table->InnerClipRect.Max.x, unused_x1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1205 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1206 |
table->InnerWindow->ParentWorkRect = table->WorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1207 |
table->BorderX1 = table->InnerClipRect.Min.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1208 |
table->BorderX2 = table->InnerClipRect.Max.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1209 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1210 |
// Setup window's WorkRect.Max.y for GetContentRegionAvail(). Other values will be updated in each TableBeginCell() call. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1211 |
float window_content_max_y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1212 |
if (table->Flags & ImGuiTableFlags_NoHostExtendY) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1213 |
window_content_max_y = table->OuterRect.Max.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1214 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1215 |
window_content_max_y = ImMax(table->InnerWindow->ContentRegionRect.Max.y, (table->Flags & ImGuiTableFlags_ScrollY) ? 0.0f : table->OuterRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1216 |
table->InnerWindow->WorkRect.Max.y = ImClamp(window_content_max_y - g.Style.CellPadding.y, table->InnerWindow->WorkRect.Min.y, table->InnerWindow->WorkRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1217 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1218 |
// [Part 9] Allocate draw channels and setup background cliprect |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1219 |
TableSetupDrawChannels(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1220 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1221 |
// [Part 10] Hit testing on borders |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1222 |
if (table->Flags & ImGuiTableFlags_Resizable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1223 |
TableUpdateBorders(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1224 |
table_instance->LastTopHeadersRowHeight = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1225 |
table->IsLayoutLocked = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1226 |
table->IsUsingHeaders = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1227 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1228 |
// Highlight header |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1229 |
table->HighlightColumnHeader = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1230 |
if (table->IsContextPopupOpen && table->ContextPopupColumn != -1 && table->InstanceInteracted == table->InstanceCurrent) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1231 |
table->HighlightColumnHeader = table->ContextPopupColumn; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1232 |
else if ((table->Flags & ImGuiTableFlags_HighlightHoveredColumn) && table->HoveredColumnBody != -1 && table->HoveredColumnBody != table->ColumnsCount && table->HoveredColumnBorder == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1233 |
if (g.ActiveId == 0 || (table->IsActiveIdInTable || g.DragDropActive)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1234 |
table->HighlightColumnHeader = table->HoveredColumnBody; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1235 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1236 |
// [Part 11] Default context menu |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1237 |
// - To append to this menu: you can call TableBeginContextMenuPopup()/.../EndPopup(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1238 |
// - To modify or replace this: set table->IsContextPopupNoDefaultContents = true, then call TableBeginContextMenuPopup()/.../EndPopup(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1239 |
// - You may call TableDrawDefaultContextMenu() with selected flags to display specific sections of the default menu, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1240 |
// e.g. TableDrawDefaultContextMenu(table, table->Flags & ~ImGuiTableFlags_Hideable) will display everything EXCEPT columns visibility options. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1241 |
if (table->DisableDefaultContextMenu == false && TableBeginContextMenuPopup(table)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1242 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1243 |
TableDrawDefaultContextMenu(table, table->Flags); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1244 |
EndPopup(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1245 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1246 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1247 |
// [Part 12] Sanitize and build sort specs before we have a chance to use them for display. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1248 |
// This path will only be exercised when sort specs are modified before header rows (e.g. init or visibility change) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1249 |
if (table->IsSortSpecsDirty && (table->Flags & ImGuiTableFlags_Sortable)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1250 |
TableSortSpecsBuild(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1251 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1252 |
// [Part 13] Setup inner window decoration size (for scrolling / nav tracking to properly take account of frozen rows/columns) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1253 |
if (table->FreezeColumnsRequest > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1254 |
table->InnerWindow->DecoInnerSizeX1 = table->Columns[table->DisplayOrderToIndex[table->FreezeColumnsRequest - 1]].MaxX - table->OuterRect.Min.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1255 |
if (table->FreezeRowsRequest > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1256 |
table->InnerWindow->DecoInnerSizeY1 = table_instance->LastFrozenHeight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1257 |
table_instance->LastFrozenHeight = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1258 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1259 |
// Initial state |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1260 |
ImGuiWindow* inner_window = table->InnerWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1261 |
if (table->Flags & ImGuiTableFlags_NoClip) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1262 |
table->DrawSplitter->SetCurrentChannel(inner_window->DrawList, TABLE_DRAW_CHANNEL_NOCLIP); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1263 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1264 |
inner_window->DrawList->PushClipRect(inner_window->InnerClipRect.Min, inner_window->InnerClipRect.Max, false); // FIXME: use table->InnerClipRect? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1265 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1266 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1267 |
// Process hit-testing on resizing borders. Actual size change will be applied in EndTable() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1268 |
// - Set table->HoveredColumnBorder with a short delay/timer to reduce visual feedback noise. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1269 |
void ImGui::TableUpdateBorders(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1270 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1271 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1272 |
IM_ASSERT(table->Flags & ImGuiTableFlags_Resizable); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1273 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1274 |
// At this point OuterRect height may be zero or under actual final height, so we rely on temporal coherency and |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1275 |
// use the final height from last frame. Because this is only affecting _interaction_ with columns, it is not |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1276 |
// really problematic (whereas the actual visual will be displayed in EndTable() and using the current frame height). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1277 |
// Actual columns highlight/render will be performed in EndTable() and not be affected. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1278 |
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1279 |
const float hit_half_width = ImTrunc(TABLE_RESIZE_SEPARATOR_HALF_THICKNESS * g.CurrentDpiScale); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1280 |
const float hit_y1 = (table->FreezeRowsCount >= 1 ? table->OuterRect.Min.y : table->WorkRect.Min.y) + table->AngledHeadersHeight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1281 |
const float hit_y2_body = ImMax(table->OuterRect.Max.y, hit_y1 + table_instance->LastOuterHeight - table->AngledHeadersHeight); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1282 |
const float hit_y2_head = hit_y1 + table_instance->LastTopHeadersRowHeight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1283 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1284 |
for (int order_n = 0; order_n < table->ColumnsCount; order_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1285 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1286 |
if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1287 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1288 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1289 |
const int column_n = table->DisplayOrderToIndex[order_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1290 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1291 |
if (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1292 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1293 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1294 |
// ImGuiTableFlags_NoBordersInBodyUntilResize will be honored in TableDrawBorders() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1295 |
const float border_y2_hit = (table->Flags & ImGuiTableFlags_NoBordersInBody) ? hit_y2_head : hit_y2_body; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1296 |
if ((table->Flags & ImGuiTableFlags_NoBordersInBody) && table->IsUsingHeaders == false) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1297 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1298 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1299 |
if (!column->IsVisibleX && table->LastResizedColumn != column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1300 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1301 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1302 |
ImGuiID column_id = TableGetColumnResizeID(table, column_n, table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1303 |
ImRect hit_rect(column->MaxX - hit_half_width, hit_y1, column->MaxX + hit_half_width, border_y2_hit); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1304 |
ItemAdd(hit_rect, column_id, NULL, ImGuiItemFlags_NoNav); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1305 |
//GetForegroundDrawList()->AddRect(hit_rect.Min, hit_rect.Max, IM_COL32(255, 0, 0, 100)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1306 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1307 |
bool hovered = false, held = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1308 |
bool pressed = ButtonBehavior(hit_rect, column_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_NoNavFocus); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1309 |
if (pressed && IsMouseDoubleClicked(0)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1310 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1311 |
TableSetColumnWidthAutoSingle(table, column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1312 |
ClearActiveID(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1313 |
held = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1314 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1315 |
if (held) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1316 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1317 |
if (table->LastResizedColumn == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1318 |
table->ResizeLockMinContentsX2 = table->RightMostEnabledColumn != -1 ? table->Columns[table->RightMostEnabledColumn].MaxX : -FLT_MAX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1319 |
table->ResizedColumn = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1320 |
table->InstanceInteracted = table->InstanceCurrent; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1321 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1322 |
if ((hovered && g.HoveredIdTimer > TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER) || held) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1323 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1324 |
table->HoveredColumnBorder = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1325 |
SetMouseCursor(ImGuiMouseCursor_ResizeEW); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1326 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1327 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1328 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1329 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1330 |
void ImGui::EndTable() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1331 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1332 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1333 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1334 |
IM_ASSERT(table != NULL && "Only call EndTable() if BeginTable() returns true!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1335 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1336 |
// This assert would be very useful to catch a common error... unfortunately it would probably trigger in some |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1337 |
// cases, and for consistency user may sometimes output empty tables (and still benefit from e.g. outer border) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1338 |
//IM_ASSERT(table->IsLayoutLocked && "Table unused: never called TableNextRow(), is that the intent?"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1339 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1340 |
// If the user never got to call TableNextRow() or TableNextColumn(), we call layout ourselves to ensure all our |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1341 |
// code paths are consistent (instead of just hoping that TableBegin/TableEnd will work), get borders drawn, etc. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1342 |
if (!table->IsLayoutLocked) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1343 |
TableUpdateLayout(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1344 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1345 |
const ImGuiTableFlags flags = table->Flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1346 |
ImGuiWindow* inner_window = table->InnerWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1347 |
ImGuiWindow* outer_window = table->OuterWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1348 |
ImGuiTableTempData* temp_data = table->TempData; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1349 |
IM_ASSERT(inner_window == g.CurrentWindow); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1350 |
IM_ASSERT(outer_window == inner_window || outer_window == inner_window->ParentWindow); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1351 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1352 |
if (table->IsInsideRow) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1353 |
TableEndRow(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1354 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1355 |
// Context menu in columns body |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1356 |
if (flags & ImGuiTableFlags_ContextMenuInBody) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1357 |
if (table->HoveredColumnBody != -1 && !IsAnyItemHovered() && IsMouseReleased(ImGuiMouseButton_Right)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1358 |
TableOpenContextMenu((int)table->HoveredColumnBody); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1359 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1360 |
// Finalize table height |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1361 |
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1362 |
inner_window->DC.PrevLineSize = temp_data->HostBackupPrevLineSize; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1363 |
inner_window->DC.CurrLineSize = temp_data->HostBackupCurrLineSize; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1364 |
inner_window->DC.CursorMaxPos = temp_data->HostBackupCursorMaxPos; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1365 |
const float inner_content_max_y = table->RowPosY2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1366 |
IM_ASSERT(table->RowPosY2 == inner_window->DC.CursorPos.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1367 |
if (inner_window != outer_window) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1368 |
inner_window->DC.CursorMaxPos.y = inner_content_max_y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1369 |
else if (!(flags & ImGuiTableFlags_NoHostExtendY)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1370 |
table->OuterRect.Max.y = table->InnerRect.Max.y = ImMax(table->OuterRect.Max.y, inner_content_max_y); // Patch OuterRect/InnerRect height |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1371 |
table->WorkRect.Max.y = ImMax(table->WorkRect.Max.y, table->OuterRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1372 |
table_instance->LastOuterHeight = table->OuterRect.GetHeight(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1373 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1374 |
// Setup inner scrolling range |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1375 |
// FIXME: This ideally should be done earlier, in BeginTable() SetNextWindowContentSize call, just like writing to inner_window->DC.CursorMaxPos.y, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1376 |
// but since the later is likely to be impossible to do we'd rather update both axises together. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1377 |
if (table->Flags & ImGuiTableFlags_ScrollX) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1378 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1379 |
const float outer_padding_for_border = (table->Flags & ImGuiTableFlags_BordersOuterV) ? TABLE_BORDER_SIZE : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1380 |
float max_pos_x = table->InnerWindow->DC.CursorMaxPos.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1381 |
if (table->RightMostEnabledColumn != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1382 |
max_pos_x = ImMax(max_pos_x, table->Columns[table->RightMostEnabledColumn].WorkMaxX + table->CellPaddingX + table->OuterPaddingX - outer_padding_for_border); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1383 |
if (table->ResizedColumn != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1384 |
max_pos_x = ImMax(max_pos_x, table->ResizeLockMinContentsX2); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1385 |
table->InnerWindow->DC.CursorMaxPos.x = max_pos_x + table->TempData->AngledHeadersExtraWidth; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1386 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1387 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1388 |
// Pop clipping rect |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1389 |
if (!(flags & ImGuiTableFlags_NoClip)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1390 |
inner_window->DrawList->PopClipRect(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1391 |
inner_window->ClipRect = inner_window->DrawList->_ClipRectStack.back(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1392 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1393 |
// Draw borders |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1394 |
if ((flags & ImGuiTableFlags_Borders) != 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1395 |
TableDrawBorders(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1396 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1397 |
#if 0 |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1398 |
// Strip out dummy channel draw calls |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1399 |
// We have no way to prevent user submitting direct ImDrawList calls into a hidden column (but ImGui:: calls will be clipped out) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1400 |
// Pros: remove draw calls which will have no effect. since they'll have zero-size cliprect they may be early out anyway. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1401 |
// Cons: making it harder for users watching metrics/debugger to spot the wasted vertices. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1402 |
if (table->DummyDrawChannel != (ImGuiTableColumnIdx)-1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1403 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1404 |
ImDrawChannel* dummy_channel = &table->DrawSplitter._Channels[table->DummyDrawChannel]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1405 |
dummy_channel->_CmdBuffer.resize(0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1406 |
dummy_channel->_IdxBuffer.resize(0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1407 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1408 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1409 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1410 |
// Flatten channels and merge draw calls |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1411 |
ImDrawListSplitter* splitter = table->DrawSplitter; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1412 |
splitter->SetCurrentChannel(inner_window->DrawList, 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1413 |
if ((table->Flags & ImGuiTableFlags_NoClip) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1414 |
TableMergeDrawChannels(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1415 |
splitter->Merge(inner_window->DrawList); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1416 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1417 |
// Update ColumnsAutoFitWidth to get us ahead for host using our size to auto-resize without waiting for next BeginTable() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1418 |
float auto_fit_width_for_fixed = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1419 |
float auto_fit_width_for_stretched = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1420 |
float auto_fit_width_for_stretched_min = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1421 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1422 |
if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1423 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1424 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1425 |
float column_width_request = ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !(column->Flags & ImGuiTableColumnFlags_NoResize)) ? column->WidthRequest : TableGetColumnWidthAuto(table, column); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1426 |
if (column->Flags & ImGuiTableColumnFlags_WidthFixed) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1427 |
auto_fit_width_for_fixed += column_width_request; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1428 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1429 |
auto_fit_width_for_stretched += column_width_request; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1430 |
if ((column->Flags & ImGuiTableColumnFlags_WidthStretch) && (column->Flags & ImGuiTableColumnFlags_NoResize) != 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1431 |
auto_fit_width_for_stretched_min = ImMax(auto_fit_width_for_stretched_min, column_width_request / (column->StretchWeight / table->ColumnsStretchSumWeights)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1432 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1433 |
const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1434 |
table->ColumnsAutoFitWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount + auto_fit_width_for_fixed + ImMax(auto_fit_width_for_stretched, auto_fit_width_for_stretched_min); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1435 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1436 |
// Update scroll |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1437 |
if ((table->Flags & ImGuiTableFlags_ScrollX) == 0 && inner_window != outer_window) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1438 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1439 |
inner_window->Scroll.x = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1440 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1441 |
else if (table->LastResizedColumn != -1 && table->ResizedColumn == -1 && inner_window->ScrollbarX && table->InstanceInteracted == table->InstanceCurrent) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1442 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1443 |
// When releasing a column being resized, scroll to keep the resulting column in sight |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1444 |
const float neighbor_width_to_keep_visible = table->MinColumnWidth + table->CellPaddingX * 2.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1445 |
ImGuiTableColumn* column = &table->Columns[table->LastResizedColumn]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1446 |
if (column->MaxX < table->InnerClipRect.Min.x) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1447 |
SetScrollFromPosX(inner_window, column->MaxX - inner_window->Pos.x - neighbor_width_to_keep_visible, 1.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1448 |
else if (column->MaxX > table->InnerClipRect.Max.x) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1449 |
SetScrollFromPosX(inner_window, column->MaxX - inner_window->Pos.x + neighbor_width_to_keep_visible, 1.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1450 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1451 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1452 |
// Apply resizing/dragging at the end of the frame |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1453 |
if (table->ResizedColumn != -1 && table->InstanceCurrent == table->InstanceInteracted) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1454 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1455 |
ImGuiTableColumn* column = &table->Columns[table->ResizedColumn]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1456 |
const float new_x2 = (g.IO.MousePos.x - g.ActiveIdClickOffset.x + ImTrunc(TABLE_RESIZE_SEPARATOR_HALF_THICKNESS * g.CurrentDpiScale)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1457 |
const float new_width = ImTrunc(new_x2 - column->MinX - table->CellSpacingX1 - table->CellPaddingX * 2.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1458 |
table->ResizedColumnNextWidth = new_width; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1459 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1460 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1461 |
table->IsActiveIdInTable = (g.ActiveIdIsAlive != 0 && table->IsActiveIdAliveBeforeTable == false); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1462 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1463 |
// Pop from id stack |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1464 |
IM_ASSERT_USER_ERROR(inner_window->IDStack.back() == table_instance->TableInstanceID, "Mismatching PushID/PopID!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1465 |
IM_ASSERT_USER_ERROR(outer_window->DC.ItemWidthStack.Size >= temp_data->HostBackupItemWidthStackSize, "Too many PopItemWidth!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1466 |
if (table->InstanceCurrent > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1467 |
PopID(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1468 |
PopID(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1469 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1470 |
// Restore window data that we modified |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1471 |
const ImVec2 backup_outer_max_pos = outer_window->DC.CursorMaxPos; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1472 |
inner_window->WorkRect = temp_data->HostBackupWorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1473 |
inner_window->ParentWorkRect = temp_data->HostBackupParentWorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1474 |
inner_window->SkipItems = table->HostSkipItems; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1475 |
outer_window->DC.CursorPos = table->OuterRect.Min; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1476 |
outer_window->DC.ItemWidth = temp_data->HostBackupItemWidth; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1477 |
outer_window->DC.ItemWidthStack.Size = temp_data->HostBackupItemWidthStackSize; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1478 |
outer_window->DC.ColumnsOffset = temp_data->HostBackupColumnsOffset; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1479 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1480 |
// Layout in outer window |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1481 |
// (FIXME: To allow auto-fit and allow desirable effect of SameLine() we dissociate 'used' vs 'ideal' size by overriding |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1482 |
// CursorPosPrevLine and CursorMaxPos manually. That should be a more general layout feature, see same problem e.g. #3414) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1483 |
if (inner_window != outer_window) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1484 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1485 |
short backup_nav_layers_active_mask = inner_window->DC.NavLayersActiveMask; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1486 |
inner_window->DC.NavLayersActiveMask |= 1 << ImGuiNavLayer_Main; // So empty table don't appear to navigate differently. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1487 |
g.CurrentTable = NULL; // To avoid error recovery recursing |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1488 |
EndChild(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1489 |
g.CurrentTable = table; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1490 |
inner_window->DC.NavLayersActiveMask = backup_nav_layers_active_mask; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1491 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1492 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1493 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1494 |
ItemSize(table->OuterRect.GetSize()); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1495 |
ItemAdd(table->OuterRect, 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1496 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1497 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1498 |
// Override declared contents width/height to enable auto-resize while not needlessly adding a scrollbar |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1499 |
if (table->Flags & ImGuiTableFlags_NoHostExtendX) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1500 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1501 |
// FIXME-TABLE: Could we remove this section? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1502 |
// ColumnsAutoFitWidth may be one frame ahead here since for Fixed+NoResize is calculated from latest contents |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1503 |
IM_ASSERT((table->Flags & ImGuiTableFlags_ScrollX) == 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1504 |
outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, table->OuterRect.Min.x + table->ColumnsAutoFitWidth); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1505 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1506 |
else if (temp_data->UserOuterSize.x <= 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1507 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1508 |
// Some references for this: #7651 + tests "table_reported_size", "table_reported_size_outer" equivalent Y block |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1509 |
// - Checking for ImGuiTableFlags_ScrollX/ScrollY flag makes us a frame ahead when disabling those flags. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1510 |
// - FIXME-TABLE: Would make sense to pre-compute expected scrollbar visibility/sizes to generally save a frame of feedback. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1511 |
const float inner_content_max_x = table->OuterRect.Min.x + table->ColumnsAutoFitWidth; // Slightly misleading name but used for code symmetry with inner_content_max_y |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1512 |
const float decoration_size = table->TempData->AngledHeadersExtraWidth + ((table->Flags & ImGuiTableFlags_ScrollY) ? inner_window->ScrollbarSizes.x : 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1513 |
outer_window->DC.IdealMaxPos.x = ImMax(outer_window->DC.IdealMaxPos.x, inner_content_max_x + decoration_size - temp_data->UserOuterSize.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1514 |
outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, ImMin(table->OuterRect.Max.x, inner_content_max_x + decoration_size)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1515 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1516 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1517 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1518 |
outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, table->OuterRect.Max.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1519 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1520 |
if (temp_data->UserOuterSize.y <= 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1521 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1522 |
const float decoration_size = (table->Flags & ImGuiTableFlags_ScrollX) ? inner_window->ScrollbarSizes.y : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1523 |
outer_window->DC.IdealMaxPos.y = ImMax(outer_window->DC.IdealMaxPos.y, inner_content_max_y + decoration_size - temp_data->UserOuterSize.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1524 |
outer_window->DC.CursorMaxPos.y = ImMax(backup_outer_max_pos.y, ImMin(table->OuterRect.Max.y, inner_content_max_y + decoration_size)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1525 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1526 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1527 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1528 |
// OuterRect.Max.y may already have been pushed downward from the initial value (unless ImGuiTableFlags_NoHostExtendY is set) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1529 |
outer_window->DC.CursorMaxPos.y = ImMax(backup_outer_max_pos.y, table->OuterRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1530 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1531 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1532 |
// Save settings |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1533 |
if (table->IsSettingsDirty) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1534 |
TableSaveSettings(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1535 |
table->IsInitializing = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1536 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1537 |
// Clear or restore current table, if any |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1538 |
IM_ASSERT(g.CurrentWindow == outer_window && g.CurrentTable == table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1539 |
IM_ASSERT(g.TablesTempDataStacked > 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1540 |
temp_data = (--g.TablesTempDataStacked > 0) ? &g.TablesTempData[g.TablesTempDataStacked - 1] : NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1541 |
g.CurrentTable = temp_data ? g.Tables.GetByIndex(temp_data->TableIndex) : NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1542 |
if (g.CurrentTable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1543 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1544 |
g.CurrentTable->TempData = temp_data; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1545 |
g.CurrentTable->DrawSplitter = &temp_data->DrawSplitter; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1546 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1547 |
outer_window->DC.CurrentTableIdx = g.CurrentTable ? g.Tables.GetIndex(g.CurrentTable) : -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1548 |
NavUpdateCurrentWindowIsScrollPushableX(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1549 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1550 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1551 |
// See "COLUMNS SIZING POLICIES" comments at the top of this file |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1552 |
// If (init_width_or_weight <= 0.0f) it is ignored |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1553 |
void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags, float init_width_or_weight, ImGuiID user_id) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1554 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1555 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1556 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1557 |
IM_ASSERT(table != NULL && "Need to call TableSetupColumn() after BeginTable()!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1558 |
IM_ASSERT(table->IsLayoutLocked == false && "Need to call call TableSetupColumn() before first row!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1559 |
IM_ASSERT((flags & ImGuiTableColumnFlags_StatusMask_) == 0 && "Illegal to pass StatusMask values to TableSetupColumn()"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1560 |
if (table->DeclColumnsCount >= table->ColumnsCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1561 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1562 |
IM_ASSERT_USER_ERROR(table->DeclColumnsCount < table->ColumnsCount, "Called TableSetupColumn() too many times!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1563 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1564 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1565 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1566 |
ImGuiTableColumn* column = &table->Columns[table->DeclColumnsCount]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1567 |
table->DeclColumnsCount++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1568 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1569 |
// Assert when passing a width or weight if policy is entirely left to default, to avoid storing width into weight and vice-versa. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1570 |
// Give a grace to users of ImGuiTableFlags_ScrollX. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1571 |
if (table->IsDefaultSizingPolicy && (flags & ImGuiTableColumnFlags_WidthMask_) == 0 && (flags & ImGuiTableFlags_ScrollX) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1572 |
IM_ASSERT(init_width_or_weight <= 0.0f && "Can only specify width/weight if sizing policy is set explicitly in either Table or Column."); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1573 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1574 |
// When passing a width automatically enforce WidthFixed policy |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1575 |
// (whereas TableSetupColumnFlags would default to WidthAuto if table is not Resizable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1576 |
if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0 && init_width_or_weight > 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1577 |
if ((table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedFit || (table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedSame) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1578 |
flags |= ImGuiTableColumnFlags_WidthFixed; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1579 |
if (flags & ImGuiTableColumnFlags_AngledHeader) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1580 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1581 |
flags |= ImGuiTableColumnFlags_NoHeaderLabel; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1582 |
table->AngledHeadersCount++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1583 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1584 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1585 |
TableSetupColumnFlags(table, column, flags); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1586 |
column->UserID = user_id; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1587 |
flags = column->Flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1588 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1589 |
// Initialize defaults |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1590 |
column->InitStretchWeightOrWidth = init_width_or_weight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1591 |
if (table->IsInitializing) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1592 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1593 |
// Init width or weight |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1594 |
if (column->WidthRequest < 0.0f && column->StretchWeight < 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1595 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1596 |
if ((flags & ImGuiTableColumnFlags_WidthFixed) && init_width_or_weight > 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1597 |
column->WidthRequest = init_width_or_weight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1598 |
if (flags & ImGuiTableColumnFlags_WidthStretch) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1599 |
column->StretchWeight = (init_width_or_weight > 0.0f) ? init_width_or_weight : -1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1600 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1601 |
// Disable auto-fit if an explicit width/weight has been specified |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1602 |
if (init_width_or_weight > 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1603 |
column->AutoFitQueue = 0x00; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1604 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1605 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1606 |
// Init default visibility/sort state |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1607 |
if ((flags & ImGuiTableColumnFlags_DefaultHide) && (table->SettingsLoadedFlags & ImGuiTableFlags_Hideable) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1608 |
column->IsUserEnabled = column->IsUserEnabledNextFrame = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1609 |
if (flags & ImGuiTableColumnFlags_DefaultSort && (table->SettingsLoadedFlags & ImGuiTableFlags_Sortable) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1610 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1611 |
column->SortOrder = 0; // Multiple columns using _DefaultSort will be reassigned unique SortOrder values when building the sort specs. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1612 |
column->SortDirection = (column->Flags & ImGuiTableColumnFlags_PreferSortDescending) ? (ImS8)ImGuiSortDirection_Descending : (ImU8)(ImGuiSortDirection_Ascending); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1613 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1614 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1615 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1616 |
// Store name (append with zero-terminator in contiguous buffer) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1617 |
// FIXME: If we recorded the number of \n in names we could compute header row height |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1618 |
column->NameOffset = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1619 |
if (label != NULL && label[0] != 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1620 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1621 |
column->NameOffset = (ImS16)table->ColumnsNames.size(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1622 |
table->ColumnsNames.append(label, label + strlen(label) + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1623 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1624 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1625 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1626 |
// [Public] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1627 |
void ImGui::TableSetupScrollFreeze(int columns, int rows) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1628 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1629 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1630 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1631 |
IM_ASSERT(table != NULL && "Need to call TableSetupColumn() after BeginTable()!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1632 |
IM_ASSERT(table->IsLayoutLocked == false && "Need to call TableSetupColumn() before first row!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1633 |
IM_ASSERT(columns >= 0 && columns < IMGUI_TABLE_MAX_COLUMNS); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1634 |
IM_ASSERT(rows >= 0 && rows < 128); // Arbitrary limit |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1635 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1636 |
table->FreezeColumnsRequest = (table->Flags & ImGuiTableFlags_ScrollX) ? (ImGuiTableColumnIdx)ImMin(columns, table->ColumnsCount) : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1637 |
table->FreezeColumnsCount = (table->InnerWindow->Scroll.x != 0.0f) ? table->FreezeColumnsRequest : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1638 |
table->FreezeRowsRequest = (table->Flags & ImGuiTableFlags_ScrollY) ? (ImGuiTableColumnIdx)rows : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1639 |
table->FreezeRowsCount = (table->InnerWindow->Scroll.y != 0.0f) ? table->FreezeRowsRequest : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1640 |
table->IsUnfrozenRows = (table->FreezeRowsCount == 0); // Make sure this is set before TableUpdateLayout() so ImGuiListClipper can benefit from it.b |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1641 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1642 |
// Ensure frozen columns are ordered in their section. We still allow multiple frozen columns to be reordered. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1643 |
// FIXME-TABLE: This work for preserving 2143 into 21|43. How about 4321 turning into 21|43? (preserve relative order in each section) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1644 |
for (int column_n = 0; column_n < table->FreezeColumnsRequest; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1645 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1646 |
int order_n = table->DisplayOrderToIndex[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1647 |
if (order_n != column_n && order_n >= table->FreezeColumnsRequest) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1648 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1649 |
ImSwap(table->Columns[table->DisplayOrderToIndex[order_n]].DisplayOrder, table->Columns[table->DisplayOrderToIndex[column_n]].DisplayOrder); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1650 |
ImSwap(table->DisplayOrderToIndex[order_n], table->DisplayOrderToIndex[column_n]); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1651 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1652 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1653 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1654 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1655 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1656 |
// [SECTION] Tables: Simple accessors |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1657 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1658 |
// - TableGetColumnCount() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1659 |
// - TableGetColumnName() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1660 |
// - TableGetColumnName() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1661 |
// - TableSetColumnEnabled() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1662 |
// - TableGetColumnFlags() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1663 |
// - TableGetCellBgRect() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1664 |
// - TableGetColumnResizeID() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1665 |
// - TableGetHoveredColumn() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1666 |
// - TableGetHoveredRow() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1667 |
// - TableSetBgColor() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1668 |
//----------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1669 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1670 |
int ImGui::TableGetColumnCount() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1671 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1672 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1673 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1674 |
return table ? table->ColumnsCount : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1675 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1676 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1677 |
const char* ImGui::TableGetColumnName(int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1678 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1679 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1680 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1681 |
if (!table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1682 |
return NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1683 |
if (column_n < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1684 |
column_n = table->CurrentColumn; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1685 |
return TableGetColumnName(table, column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1686 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1687 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1688 |
const char* ImGui::TableGetColumnName(const ImGuiTable* table, int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1689 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1690 |
if (table->IsLayoutLocked == false && column_n >= table->DeclColumnsCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1691 |
return ""; // NameOffset is invalid at this point |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1692 |
const ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1693 |
if (column->NameOffset == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1694 |
return ""; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1695 |
return &table->ColumnsNames.Buf[column->NameOffset]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1696 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1697 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1698 |
// Change user accessible enabled/disabled state of a column (often perceived as "showing/hiding" from users point of view) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1699 |
// Note that end-user can use the context menu to change this themselves (right-click in headers, or right-click in columns body with ImGuiTableFlags_ContextMenuInBody) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1700 |
// - Require table to have the ImGuiTableFlags_Hideable flag because we are manipulating user accessible state. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1701 |
// - Request will be applied during next layout, which happens on the first call to TableNextRow() after BeginTable(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1702 |
// - For the getter you can test (TableGetColumnFlags() & ImGuiTableColumnFlags_IsEnabled) != 0. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1703 |
// - Alternative: the ImGuiTableColumnFlags_Disabled is an overriding/master disable flag which will also hide the column from context menu. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1704 |
void ImGui::TableSetColumnEnabled(int column_n, bool enabled) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1705 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1706 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1707 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1708 |
IM_ASSERT(table != NULL); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1709 |
if (!table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1710 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1711 |
IM_ASSERT(table->Flags & ImGuiTableFlags_Hideable); // See comments above |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1712 |
if (column_n < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1713 |
column_n = table->CurrentColumn; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1714 |
IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1715 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1716 |
column->IsUserEnabledNextFrame = enabled; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1717 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1718 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1719 |
// We allow querying for an extra column in order to poll the IsHovered state of the right-most section |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1720 |
ImGuiTableColumnFlags ImGui::TableGetColumnFlags(int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1721 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1722 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1723 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1724 |
if (!table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1725 |
return ImGuiTableColumnFlags_None; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1726 |
if (column_n < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1727 |
column_n = table->CurrentColumn; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1728 |
if (column_n == table->ColumnsCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1729 |
return (table->HoveredColumnBody == column_n) ? ImGuiTableColumnFlags_IsHovered : ImGuiTableColumnFlags_None; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1730 |
return table->Columns[column_n].Flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1731 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1732 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1733 |
// Return the cell rectangle based on currently known height. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1734 |
// - Important: we generally don't know our row height until the end of the row, so Max.y will be incorrect in many situations. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1735 |
// The only case where this is correct is if we provided a min_row_height to TableNextRow() and don't go below it, or in TableEndRow() when we locked that height. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1736 |
// - Important: if ImGuiTableFlags_PadOuterX is set but ImGuiTableFlags_PadInnerX is not set, the outer-most left and right |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1737 |
// columns report a small offset so their CellBgRect can extend up to the outer border. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1738 |
// FIXME: But the rendering code in TableEndRow() nullifies that with clamping required for scrolling. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1739 |
ImRect ImGui::TableGetCellBgRect(const ImGuiTable* table, int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1740 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1741 |
const ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1742 |
float x1 = column->MinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1743 |
float x2 = column->MaxX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1744 |
//if (column->PrevEnabledColumn == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1745 |
// x1 -= table->OuterPaddingX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1746 |
//if (column->NextEnabledColumn == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1747 |
// x2 += table->OuterPaddingX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1748 |
x1 = ImMax(x1, table->WorkRect.Min.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1749 |
x2 = ImMin(x2, table->WorkRect.Max.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1750 |
return ImRect(x1, table->RowPosY1, x2, table->RowPosY2); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1751 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1752 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1753 |
// Return the resizing ID for the right-side of the given column. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1754 |
ImGuiID ImGui::TableGetColumnResizeID(ImGuiTable* table, int column_n, int instance_no) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1755 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1756 |
IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1757 |
ImGuiID instance_id = TableGetInstanceID(table, instance_no); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1758 |
return instance_id + 1 + column_n; // FIXME: #6140: still not ideal |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1759 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1760 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1761 |
// Return -1 when table is not hovered. return columns_count if hovering the unused space at the right of the right-most visible column. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1762 |
int ImGui::TableGetHoveredColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1763 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1764 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1765 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1766 |
if (!table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1767 |
return -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1768 |
return (int)table->HoveredColumnBody; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1769 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1770 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1771 |
// Return -1 when table is not hovered. Return maxrow+1 if in table but below last submitted row. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1772 |
// *IMPORTANT* Unlike TableGetHoveredColumn(), this has a one frame latency in updating the value. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1773 |
// This difference with is the reason why this is not public yet. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1774 |
int ImGui::TableGetHoveredRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1775 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1776 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1777 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1778 |
if (!table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1779 |
return -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1780 |
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1781 |
return (int)table_instance->HoveredRowLast; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1782 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1783 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1784 |
void ImGui::TableSetBgColor(ImGuiTableBgTarget target, ImU32 color, int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1785 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1786 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1787 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1788 |
IM_ASSERT(target != ImGuiTableBgTarget_None); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1789 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1790 |
if (color == IM_COL32_DISABLE) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1791 |
color = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1792 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1793 |
// We cannot draw neither the cell or row background immediately as we don't know the row height at this point in time. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1794 |
switch (target) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1795 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1796 |
case ImGuiTableBgTarget_CellBg: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1797 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1798 |
if (table->RowPosY1 > table->InnerClipRect.Max.y) // Discard |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1799 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1800 |
if (column_n == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1801 |
column_n = table->CurrentColumn; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1802 |
if (!IM_BITARRAY_TESTBIT(table->VisibleMaskByIndex, column_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1803 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1804 |
if (table->RowCellDataCurrent < 0 || table->RowCellData[table->RowCellDataCurrent].Column != column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1805 |
table->RowCellDataCurrent++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1806 |
ImGuiTableCellData* cell_data = &table->RowCellData[table->RowCellDataCurrent]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1807 |
cell_data->BgColor = color; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1808 |
cell_data->Column = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1809 |
break; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1810 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1811 |
case ImGuiTableBgTarget_RowBg0: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1812 |
case ImGuiTableBgTarget_RowBg1: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1813 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1814 |
if (table->RowPosY1 > table->InnerClipRect.Max.y) // Discard |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1815 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1816 |
IM_ASSERT(column_n == -1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1817 |
int bg_idx = (target == ImGuiTableBgTarget_RowBg1) ? 1 : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1818 |
table->RowBgColor[bg_idx] = color; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1819 |
break; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1820 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1821 |
default: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1822 |
IM_ASSERT(0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1823 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1824 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1825 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1826 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1827 |
// [SECTION] Tables: Row changes |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1828 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1829 |
// - TableGetRowIndex() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1830 |
// - TableNextRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1831 |
// - TableBeginRow() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1832 |
// - TableEndRow() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1833 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1834 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1835 |
// [Public] Note: for row coloring we use ->RowBgColorCounter which is the same value without counting header rows |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1836 |
int ImGui::TableGetRowIndex() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1837 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1838 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1839 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1840 |
if (!table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1841 |
return 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1842 |
return table->CurrentRow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1843 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1844 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1845 |
// [Public] Starts into the first cell of a new row |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1846 |
void ImGui::TableNextRow(ImGuiTableRowFlags row_flags, float row_min_height) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1847 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1848 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1849 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1850 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1851 |
if (!table->IsLayoutLocked) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1852 |
TableUpdateLayout(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1853 |
if (table->IsInsideRow) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1854 |
TableEndRow(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1855 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1856 |
table->LastRowFlags = table->RowFlags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1857 |
table->RowFlags = row_flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1858 |
table->RowCellPaddingY = g.Style.CellPadding.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1859 |
table->RowMinHeight = row_min_height; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1860 |
TableBeginRow(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1861 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1862 |
// We honor min_row_height requested by user, but cannot guarantee per-row maximum height, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1863 |
// because that would essentially require a unique clipping rectangle per-cell. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1864 |
table->RowPosY2 += table->RowCellPaddingY * 2.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1865 |
table->RowPosY2 = ImMax(table->RowPosY2, table->RowPosY1 + row_min_height); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1866 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1867 |
// Disable output until user calls TableNextColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1868 |
table->InnerWindow->SkipItems = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1869 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1870 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1871 |
// [Internal] Only called by TableNextRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1872 |
void ImGui::TableBeginRow(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1873 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1874 |
ImGuiWindow* window = table->InnerWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1875 |
IM_ASSERT(!table->IsInsideRow); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1876 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1877 |
// New row |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1878 |
table->CurrentRow++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1879 |
table->CurrentColumn = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1880 |
table->RowBgColor[0] = table->RowBgColor[1] = IM_COL32_DISABLE; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1881 |
table->RowCellDataCurrent = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1882 |
table->IsInsideRow = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1883 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1884 |
// Begin frozen rows |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1885 |
float next_y1 = table->RowPosY2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1886 |
if (table->CurrentRow == 0 && table->FreezeRowsCount > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1887 |
next_y1 = window->DC.CursorPos.y = table->OuterRect.Min.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1888 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1889 |
table->RowPosY1 = table->RowPosY2 = next_y1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1890 |
table->RowTextBaseline = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1891 |
table->RowIndentOffsetX = window->DC.Indent.x - table->HostIndentX; // Lock indent |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1892 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1893 |
window->DC.PrevLineTextBaseOffset = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1894 |
window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + table->RowCellPaddingY); // This allows users to call SameLine() to share LineSize between columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1895 |
window->DC.PrevLineSize = window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); // This allows users to call SameLine() to share LineSize between columns, and to call it from first column too. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1896 |
window->DC.IsSameLine = window->DC.IsSetPos = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1897 |
window->DC.CursorMaxPos.y = next_y1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1898 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1899 |
// Making the header BG color non-transparent will allow us to overlay it multiple times when handling smooth dragging. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1900 |
if (table->RowFlags & ImGuiTableRowFlags_Headers) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1901 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1902 |
TableSetBgColor(ImGuiTableBgTarget_RowBg0, GetColorU32(ImGuiCol_TableHeaderBg)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1903 |
if (table->CurrentRow == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1904 |
table->IsUsingHeaders = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1905 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1906 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1907 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1908 |
// [Internal] Called by TableNextRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1909 |
void ImGui::TableEndRow(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1910 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1911 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1912 |
ImGuiWindow* window = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1913 |
IM_ASSERT(window == table->InnerWindow); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1914 |
IM_ASSERT(table->IsInsideRow); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1915 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1916 |
if (table->CurrentColumn != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1917 |
TableEndCell(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1918 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1919 |
// Logging |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1920 |
if (g.LogEnabled) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1921 |
LogRenderedText(NULL, "|"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1922 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1923 |
// Position cursor at the bottom of our row so it can be used for e.g. clipping calculation. However it is |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1924 |
// likely that the next call to TableBeginCell() will reposition the cursor to take account of vertical padding. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1925 |
window->DC.CursorPos.y = table->RowPosY2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1926 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1927 |
// Row background fill |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1928 |
const float bg_y1 = table->RowPosY1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1929 |
const float bg_y2 = table->RowPosY2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1930 |
const bool unfreeze_rows_actual = (table->CurrentRow + 1 == table->FreezeRowsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1931 |
const bool unfreeze_rows_request = (table->CurrentRow + 1 == table->FreezeRowsRequest); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1932 |
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1933 |
if ((table->RowFlags & ImGuiTableRowFlags_Headers) && (table->CurrentRow == 0 || (table->LastRowFlags & ImGuiTableRowFlags_Headers))) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1934 |
table_instance->LastTopHeadersRowHeight += bg_y2 - bg_y1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1935 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1936 |
const bool is_visible = (bg_y2 >= table->InnerClipRect.Min.y && bg_y1 <= table->InnerClipRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1937 |
if (is_visible) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1938 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1939 |
// Update data for TableGetHoveredRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1940 |
if (table->HoveredColumnBody != -1 && g.IO.MousePos.y >= bg_y1 && g.IO.MousePos.y < bg_y2 && table_instance->HoveredRowNext < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1941 |
table_instance->HoveredRowNext = table->CurrentRow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1942 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1943 |
// Decide of background color for the row |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1944 |
ImU32 bg_col0 = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1945 |
ImU32 bg_col1 = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1946 |
if (table->RowBgColor[0] != IM_COL32_DISABLE) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1947 |
bg_col0 = table->RowBgColor[0]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1948 |
else if (table->Flags & ImGuiTableFlags_RowBg) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1949 |
bg_col0 = GetColorU32((table->RowBgColorCounter & 1) ? ImGuiCol_TableRowBgAlt : ImGuiCol_TableRowBg); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1950 |
if (table->RowBgColor[1] != IM_COL32_DISABLE) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1951 |
bg_col1 = table->RowBgColor[1]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1952 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1953 |
// Decide of top border color |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1954 |
ImU32 top_border_col = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1955 |
const float border_size = TABLE_BORDER_SIZE; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1956 |
if (table->CurrentRow > 0 && (table->Flags & ImGuiTableFlags_BordersInnerH)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1957 |
top_border_col = (table->LastRowFlags & ImGuiTableRowFlags_Headers) ? table->BorderColorStrong : table->BorderColorLight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1958 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1959 |
const bool draw_cell_bg_color = table->RowCellDataCurrent >= 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1960 |
const bool draw_strong_bottom_border = unfreeze_rows_actual; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1961 |
if ((bg_col0 | bg_col1 | top_border_col) != 0 || draw_strong_bottom_border || draw_cell_bg_color) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1962 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1963 |
// In theory we could call SetWindowClipRectBeforeSetChannel() but since we know TableEndRow() is |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1964 |
// always followed by a change of clipping rectangle we perform the smallest overwrite possible here. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1965 |
if ((table->Flags & ImGuiTableFlags_NoClip) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1966 |
window->DrawList->_CmdHeader.ClipRect = table->Bg0ClipRectForDrawCmd.ToVec4(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1967 |
table->DrawSplitter->SetCurrentChannel(window->DrawList, TABLE_DRAW_CHANNEL_BG0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1968 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1969 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1970 |
// Draw row background |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1971 |
// We soft/cpu clip this so all backgrounds and borders can share the same clipping rectangle |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1972 |
if (bg_col0 || bg_col1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1973 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1974 |
ImRect row_rect(table->WorkRect.Min.x, bg_y1, table->WorkRect.Max.x, bg_y2); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1975 |
row_rect.ClipWith(table->BgClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1976 |
if (bg_col0 != 0 && row_rect.Min.y < row_rect.Max.y) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1977 |
window->DrawList->AddRectFilled(row_rect.Min, row_rect.Max, bg_col0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1978 |
if (bg_col1 != 0 && row_rect.Min.y < row_rect.Max.y) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1979 |
window->DrawList->AddRectFilled(row_rect.Min, row_rect.Max, bg_col1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1980 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1981 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1982 |
// Draw cell background color |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1983 |
if (draw_cell_bg_color) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1984 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1985 |
ImGuiTableCellData* cell_data_end = &table->RowCellData[table->RowCellDataCurrent]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1986 |
for (ImGuiTableCellData* cell_data = &table->RowCellData[0]; cell_data <= cell_data_end; cell_data++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1987 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1988 |
// As we render the BG here we need to clip things (for layout we would not) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1989 |
// FIXME: This cancels the OuterPadding addition done by TableGetCellBgRect(), need to keep it while rendering correctly while scrolling. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1990 |
const ImGuiTableColumn* column = &table->Columns[cell_data->Column]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1991 |
ImRect cell_bg_rect = TableGetCellBgRect(table, cell_data->Column); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1992 |
cell_bg_rect.ClipWith(table->BgClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1993 |
cell_bg_rect.Min.x = ImMax(cell_bg_rect.Min.x, column->ClipRect.Min.x); // So that first column after frozen one gets clipped when scrolling |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1994 |
cell_bg_rect.Max.x = ImMin(cell_bg_rect.Max.x, column->MaxX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1995 |
if (cell_bg_rect.Min.y < cell_bg_rect.Max.y) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1996 |
window->DrawList->AddRectFilled(cell_bg_rect.Min, cell_bg_rect.Max, cell_data->BgColor); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1997 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1998 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
1999 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2000 |
// Draw top border |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2001 |
if (top_border_col && bg_y1 >= table->BgClipRect.Min.y && bg_y1 < table->BgClipRect.Max.y) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2002 |
window->DrawList->AddLine(ImVec2(table->BorderX1, bg_y1), ImVec2(table->BorderX2, bg_y1), top_border_col, border_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2003 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2004 |
// Draw bottom border at the row unfreezing mark (always strong) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2005 |
if (draw_strong_bottom_border && bg_y2 >= table->BgClipRect.Min.y && bg_y2 < table->BgClipRect.Max.y) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2006 |
window->DrawList->AddLine(ImVec2(table->BorderX1, bg_y2), ImVec2(table->BorderX2, bg_y2), table->BorderColorStrong, border_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2007 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2008 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2009 |
// End frozen rows (when we are past the last frozen row line, teleport cursor and alter clipping rectangle) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2010 |
// We need to do that in TableEndRow() instead of TableBeginRow() so the list clipper can mark end of row and |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2011 |
// get the new cursor position. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2012 |
if (unfreeze_rows_request) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2013 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2014 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2015 |
table->Columns[column_n].NavLayerCurrent = ImGuiNavLayer_Main; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2016 |
const float y0 = ImMax(table->RowPosY2 + 1, table->InnerClipRect.Min.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2017 |
table_instance->LastFrozenHeight = y0 - table->OuterRect.Min.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2018 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2019 |
if (unfreeze_rows_actual) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2020 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2021 |
IM_ASSERT(table->IsUnfrozenRows == false); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2022 |
table->IsUnfrozenRows = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2023 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2024 |
// BgClipRect starts as table->InnerClipRect, reduce it now and make BgClipRectForDrawCmd == BgClipRect |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2025 |
table->BgClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y = ImMin(y0, table->InnerClipRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2026 |
table->BgClipRect.Max.y = table->Bg2ClipRectForDrawCmd.Max.y = table->InnerClipRect.Max.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2027 |
table->Bg2DrawChannelCurrent = table->Bg2DrawChannelUnfrozen; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2028 |
IM_ASSERT(table->Bg2ClipRectForDrawCmd.Min.y <= table->Bg2ClipRectForDrawCmd.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2029 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2030 |
float row_height = table->RowPosY2 - table->RowPosY1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2031 |
table->RowPosY2 = window->DC.CursorPos.y = table->WorkRect.Min.y + table->RowPosY2 - table->OuterRect.Min.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2032 |
table->RowPosY1 = table->RowPosY2 - row_height; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2033 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2034 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2035 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2036 |
column->DrawChannelCurrent = column->DrawChannelUnfrozen; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2037 |
column->ClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2038 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2039 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2040 |
// Update cliprect ahead of TableBeginCell() so clipper can access to new ClipRect->Min.y |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2041 |
SetWindowClipRectBeforeSetChannel(window, table->Columns[0].ClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2042 |
table->DrawSplitter->SetCurrentChannel(window->DrawList, table->Columns[0].DrawChannelCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2043 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2044 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2045 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2046 |
if (!(table->RowFlags & ImGuiTableRowFlags_Headers)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2047 |
table->RowBgColorCounter++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2048 |
table->IsInsideRow = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2049 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2050 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2051 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2052 |
// [SECTION] Tables: Columns changes |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2053 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2054 |
// - TableGetColumnIndex() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2055 |
// - TableSetColumnIndex() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2056 |
// - TableNextColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2057 |
// - TableBeginCell() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2058 |
// - TableEndCell() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2059 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2060 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2061 |
int ImGui::TableGetColumnIndex() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2062 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2063 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2064 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2065 |
if (!table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2066 |
return 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2067 |
return table->CurrentColumn; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2068 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2069 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2070 |
// [Public] Append into a specific column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2071 |
bool ImGui::TableSetColumnIndex(int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2072 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2073 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2074 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2075 |
if (!table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2076 |
return false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2077 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2078 |
if (table->CurrentColumn != column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2079 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2080 |
if (table->CurrentColumn != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2081 |
TableEndCell(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2082 |
IM_ASSERT(column_n >= 0 && table->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2083 |
TableBeginCell(table, column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2084 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2085 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2086 |
// Return whether the column is visible. User may choose to skip submitting items based on this return value, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2087 |
// however they shouldn't skip submitting for columns that may have the tallest contribution to row height. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2088 |
return table->Columns[column_n].IsRequestOutput; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2089 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2090 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2091 |
// [Public] Append into the next column, wrap and create a new row when already on last column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2092 |
bool ImGui::TableNextColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2093 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2094 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2095 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2096 |
if (!table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2097 |
return false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2098 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2099 |
if (table->IsInsideRow && table->CurrentColumn + 1 < table->ColumnsCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2100 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2101 |
if (table->CurrentColumn != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2102 |
TableEndCell(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2103 |
TableBeginCell(table, table->CurrentColumn + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2104 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2105 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2106 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2107 |
TableNextRow(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2108 |
TableBeginCell(table, 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2109 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2110 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2111 |
// Return whether the column is visible. User may choose to skip submitting items based on this return value, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2112 |
// however they shouldn't skip submitting for columns that may have the tallest contribution to row height. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2113 |
return table->Columns[table->CurrentColumn].IsRequestOutput; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2114 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2115 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2116 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2117 |
// [Internal] Called by TableSetColumnIndex()/TableNextColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2118 |
// This is called very frequently, so we need to be mindful of unnecessary overhead. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2119 |
// FIXME-TABLE FIXME-OPT: Could probably shortcut some things for non-active or clipped columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2120 |
void ImGui::TableBeginCell(ImGuiTable* table, int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2121 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2122 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2123 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2124 |
ImGuiWindow* window = table->InnerWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2125 |
table->CurrentColumn = column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2126 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2127 |
// Start position is roughly ~~ CellRect.Min + CellPadding + Indent |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2128 |
float start_x = column->WorkMinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2129 |
if (column->Flags & ImGuiTableColumnFlags_IndentEnable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2130 |
start_x += table->RowIndentOffsetX; // ~~ += window.DC.Indent.x - table->HostIndentX, except we locked it for the row. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2131 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2132 |
window->DC.CursorPos.x = start_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2133 |
window->DC.CursorPos.y = table->RowPosY1 + table->RowCellPaddingY; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2134 |
window->DC.CursorMaxPos.x = window->DC.CursorPos.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2135 |
window->DC.ColumnsOffset.x = start_x - window->Pos.x - window->DC.Indent.x; // FIXME-WORKRECT |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2136 |
window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x; // PrevLine.y is preserved. This allows users to call SameLine() to share LineSize between columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2137 |
window->DC.CurrLineTextBaseOffset = table->RowTextBaseline; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2138 |
window->DC.NavLayerCurrent = (ImGuiNavLayer)column->NavLayerCurrent; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2139 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2140 |
// Note how WorkRect.Max.y is only set once during layout |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2141 |
window->WorkRect.Min.y = window->DC.CursorPos.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2142 |
window->WorkRect.Min.x = column->WorkMinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2143 |
window->WorkRect.Max.x = column->WorkMaxX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2144 |
window->DC.ItemWidth = column->ItemWidth; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2145 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2146 |
window->SkipItems = column->IsSkipItems; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2147 |
if (column->IsSkipItems) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2148 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2149 |
g.LastItemData.ID = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2150 |
g.LastItemData.StatusFlags = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2151 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2152 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2153 |
if (table->Flags & ImGuiTableFlags_NoClip) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2154 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2155 |
// FIXME: if we end up drawing all borders/bg in EndTable, could remove this and just assert that channel hasn't changed. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2156 |
table->DrawSplitter->SetCurrentChannel(window->DrawList, TABLE_DRAW_CHANNEL_NOCLIP); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2157 |
//IM_ASSERT(table->DrawSplitter._Current == TABLE_DRAW_CHANNEL_NOCLIP); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2158 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2159 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2160 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2161 |
// FIXME-TABLE: Could avoid this if draw channel is dummy channel? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2162 |
SetWindowClipRectBeforeSetChannel(window, column->ClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2163 |
table->DrawSplitter->SetCurrentChannel(window->DrawList, column->DrawChannelCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2164 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2165 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2166 |
// Logging |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2167 |
if (g.LogEnabled && !column->IsSkipItems) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2168 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2169 |
LogRenderedText(&window->DC.CursorPos, "|"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2170 |
g.LogLinePosY = FLT_MAX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2171 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2172 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2173 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2174 |
// [Internal] Called by TableNextRow()/TableSetColumnIndex()/TableNextColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2175 |
void ImGui::TableEndCell(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2176 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2177 |
ImGuiTableColumn* column = &table->Columns[table->CurrentColumn]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2178 |
ImGuiWindow* window = table->InnerWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2179 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2180 |
if (window->DC.IsSetPos) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2181 |
ErrorCheckUsingSetCursorPosToExtendParentBoundaries(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2182 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2183 |
// Report maximum position so we can infer content size per column. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2184 |
float* p_max_pos_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2185 |
if (table->RowFlags & ImGuiTableRowFlags_Headers) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2186 |
p_max_pos_x = &column->ContentMaxXHeadersUsed; // Useful in case user submit contents in header row that is not a TableHeader() call |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2187 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2188 |
p_max_pos_x = table->IsUnfrozenRows ? &column->ContentMaxXUnfrozen : &column->ContentMaxXFrozen; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2189 |
*p_max_pos_x = ImMax(*p_max_pos_x, window->DC.CursorMaxPos.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2190 |
if (column->IsEnabled) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2191 |
table->RowPosY2 = ImMax(table->RowPosY2, window->DC.CursorMaxPos.y + table->RowCellPaddingY); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2192 |
column->ItemWidth = window->DC.ItemWidth; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2193 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2194 |
// Propagate text baseline for the entire row |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2195 |
// FIXME-TABLE: Here we propagate text baseline from the last line of the cell.. instead of the first one. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2196 |
table->RowTextBaseline = ImMax(table->RowTextBaseline, window->DC.PrevLineTextBaseOffset); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2197 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2198 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2199 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2200 |
// [SECTION] Tables: Columns width management |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2201 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2202 |
// - TableGetMaxColumnWidth() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2203 |
// - TableGetColumnWidthAuto() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2204 |
// - TableSetColumnWidth() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2205 |
// - TableSetColumnWidthAutoSingle() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2206 |
// - TableSetColumnWidthAutoAll() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2207 |
// - TableUpdateColumnsWeightFromWidth() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2208 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2209 |
// Note that actual columns widths are computed in TableUpdateLayout(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2210 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2211 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2212 |
// Maximum column content width given current layout. Use column->MinX so this value differs on a per-column basis. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2213 |
float ImGui::TableCalcMaxColumnWidth(const ImGuiTable* table, int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2214 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2215 |
const ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2216 |
float max_width = FLT_MAX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2217 |
const float min_column_distance = table->MinColumnWidth + table->CellPaddingX * 2.0f + table->CellSpacingX1 + table->CellSpacingX2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2218 |
if (table->Flags & ImGuiTableFlags_ScrollX) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2219 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2220 |
// Frozen columns can't reach beyond visible width else scrolling will naturally break. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2221 |
// (we use DisplayOrder as within a set of multiple frozen column reordering is possible) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2222 |
if (column->DisplayOrder < table->FreezeColumnsRequest) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2223 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2224 |
max_width = (table->InnerClipRect.Max.x - (table->FreezeColumnsRequest - column->DisplayOrder) * min_column_distance) - column->MinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2225 |
max_width = max_width - table->OuterPaddingX - table->CellPaddingX - table->CellSpacingX2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2226 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2227 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2228 |
else if ((table->Flags & ImGuiTableFlags_NoKeepColumnsVisible) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2229 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2230 |
// If horizontal scrolling if disabled, we apply a final lossless shrinking of columns in order to make |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2231 |
// sure they are all visible. Because of this we also know that all of the columns will always fit in |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2232 |
// table->WorkRect and therefore in table->InnerRect (because ScrollX is off) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2233 |
// FIXME-TABLE: This is solved incorrectly but also quite a difficult problem to fix as we also want ClipRect width to match. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2234 |
// See "table_width_distrib" and "table_width_keep_visible" tests |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2235 |
max_width = table->WorkRect.Max.x - (table->ColumnsEnabledCount - column->IndexWithinEnabledSet - 1) * min_column_distance - column->MinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2236 |
//max_width -= table->CellSpacingX1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2237 |
max_width -= table->CellSpacingX2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2238 |
max_width -= table->CellPaddingX * 2.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2239 |
max_width -= table->OuterPaddingX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2240 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2241 |
return max_width; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2242 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2243 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2244 |
// Note this is meant to be stored in column->WidthAuto, please generally use the WidthAuto field |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2245 |
float ImGui::TableGetColumnWidthAuto(ImGuiTable* table, ImGuiTableColumn* column) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2246 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2247 |
const float content_width_body = ImMax(column->ContentMaxXFrozen, column->ContentMaxXUnfrozen) - column->WorkMinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2248 |
const float content_width_headers = column->ContentMaxXHeadersIdeal - column->WorkMinX; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2249 |
float width_auto = content_width_body; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2250 |
if (!(column->Flags & ImGuiTableColumnFlags_NoHeaderWidth)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2251 |
width_auto = ImMax(width_auto, content_width_headers); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2252 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2253 |
// Non-resizable fixed columns preserve their requested width |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2254 |
if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && column->InitStretchWeightOrWidth > 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2255 |
if (!(table->Flags & ImGuiTableFlags_Resizable) || (column->Flags & ImGuiTableColumnFlags_NoResize)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2256 |
width_auto = column->InitStretchWeightOrWidth; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2257 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2258 |
return ImMax(width_auto, table->MinColumnWidth); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2259 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2260 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2261 |
// 'width' = inner column width, without padding |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2262 |
void ImGui::TableSetColumnWidth(int column_n, float width) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2263 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2264 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2265 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2266 |
IM_ASSERT(table != NULL && table->IsLayoutLocked == false); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2267 |
IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2268 |
ImGuiTableColumn* column_0 = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2269 |
float column_0_width = width; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2270 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2271 |
// Apply constraints early |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2272 |
// Compare both requested and actual given width to avoid overwriting requested width when column is stuck (minimum size, bounded) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2273 |
IM_ASSERT(table->MinColumnWidth > 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2274 |
const float min_width = table->MinColumnWidth; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2275 |
const float max_width = ImMax(min_width, column_0->WidthMax); // Don't use TableCalcMaxColumnWidth() here as it would rely on MinX from last instance (#7933) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2276 |
column_0_width = ImClamp(column_0_width, min_width, max_width); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2277 |
if (column_0->WidthGiven == column_0_width || column_0->WidthRequest == column_0_width) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2278 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2279 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2280 |
//IMGUI_DEBUG_PRINT("TableSetColumnWidth(%d, %.1f->%.1f)\n", column_0_idx, column_0->WidthGiven, column_0_width); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2281 |
ImGuiTableColumn* column_1 = (column_0->NextEnabledColumn != -1) ? &table->Columns[column_0->NextEnabledColumn] : NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2282 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2283 |
// In this surprisingly not simple because of how we support mixing Fixed and multiple Stretch columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2284 |
// - All fixed: easy. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2285 |
// - All stretch: easy. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2286 |
// - One or more fixed + one stretch: easy. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2287 |
// - One or more fixed + more than one stretch: tricky. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2288 |
// Qt when manual resize is enabled only supports a single _trailing_ stretch column, we support more cases here. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2289 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2290 |
// When forwarding resize from Wn| to Fn+1| we need to be considerate of the _NoResize flag on Fn+1. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2291 |
// FIXME-TABLE: Find a way to rewrite all of this so interactions feel more consistent for the user. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2292 |
// Scenarios: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2293 |
// - F1 F2 F3 resize from F1| or F2| --> ok: alter ->WidthRequested of Fixed column. Subsequent columns will be offset. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2294 |
// - F1 F2 F3 resize from F3| --> ok: alter ->WidthRequested of Fixed column. If active, ScrollX extent can be altered. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2295 |
// - F1 F2 W3 resize from F1| or F2| --> ok: alter ->WidthRequested of Fixed column. If active, ScrollX extent can be altered, but it doesn't make much sense as the Stretch column will always be minimal size. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2296 |
// - F1 F2 W3 resize from W3| --> ok: no-op (disabled by Resize Rule 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2297 |
// - W1 W2 W3 resize from W1| or W2| --> ok |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2298 |
// - W1 W2 W3 resize from W3| --> ok: no-op (disabled by Resize Rule 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2299 |
// - W1 F2 F3 resize from F3| --> ok: no-op (disabled by Resize Rule 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2300 |
// - W1 F2 resize from F2| --> ok: no-op (disabled by Resize Rule 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2301 |
// - W1 W2 F3 resize from W1| or W2| --> ok |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2302 |
// - W1 F2 W3 resize from W1| or F2| --> ok |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2303 |
// - F1 W2 F3 resize from W2| --> ok |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2304 |
// - F1 W3 F2 resize from W3| --> ok |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2305 |
// - W1 F2 F3 resize from W1| --> ok: equivalent to resizing |F2. F3 will not move. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2306 |
// - W1 F2 F3 resize from F2| --> ok |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2307 |
// All resizes from a Wx columns are locking other columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2308 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2309 |
// Possible improvements: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2310 |
// - W1 W2 W3 resize W1| --> to not be stuck, both W2 and W3 would stretch down. Seems possible to fix. Would be most beneficial to simplify resize of all-weighted columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2311 |
// - W3 F1 F2 resize W3| --> to not be stuck past F1|, both F1 and F2 would need to stretch down, which would be lossy or ambiguous. Seems hard to fix. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2312 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2313 |
// [Resize Rule 1] Can't resize from right of right-most visible column if there is any Stretch column. Implemented in TableUpdateLayout(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2314 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2315 |
// If we have all Fixed columns OR resizing a Fixed column that doesn't come after a Stretch one, we can do an offsetting resize. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2316 |
// This is the preferred resize path |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2317 |
if (column_0->Flags & ImGuiTableColumnFlags_WidthFixed) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2318 |
if (!column_1 || table->LeftMostStretchedColumn == -1 || table->Columns[table->LeftMostStretchedColumn].DisplayOrder >= column_0->DisplayOrder) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2319 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2320 |
column_0->WidthRequest = column_0_width; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2321 |
table->IsSettingsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2322 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2323 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2324 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2325 |
// We can also use previous column if there's no next one (this is used when doing an auto-fit on the right-most stretch column) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2326 |
if (column_1 == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2327 |
column_1 = (column_0->PrevEnabledColumn != -1) ? &table->Columns[column_0->PrevEnabledColumn] : NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2328 |
if (column_1 == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2329 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2330 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2331 |
// Resizing from right-side of a Stretch column before a Fixed column forward sizing to left-side of fixed column. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2332 |
// (old_a + old_b == new_a + new_b) --> (new_a == old_a + old_b - new_b) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2333 |
float column_1_width = ImMax(column_1->WidthRequest - (column_0_width - column_0->WidthRequest), min_width); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2334 |
column_0_width = column_0->WidthRequest + column_1->WidthRequest - column_1_width; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2335 |
IM_ASSERT(column_0_width > 0.0f && column_1_width > 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2336 |
column_0->WidthRequest = column_0_width; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2337 |
column_1->WidthRequest = column_1_width; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2338 |
if ((column_0->Flags | column_1->Flags) & ImGuiTableColumnFlags_WidthStretch) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2339 |
TableUpdateColumnsWeightFromWidth(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2340 |
table->IsSettingsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2341 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2342 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2343 |
// Disable clipping then auto-fit, will take 2 frames |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2344 |
// (we don't take a shortcut for unclipped columns to reduce inconsistencies when e.g. resizing multiple columns) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2345 |
void ImGui::TableSetColumnWidthAutoSingle(ImGuiTable* table, int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2346 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2347 |
// Single auto width uses auto-fit |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2348 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2349 |
if (!column->IsEnabled) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2350 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2351 |
column->CannotSkipItemsQueue = (1 << 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2352 |
table->AutoFitSingleColumn = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2353 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2354 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2355 |
void ImGui::TableSetColumnWidthAutoAll(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2356 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2357 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2358 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2359 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2360 |
if (!column->IsEnabled && !(column->Flags & ImGuiTableColumnFlags_WidthStretch)) // Cannot reset weight of hidden stretch column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2361 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2362 |
column->CannotSkipItemsQueue = (1 << 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2363 |
column->AutoFitQueue = (1 << 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2364 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2365 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2366 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2367 |
void ImGui::TableUpdateColumnsWeightFromWidth(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2368 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2369 |
IM_ASSERT(table->LeftMostStretchedColumn != -1 && table->RightMostStretchedColumn != -1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2370 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2371 |
// Measure existing quantities |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2372 |
float visible_weight = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2373 |
float visible_width = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2374 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2375 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2376 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2377 |
if (!column->IsEnabled || !(column->Flags & ImGuiTableColumnFlags_WidthStretch)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2378 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2379 |
IM_ASSERT(column->StretchWeight > 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2380 |
visible_weight += column->StretchWeight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2381 |
visible_width += column->WidthRequest; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2382 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2383 |
IM_ASSERT(visible_weight > 0.0f && visible_width > 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2384 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2385 |
// Apply new weights |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2386 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2387 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2388 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2389 |
if (!column->IsEnabled || !(column->Flags & ImGuiTableColumnFlags_WidthStretch)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2390 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2391 |
column->StretchWeight = (column->WidthRequest / visible_width) * visible_weight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2392 |
IM_ASSERT(column->StretchWeight > 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2393 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2394 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2395 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2396 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2397 |
// [SECTION] Tables: Drawing |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2398 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2399 |
// - TablePushBackgroundChannel() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2400 |
// - TablePopBackgroundChannel() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2401 |
// - TableSetupDrawChannels() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2402 |
// - TableMergeDrawChannels() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2403 |
// - TableGetColumnBorderCol() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2404 |
// - TableDrawBorders() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2405 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2406 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2407 |
// Bg2 is used by Selectable (and possibly other widgets) to render to the background. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2408 |
// Unlike our Bg0/1 channel which we uses for RowBg/CellBg/Borders and where we guarantee all shapes to be CPU-clipped, the Bg2 channel being widgets-facing will rely on regular ClipRect. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2409 |
void ImGui::TablePushBackgroundChannel() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2410 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2411 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2412 |
ImGuiWindow* window = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2413 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2414 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2415 |
// Optimization: avoid SetCurrentChannel() + PushClipRect() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2416 |
table->HostBackupInnerClipRect = window->ClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2417 |
SetWindowClipRectBeforeSetChannel(window, table->Bg2ClipRectForDrawCmd); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2418 |
table->DrawSplitter->SetCurrentChannel(window->DrawList, table->Bg2DrawChannelCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2419 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2420 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2421 |
void ImGui::TablePopBackgroundChannel() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2422 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2423 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2424 |
ImGuiWindow* window = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2425 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2426 |
ImGuiTableColumn* column = &table->Columns[table->CurrentColumn]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2427 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2428 |
// Optimization: avoid PopClipRect() + SetCurrentChannel() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2429 |
SetWindowClipRectBeforeSetChannel(window, table->HostBackupInnerClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2430 |
table->DrawSplitter->SetCurrentChannel(window->DrawList, column->DrawChannelCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2431 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2432 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2433 |
// Allocate draw channels. Called by TableUpdateLayout() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2434 |
// - We allocate them following storage order instead of display order so reordering columns won't needlessly |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2435 |
// increase overall dormant memory cost. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2436 |
// - We isolate headers draw commands in their own channels instead of just altering clip rects. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2437 |
// This is in order to facilitate merging of draw commands. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2438 |
// - After crossing FreezeRowsCount, all columns see their current draw channel changed to a second set of channels. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2439 |
// - We only use the dummy draw channel so we can push a null clipping rectangle into it without affecting other |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2440 |
// channels, while simplifying per-row/per-cell overhead. It will be empty and discarded when merged. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2441 |
// - We allocate 1 or 2 background draw channels. This is because we know TablePushBackgroundChannel() is only used for |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2442 |
// horizontal spanning. If we allowed vertical spanning we'd need one background draw channel per merge group (1-4). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2443 |
// Draw channel allocation (before merging): |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2444 |
// - NoClip --> 2+D+1 channels: bg0/1 + bg2 + foreground (same clip rect == always 1 draw call) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2445 |
// - Clip --> 2+D+N channels |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2446 |
// - FreezeRows --> 2+D+N*2 (unless scrolling value is zero) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2447 |
// - FreezeRows || FreezeColunns --> 3+D+N*2 (unless scrolling value is zero) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2448 |
// Where D is 1 if any column is clipped or hidden (dummy channel) otherwise 0. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2449 |
void ImGui::TableSetupDrawChannels(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2450 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2451 |
const int freeze_row_multiplier = (table->FreezeRowsCount > 0) ? 2 : 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2452 |
const int channels_for_row = (table->Flags & ImGuiTableFlags_NoClip) ? 1 : table->ColumnsEnabledCount; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2453 |
const int channels_for_bg = 1 + 1 * freeze_row_multiplier; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2454 |
const int channels_for_dummy = (table->ColumnsEnabledCount < table->ColumnsCount || (memcmp(table->VisibleMaskByIndex, table->EnabledMaskByIndex, ImBitArrayGetStorageSizeInBytes(table->ColumnsCount)) != 0)) ? +1 : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2455 |
const int channels_total = channels_for_bg + (channels_for_row * freeze_row_multiplier) + channels_for_dummy; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2456 |
table->DrawSplitter->Split(table->InnerWindow->DrawList, channels_total); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2457 |
table->DummyDrawChannel = (ImGuiTableDrawChannelIdx)((channels_for_dummy > 0) ? channels_total - 1 : -1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2458 |
table->Bg2DrawChannelCurrent = TABLE_DRAW_CHANNEL_BG2_FROZEN; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2459 |
table->Bg2DrawChannelUnfrozen = (ImGuiTableDrawChannelIdx)((table->FreezeRowsCount > 0) ? 2 + channels_for_row : TABLE_DRAW_CHANNEL_BG2_FROZEN); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2460 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2461 |
int draw_channel_current = 2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2462 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2463 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2464 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2465 |
if (column->IsVisibleX && column->IsVisibleY) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2466 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2467 |
column->DrawChannelFrozen = (ImGuiTableDrawChannelIdx)(draw_channel_current); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2468 |
column->DrawChannelUnfrozen = (ImGuiTableDrawChannelIdx)(draw_channel_current + (table->FreezeRowsCount > 0 ? channels_for_row + 1 : 0)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2469 |
if (!(table->Flags & ImGuiTableFlags_NoClip)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2470 |
draw_channel_current++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2471 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2472 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2473 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2474 |
column->DrawChannelFrozen = column->DrawChannelUnfrozen = table->DummyDrawChannel; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2475 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2476 |
column->DrawChannelCurrent = column->DrawChannelFrozen; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2477 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2478 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2479 |
// Initial draw cmd starts with a BgClipRect that matches the one of its host, to facilitate merge draw commands by default. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2480 |
// All our cell highlight are manually clipped with BgClipRect. When unfreezing it will be made smaller to fit scrolling rect. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2481 |
// (This technically isn't part of setting up draw channels, but is reasonably related to be done here) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2482 |
table->BgClipRect = table->InnerClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2483 |
table->Bg0ClipRectForDrawCmd = table->OuterWindow->ClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2484 |
table->Bg2ClipRectForDrawCmd = table->HostClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2485 |
IM_ASSERT(table->BgClipRect.Min.y <= table->BgClipRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2486 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2487 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2488 |
// This function reorder draw channels based on matching clip rectangle, to facilitate merging them. Called by EndTable(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2489 |
// For simplicity we call it TableMergeDrawChannels() but in fact it only reorder channels + overwrite ClipRect, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2490 |
// actual merging is done by table->DrawSplitter.Merge() which is called right after TableMergeDrawChannels(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2491 |
// |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2492 |
// Columns where the contents didn't stray off their local clip rectangle can be merged. To achieve |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2493 |
// this we merge their clip rect and make them contiguous in the channel list, so they can be merged |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2494 |
// by the call to DrawSplitter.Merge() following to the call to this function. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2495 |
// We reorder draw commands by arranging them into a maximum of 4 distinct groups: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2496 |
// |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2497 |
// 1 group: 2 groups: 2 groups: 4 groups: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2498 |
// [ 0. ] no freeze [ 0. ] row freeze [ 01 ] col freeze [ 01 ] row+col freeze |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2499 |
// [ .. ] or no scroll [ 2. ] and v-scroll [ .. ] and h-scroll [ 23 ] and v+h-scroll |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2500 |
// |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2501 |
// Each column itself can use 1 channel (row freeze disabled) or 2 channels (row freeze enabled). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2502 |
// When the contents of a column didn't stray off its limit, we move its channels into the corresponding group |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2503 |
// based on its position (within frozen rows/columns groups or not). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2504 |
// At the end of the operation our 1-4 groups will each have a ImDrawCmd using the same ClipRect. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2505 |
// This function assume that each column are pointing to a distinct draw channel, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2506 |
// otherwise merge_group->ChannelsCount will not match set bit count of merge_group->ChannelsMask. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2507 |
// |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2508 |
// Column channels will not be merged into one of the 1-4 groups in the following cases: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2509 |
// - The contents stray off its clipping rectangle (we only compare the MaxX value, not the MinX value). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2510 |
// Direct ImDrawList calls won't be taken into account by default, if you use them make sure the ImGui:: bounds |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2511 |
// matches, by e.g. calling SetCursorScreenPos(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2512 |
// - The channel uses more than one draw command itself. We drop all our attempt at merging stuff here.. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2513 |
// we could do better but it's going to be rare and probably not worth the hassle. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2514 |
// Columns for which the draw channel(s) haven't been merged with other will use their own ImDrawCmd. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2515 |
// |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2516 |
// This function is particularly tricky to understand.. take a breath. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2517 |
void ImGui::TableMergeDrawChannels(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2518 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2519 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2520 |
ImDrawListSplitter* splitter = table->DrawSplitter; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2521 |
const bool has_freeze_v = (table->FreezeRowsCount > 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2522 |
const bool has_freeze_h = (table->FreezeColumnsCount > 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2523 |
IM_ASSERT(splitter->_Current == 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2524 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2525 |
// Track which groups we are going to attempt to merge, and which channels goes into each group. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2526 |
struct MergeGroup |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2527 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2528 |
ImRect ClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2529 |
int ChannelsCount = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2530 |
ImBitArrayPtr ChannelsMask = NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2531 |
}; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2532 |
int merge_group_mask = 0x00; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2533 |
MergeGroup merge_groups[4]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2534 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2535 |
// Use a reusable temp buffer for the merge masks as they are dynamically sized. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2536 |
const int max_draw_channels = (4 + table->ColumnsCount * 2); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2537 |
const int size_for_masks_bitarrays_one = (int)ImBitArrayGetStorageSizeInBytes(max_draw_channels); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2538 |
g.TempBuffer.reserve(size_for_masks_bitarrays_one * 5); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2539 |
memset(g.TempBuffer.Data, 0, size_for_masks_bitarrays_one * 5); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2540 |
for (int n = 0; n < IM_ARRAYSIZE(merge_groups); n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2541 |
merge_groups[n].ChannelsMask = (ImBitArrayPtr)(void*)(g.TempBuffer.Data + (size_for_masks_bitarrays_one * n)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2542 |
ImBitArrayPtr remaining_mask = (ImBitArrayPtr)(void*)(g.TempBuffer.Data + (size_for_masks_bitarrays_one * 4)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2543 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2544 |
// 1. Scan channels and take note of those which can be merged |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2545 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2546 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2547 |
if (!IM_BITARRAY_TESTBIT(table->VisibleMaskByIndex, column_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2548 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2549 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2550 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2551 |
const int merge_group_sub_count = has_freeze_v ? 2 : 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2552 |
for (int merge_group_sub_n = 0; merge_group_sub_n < merge_group_sub_count; merge_group_sub_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2553 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2554 |
const int channel_no = (merge_group_sub_n == 0) ? column->DrawChannelFrozen : column->DrawChannelUnfrozen; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2555 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2556 |
// Don't attempt to merge if there are multiple draw calls within the column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2557 |
ImDrawChannel* src_channel = &splitter->_Channels[channel_no]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2558 |
if (src_channel->_CmdBuffer.Size > 0 && src_channel->_CmdBuffer.back().ElemCount == 0 && src_channel->_CmdBuffer.back().UserCallback == NULL) // Equivalent of PopUnusedDrawCmd() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2559 |
src_channel->_CmdBuffer.pop_back(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2560 |
if (src_channel->_CmdBuffer.Size != 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2561 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2562 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2563 |
// Find out the width of this merge group and check if it will fit in our column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2564 |
// (note that we assume that rendering didn't stray on the left direction. we should need a CursorMinPos to detect it) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2565 |
if (!(column->Flags & ImGuiTableColumnFlags_NoClip)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2566 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2567 |
float content_max_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2568 |
if (!has_freeze_v) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2569 |
content_max_x = ImMax(column->ContentMaxXUnfrozen, column->ContentMaxXHeadersUsed); // No row freeze |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2570 |
else if (merge_group_sub_n == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2571 |
content_max_x = ImMax(column->ContentMaxXFrozen, column->ContentMaxXHeadersUsed); // Row freeze: use width before freeze |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2572 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2573 |
content_max_x = column->ContentMaxXUnfrozen; // Row freeze: use width after freeze |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2574 |
if (content_max_x > column->ClipRect.Max.x) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2575 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2576 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2577 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2578 |
const int merge_group_n = (has_freeze_h && column_n < table->FreezeColumnsCount ? 0 : 1) + (has_freeze_v && merge_group_sub_n == 0 ? 0 : 2); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2579 |
IM_ASSERT(channel_no < max_draw_channels); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2580 |
MergeGroup* merge_group = &merge_groups[merge_group_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2581 |
if (merge_group->ChannelsCount == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2582 |
merge_group->ClipRect = ImRect(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2583 |
ImBitArraySetBit(merge_group->ChannelsMask, channel_no); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2584 |
merge_group->ChannelsCount++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2585 |
merge_group->ClipRect.Add(src_channel->_CmdBuffer[0].ClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2586 |
merge_group_mask |= (1 << merge_group_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2587 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2588 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2589 |
// Invalidate current draw channel |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2590 |
// (we don't clear DrawChannelFrozen/DrawChannelUnfrozen solely to facilitate debugging/later inspection of data) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2591 |
column->DrawChannelCurrent = (ImGuiTableDrawChannelIdx)-1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2592 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2593 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2594 |
// [DEBUG] Display merge groups |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2595 |
#if 0 |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2596 |
if (g.IO.KeyShift) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2597 |
for (int merge_group_n = 0; merge_group_n < IM_ARRAYSIZE(merge_groups); merge_group_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2598 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2599 |
MergeGroup* merge_group = &merge_groups[merge_group_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2600 |
if (merge_group->ChannelsCount == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2601 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2602 |
char buf[32]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2603 |
ImFormatString(buf, 32, "MG%d:%d", merge_group_n, merge_group->ChannelsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2604 |
ImVec2 text_pos = merge_group->ClipRect.Min + ImVec2(4, 4); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2605 |
ImVec2 text_size = CalcTextSize(buf, NULL); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2606 |
GetForegroundDrawList()->AddRectFilled(text_pos, text_pos + text_size, IM_COL32(0, 0, 0, 255)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2607 |
GetForegroundDrawList()->AddText(text_pos, IM_COL32(255, 255, 0, 255), buf, NULL); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2608 |
GetForegroundDrawList()->AddRect(merge_group->ClipRect.Min, merge_group->ClipRect.Max, IM_COL32(255, 255, 0, 255)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2609 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2610 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2611 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2612 |
// 2. Rewrite channel list in our preferred order |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2613 |
if (merge_group_mask != 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2614 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2615 |
// We skip channel 0 (Bg0/Bg1) and 1 (Bg2 frozen) from the shuffling since they won't move - see channels allocation in TableSetupDrawChannels(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2616 |
const int LEADING_DRAW_CHANNELS = 2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2617 |
g.DrawChannelsTempMergeBuffer.resize(splitter->_Count - LEADING_DRAW_CHANNELS); // Use shared temporary storage so the allocation gets amortized |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2618 |
ImDrawChannel* dst_tmp = g.DrawChannelsTempMergeBuffer.Data; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2619 |
ImBitArraySetBitRange(remaining_mask, LEADING_DRAW_CHANNELS, splitter->_Count); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2620 |
ImBitArrayClearBit(remaining_mask, table->Bg2DrawChannelUnfrozen); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2621 |
IM_ASSERT(has_freeze_v == false || table->Bg2DrawChannelUnfrozen != TABLE_DRAW_CHANNEL_BG2_FROZEN); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2622 |
int remaining_count = splitter->_Count - (has_freeze_v ? LEADING_DRAW_CHANNELS + 1 : LEADING_DRAW_CHANNELS); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2623 |
//ImRect host_rect = (table->InnerWindow == table->OuterWindow) ? table->InnerClipRect : table->HostClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2624 |
ImRect host_rect = table->HostClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2625 |
for (int merge_group_n = 0; merge_group_n < IM_ARRAYSIZE(merge_groups); merge_group_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2626 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2627 |
if (int merge_channels_count = merge_groups[merge_group_n].ChannelsCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2628 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2629 |
MergeGroup* merge_group = &merge_groups[merge_group_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2630 |
ImRect merge_clip_rect = merge_group->ClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2631 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2632 |
// Extend outer-most clip limits to match those of host, so draw calls can be merged even if |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2633 |
// outer-most columns have some outer padding offsetting them from their parent ClipRect. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2634 |
// The principal cases this is dealing with are: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2635 |
// - On a same-window table (not scrolling = single group), all fitting columns ClipRect -> will extend and match host ClipRect -> will merge |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2636 |
// - Columns can use padding and have left-most ClipRect.Min.x and right-most ClipRect.Max.x != from host ClipRect -> will extend and match host ClipRect -> will merge |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2637 |
// FIXME-TABLE FIXME-WORKRECT: We are wasting a merge opportunity on tables without scrolling if column doesn't fit |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2638 |
// within host clip rect, solely because of the half-padding difference between window->WorkRect and window->InnerClipRect. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2639 |
if ((merge_group_n & 1) == 0 || !has_freeze_h) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2640 |
merge_clip_rect.Min.x = ImMin(merge_clip_rect.Min.x, host_rect.Min.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2641 |
if ((merge_group_n & 2) == 0 || !has_freeze_v) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2642 |
merge_clip_rect.Min.y = ImMin(merge_clip_rect.Min.y, host_rect.Min.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2643 |
if ((merge_group_n & 1) != 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2644 |
merge_clip_rect.Max.x = ImMax(merge_clip_rect.Max.x, host_rect.Max.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2645 |
if ((merge_group_n & 2) != 0 && (table->Flags & ImGuiTableFlags_NoHostExtendY) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2646 |
merge_clip_rect.Max.y = ImMax(merge_clip_rect.Max.y, host_rect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2647 |
//GetForegroundDrawList()->AddRect(merge_group->ClipRect.Min, merge_group->ClipRect.Max, IM_COL32(255, 0, 0, 200), 0.0f, 0, 1.0f); // [DEBUG] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2648 |
//GetForegroundDrawList()->AddLine(merge_group->ClipRect.Min, merge_clip_rect.Min, IM_COL32(255, 100, 0, 200)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2649 |
//GetForegroundDrawList()->AddLine(merge_group->ClipRect.Max, merge_clip_rect.Max, IM_COL32(255, 100, 0, 200)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2650 |
remaining_count -= merge_group->ChannelsCount; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2651 |
for (int n = 0; n < (size_for_masks_bitarrays_one >> 2); n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2652 |
remaining_mask[n] &= ~merge_group->ChannelsMask[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2653 |
for (int n = 0; n < splitter->_Count && merge_channels_count != 0; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2654 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2655 |
// Copy + overwrite new clip rect |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2656 |
if (!IM_BITARRAY_TESTBIT(merge_group->ChannelsMask, n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2657 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2658 |
IM_BITARRAY_CLEARBIT(merge_group->ChannelsMask, n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2659 |
merge_channels_count--; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2660 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2661 |
ImDrawChannel* channel = &splitter->_Channels[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2662 |
IM_ASSERT(channel->_CmdBuffer.Size == 1 && merge_clip_rect.Contains(ImRect(channel->_CmdBuffer[0].ClipRect))); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2663 |
channel->_CmdBuffer[0].ClipRect = merge_clip_rect.ToVec4(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2664 |
memcpy(dst_tmp++, channel, sizeof(ImDrawChannel)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2665 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2666 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2667 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2668 |
// Make sure Bg2DrawChannelUnfrozen appears in the middle of our groups (whereas Bg0/Bg1 and Bg2 frozen are fixed to 0 and 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2669 |
if (merge_group_n == 1 && has_freeze_v) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2670 |
memcpy(dst_tmp++, &splitter->_Channels[table->Bg2DrawChannelUnfrozen], sizeof(ImDrawChannel)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2671 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2672 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2673 |
// Append unmergeable channels that we didn't reorder at the end of the list |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2674 |
for (int n = 0; n < splitter->_Count && remaining_count != 0; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2675 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2676 |
if (!IM_BITARRAY_TESTBIT(remaining_mask, n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2677 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2678 |
ImDrawChannel* channel = &splitter->_Channels[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2679 |
memcpy(dst_tmp++, channel, sizeof(ImDrawChannel)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2680 |
remaining_count--; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2681 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2682 |
IM_ASSERT(dst_tmp == g.DrawChannelsTempMergeBuffer.Data + g.DrawChannelsTempMergeBuffer.Size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2683 |
memcpy(splitter->_Channels.Data + LEADING_DRAW_CHANNELS, g.DrawChannelsTempMergeBuffer.Data, (splitter->_Count - LEADING_DRAW_CHANNELS) * sizeof(ImDrawChannel)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2684 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2685 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2686 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2687 |
static ImU32 TableGetColumnBorderCol(ImGuiTable* table, int order_n, int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2688 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2689 |
const bool is_hovered = (table->HoveredColumnBorder == column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2690 |
const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2691 |
const bool is_frozen_separator = (table->FreezeColumnsCount == order_n + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2692 |
if (is_resized || is_hovered) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2693 |
return ImGui::GetColorU32(is_resized ? ImGuiCol_SeparatorActive : ImGuiCol_SeparatorHovered); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2694 |
if (is_frozen_separator || (table->Flags & (ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoBordersInBodyUntilResize))) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2695 |
return table->BorderColorStrong; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2696 |
return table->BorderColorLight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2697 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2698 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2699 |
// FIXME-TABLE: This is a mess, need to redesign how we render borders (as some are also done in TableEndRow) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2700 |
void ImGui::TableDrawBorders(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2701 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2702 |
ImGuiWindow* inner_window = table->InnerWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2703 |
if (!table->OuterWindow->ClipRect.Overlaps(table->OuterRect)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2704 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2705 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2706 |
ImDrawList* inner_drawlist = inner_window->DrawList; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2707 |
table->DrawSplitter->SetCurrentChannel(inner_drawlist, TABLE_DRAW_CHANNEL_BG0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2708 |
inner_drawlist->PushClipRect(table->Bg0ClipRectForDrawCmd.Min, table->Bg0ClipRectForDrawCmd.Max, false); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2709 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2710 |
// Draw inner border and resizing feedback |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2711 |
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2712 |
const float border_size = TABLE_BORDER_SIZE; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2713 |
const float draw_y1 = ImMax(table->InnerRect.Min.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table->AngledHeadersHeight) + ((table->Flags & ImGuiTableFlags_BordersOuterH) ? 1.0f : 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2714 |
const float draw_y2_body = table->InnerRect.Max.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2715 |
const float draw_y2_head = table->IsUsingHeaders ? ImMin(table->InnerRect.Max.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table_instance->LastTopHeadersRowHeight) : draw_y1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2716 |
if (table->Flags & ImGuiTableFlags_BordersInnerV) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2717 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2718 |
for (int order_n = 0; order_n < table->ColumnsCount; order_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2719 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2720 |
if (!IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2721 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2722 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2723 |
const int column_n = table->DisplayOrderToIndex[order_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2724 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2725 |
const bool is_hovered = (table->HoveredColumnBorder == column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2726 |
const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2727 |
const bool is_resizable = (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_)) == 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2728 |
const bool is_frozen_separator = (table->FreezeColumnsCount == order_n + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2729 |
if (column->MaxX > table->InnerClipRect.Max.x && !is_resized) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2730 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2731 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2732 |
// Decide whether right-most column is visible |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2733 |
if (column->NextEnabledColumn == -1 && !is_resizable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2734 |
if ((table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame || (table->Flags & ImGuiTableFlags_NoHostExtendX)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2735 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2736 |
if (column->MaxX <= column->ClipRect.Min.x) // FIXME-TABLE FIXME-STYLE: Assume BorderSize==1, this is problematic if we want to increase the border size.. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2737 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2738 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2739 |
// Draw in outer window so right-most column won't be clipped |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2740 |
// Always draw full height border when being resized/hovered, or on the delimitation of frozen column scrolling. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2741 |
float draw_y2 = (is_hovered || is_resized || is_frozen_separator || (table->Flags & (ImGuiTableFlags_NoBordersInBody | ImGuiTableFlags_NoBordersInBodyUntilResize)) == 0) ? draw_y2_body : draw_y2_head; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2742 |
if (draw_y2 > draw_y1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2743 |
inner_drawlist->AddLine(ImVec2(column->MaxX, draw_y1), ImVec2(column->MaxX, draw_y2), TableGetColumnBorderCol(table, order_n, column_n), border_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2744 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2745 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2746 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2747 |
// Draw outer border |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2748 |
// FIXME: could use AddRect or explicit VLine/HLine helper? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2749 |
if (table->Flags & ImGuiTableFlags_BordersOuter) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2750 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2751 |
// Display outer border offset by 1 which is a simple way to display it without adding an extra draw call |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2752 |
// (Without the offset, in outer_window it would be rendered behind cells, because child windows are above their |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2753 |
// parent. In inner_window, it won't reach out over scrollbars. Another weird solution would be to display part |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2754 |
// of it in inner window, and the part that's over scrollbars in the outer window..) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2755 |
// Either solution currently won't allow us to use a larger border size: the border would clipped. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2756 |
const ImRect outer_border = table->OuterRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2757 |
const ImU32 outer_col = table->BorderColorStrong; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2758 |
if ((table->Flags & ImGuiTableFlags_BordersOuter) == ImGuiTableFlags_BordersOuter) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2759 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2760 |
inner_drawlist->AddRect(outer_border.Min, outer_border.Max, outer_col, 0.0f, 0, border_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2761 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2762 |
else if (table->Flags & ImGuiTableFlags_BordersOuterV) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2763 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2764 |
inner_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Min.x, outer_border.Max.y), outer_col, border_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2765 |
inner_drawlist->AddLine(ImVec2(outer_border.Max.x, outer_border.Min.y), outer_border.Max, outer_col, border_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2766 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2767 |
else if (table->Flags & ImGuiTableFlags_BordersOuterH) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2768 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2769 |
inner_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Max.x, outer_border.Min.y), outer_col, border_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2770 |
inner_drawlist->AddLine(ImVec2(outer_border.Min.x, outer_border.Max.y), outer_border.Max, outer_col, border_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2771 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2772 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2773 |
if ((table->Flags & ImGuiTableFlags_BordersInnerH) && table->RowPosY2 < table->OuterRect.Max.y) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2774 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2775 |
// Draw bottom-most row border between it is above outer border. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2776 |
const float border_y = table->RowPosY2; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2777 |
if (border_y >= table->BgClipRect.Min.y && border_y < table->BgClipRect.Max.y) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2778 |
inner_drawlist->AddLine(ImVec2(table->BorderX1, border_y), ImVec2(table->BorderX2, border_y), table->BorderColorLight, border_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2779 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2780 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2781 |
inner_drawlist->PopClipRect(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2782 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2783 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2784 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2785 |
// [SECTION] Tables: Sorting |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2786 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2787 |
// - TableGetSortSpecs() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2788 |
// - TableFixColumnSortDirection() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2789 |
// - TableGetColumnNextSortDirection() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2790 |
// - TableSetColumnSortDirection() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2791 |
// - TableSortSpecsSanitize() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2792 |
// - TableSortSpecsBuild() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2793 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2794 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2795 |
// Return NULL if no sort specs (most often when ImGuiTableFlags_Sortable is not set) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2796 |
// When 'sort_specs->SpecsDirty == true' you should sort your data. It will be true when sorting specs have |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2797 |
// changed since last call, or the first time. Make sure to set 'SpecsDirty = false' after sorting, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2798 |
// else you may wastefully sort your data every frame! |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2799 |
// Lifetime: don't hold on this pointer over multiple frames or past any subsequent call to BeginTable()! |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2800 |
ImGuiTableSortSpecs* ImGui::TableGetSortSpecs() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2801 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2802 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2803 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2804 |
IM_ASSERT(table != NULL); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2805 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2806 |
if (!(table->Flags & ImGuiTableFlags_Sortable)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2807 |
return NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2808 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2809 |
// Require layout (in case TableHeadersRow() hasn't been called) as it may alter IsSortSpecsDirty in some paths. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2810 |
if (!table->IsLayoutLocked) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2811 |
TableUpdateLayout(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2812 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2813 |
TableSortSpecsBuild(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2814 |
return &table->SortSpecs; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2815 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2816 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2817 |
static inline ImGuiSortDirection TableGetColumnAvailSortDirection(ImGuiTableColumn* column, int n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2818 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2819 |
IM_ASSERT(n < column->SortDirectionsAvailCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2820 |
return (ImGuiSortDirection)((column->SortDirectionsAvailList >> (n << 1)) & 0x03); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2821 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2822 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2823 |
// Fix sort direction if currently set on a value which is unavailable (e.g. activating NoSortAscending/NoSortDescending) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2824 |
void ImGui::TableFixColumnSortDirection(ImGuiTable* table, ImGuiTableColumn* column) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2825 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2826 |
if (column->SortOrder == -1 || (column->SortDirectionsAvailMask & (1 << column->SortDirection)) != 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2827 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2828 |
column->SortDirection = (ImU8)TableGetColumnAvailSortDirection(column, 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2829 |
table->IsSortSpecsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2830 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2831 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2832 |
// Calculate next sort direction that would be set after clicking the column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2833 |
// - If the PreferSortDescending flag is set, we will default to a Descending direction on the first click. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2834 |
// - Note that the PreferSortAscending flag is never checked, it is essentially the default and therefore a no-op. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2835 |
IM_STATIC_ASSERT(ImGuiSortDirection_None == 0 && ImGuiSortDirection_Ascending == 1 && ImGuiSortDirection_Descending == 2); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2836 |
ImGuiSortDirection ImGui::TableGetColumnNextSortDirection(ImGuiTableColumn* column) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2837 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2838 |
IM_ASSERT(column->SortDirectionsAvailCount > 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2839 |
if (column->SortOrder == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2840 |
return TableGetColumnAvailSortDirection(column, 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2841 |
for (int n = 0; n < 3; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2842 |
if (column->SortDirection == TableGetColumnAvailSortDirection(column, n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2843 |
return TableGetColumnAvailSortDirection(column, (n + 1) % column->SortDirectionsAvailCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2844 |
IM_ASSERT(0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2845 |
return ImGuiSortDirection_None; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2846 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2847 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2848 |
// Note that the NoSortAscending/NoSortDescending flags are processed in TableSortSpecsSanitize(), and they may change/revert |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2849 |
// the value of SortDirection. We could technically also do it here but it would be unnecessary and duplicate code. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2850 |
void ImGui::TableSetColumnSortDirection(int column_n, ImGuiSortDirection sort_direction, bool append_to_sort_specs) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2851 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2852 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2853 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2854 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2855 |
if (!(table->Flags & ImGuiTableFlags_SortMulti)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2856 |
append_to_sort_specs = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2857 |
if (!(table->Flags & ImGuiTableFlags_SortTristate)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2858 |
IM_ASSERT(sort_direction != ImGuiSortDirection_None); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2859 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2860 |
ImGuiTableColumnIdx sort_order_max = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2861 |
if (append_to_sort_specs) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2862 |
for (int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2863 |
sort_order_max = ImMax(sort_order_max, table->Columns[other_column_n].SortOrder); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2864 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2865 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2866 |
column->SortDirection = (ImU8)sort_direction; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2867 |
if (column->SortDirection == ImGuiSortDirection_None) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2868 |
column->SortOrder = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2869 |
else if (column->SortOrder == -1 || !append_to_sort_specs) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2870 |
column->SortOrder = append_to_sort_specs ? sort_order_max + 1 : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2871 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2872 |
for (int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2873 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2874 |
ImGuiTableColumn* other_column = &table->Columns[other_column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2875 |
if (other_column != column && !append_to_sort_specs) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2876 |
other_column->SortOrder = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2877 |
TableFixColumnSortDirection(table, other_column); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2878 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2879 |
table->IsSettingsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2880 |
table->IsSortSpecsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2881 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2882 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2883 |
void ImGui::TableSortSpecsSanitize(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2884 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2885 |
IM_ASSERT(table->Flags & ImGuiTableFlags_Sortable); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2886 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2887 |
// Clear SortOrder from hidden column and verify that there's no gap or duplicate. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2888 |
int sort_order_count = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2889 |
ImU64 sort_order_mask = 0x00; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2890 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2891 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2892 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2893 |
if (column->SortOrder != -1 && !column->IsEnabled) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2894 |
column->SortOrder = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2895 |
if (column->SortOrder == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2896 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2897 |
sort_order_count++; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2898 |
sort_order_mask |= ((ImU64)1 << column->SortOrder); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2899 |
IM_ASSERT(sort_order_count < (int)sizeof(sort_order_mask) * 8); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2900 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2901 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2902 |
const bool need_fix_linearize = ((ImU64)1 << sort_order_count) != (sort_order_mask + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2903 |
const bool need_fix_single_sort_order = (sort_order_count > 1) && !(table->Flags & ImGuiTableFlags_SortMulti); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2904 |
if (need_fix_linearize || need_fix_single_sort_order) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2905 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2906 |
ImU64 fixed_mask = 0x00; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2907 |
for (int sort_n = 0; sort_n < sort_order_count; sort_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2908 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2909 |
// Fix: Rewrite sort order fields if needed so they have no gap or duplicate. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2910 |
// (e.g. SortOrder 0 disappeared, SortOrder 1..2 exists --> rewrite then as SortOrder 0..1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2911 |
int column_with_smallest_sort_order = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2912 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2913 |
if ((fixed_mask & ((ImU64)1 << (ImU64)column_n)) == 0 && table->Columns[column_n].SortOrder != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2914 |
if (column_with_smallest_sort_order == -1 || table->Columns[column_n].SortOrder < table->Columns[column_with_smallest_sort_order].SortOrder) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2915 |
column_with_smallest_sort_order = column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2916 |
IM_ASSERT(column_with_smallest_sort_order != -1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2917 |
fixed_mask |= ((ImU64)1 << column_with_smallest_sort_order); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2918 |
table->Columns[column_with_smallest_sort_order].SortOrder = (ImGuiTableColumnIdx)sort_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2919 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2920 |
// Fix: Make sure only one column has a SortOrder if ImGuiTableFlags_MultiSortable is not set. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2921 |
if (need_fix_single_sort_order) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2922 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2923 |
sort_order_count = 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2924 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2925 |
if (column_n != column_with_smallest_sort_order) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2926 |
table->Columns[column_n].SortOrder = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2927 |
break; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2928 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2929 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2930 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2931 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2932 |
// Fallback default sort order (if no column with the ImGuiTableColumnFlags_DefaultSort flag) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2933 |
if (sort_order_count == 0 && !(table->Flags & ImGuiTableFlags_SortTristate)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2934 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2935 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2936 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2937 |
if (column->IsEnabled && !(column->Flags & ImGuiTableColumnFlags_NoSort)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2938 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2939 |
sort_order_count = 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2940 |
column->SortOrder = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2941 |
column->SortDirection = (ImU8)TableGetColumnAvailSortDirection(column, 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2942 |
break; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2943 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2944 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2945 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2946 |
table->SortSpecsCount = (ImGuiTableColumnIdx)sort_order_count; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2947 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2948 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2949 |
void ImGui::TableSortSpecsBuild(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2950 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2951 |
bool dirty = table->IsSortSpecsDirty; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2952 |
if (dirty) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2953 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2954 |
TableSortSpecsSanitize(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2955 |
table->SortSpecsMulti.resize(table->SortSpecsCount <= 1 ? 0 : table->SortSpecsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2956 |
table->SortSpecs.SpecsDirty = true; // Mark as dirty for user |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2957 |
table->IsSortSpecsDirty = false; // Mark as not dirty for us |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2958 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2959 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2960 |
// Write output |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2961 |
// May be able to move all SortSpecs data from table (48 bytes) to ImGuiTableTempData if we decide to write it back on every BeginTable() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2962 |
ImGuiTableColumnSortSpecs* sort_specs = (table->SortSpecsCount == 0) ? NULL : (table->SortSpecsCount == 1) ? &table->SortSpecsSingle : table->SortSpecsMulti.Data; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2963 |
if (dirty && sort_specs != NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2964 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2965 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2966 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2967 |
if (column->SortOrder == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2968 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2969 |
IM_ASSERT(column->SortOrder < table->SortSpecsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2970 |
ImGuiTableColumnSortSpecs* sort_spec = &sort_specs[column->SortOrder]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2971 |
sort_spec->ColumnUserID = column->UserID; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2972 |
sort_spec->ColumnIndex = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2973 |
sort_spec->SortOrder = (ImGuiTableColumnIdx)column->SortOrder; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2974 |
sort_spec->SortDirection = (ImGuiSortDirection)column->SortDirection; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2975 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2976 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2977 |
table->SortSpecs.Specs = sort_specs; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2978 |
table->SortSpecs.SpecsCount = table->SortSpecsCount; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2979 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2980 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2981 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2982 |
// [SECTION] Tables: Headers |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2983 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2984 |
// - TableGetHeaderRowHeight() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2985 |
// - TableGetHeaderAngledMaxLabelWidth() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2986 |
// - TableHeadersRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2987 |
// - TableHeader() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2988 |
// - TableAngledHeadersRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2989 |
// - TableAngledHeadersRowEx() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2990 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2991 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2992 |
float ImGui::TableGetHeaderRowHeight() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2993 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2994 |
// Caring for a minor edge case: |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2995 |
// Calculate row height, for the unlikely case that some labels may be taller than others. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2996 |
// If we didn't do that, uneven header height would highlight but smaller one before the tallest wouldn't catch input for all height. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2997 |
// In your custom header row you may omit this all together and just call TableNextRow() without a height... |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2998 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
2999 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3000 |
float row_height = g.FontSize; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3001 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3002 |
if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3003 |
if ((table->Columns[column_n].Flags & ImGuiTableColumnFlags_NoHeaderLabel) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3004 |
row_height = ImMax(row_height, CalcTextSize(TableGetColumnName(table, column_n)).y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3005 |
return row_height + g.Style.CellPadding.y * 2.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3006 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3007 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3008 |
float ImGui::TableGetHeaderAngledMaxLabelWidth() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3009 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3010 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3011 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3012 |
float width = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3013 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3014 |
if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3015 |
if (table->Columns[column_n].Flags & ImGuiTableColumnFlags_AngledHeader) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3016 |
width = ImMax(width, CalcTextSize(TableGetColumnName(table, column_n), NULL, true).x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3017 |
return width + g.Style.CellPadding.y * 2.0f; // Swap padding |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3018 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3019 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3020 |
// [Public] This is a helper to output TableHeader() calls based on the column names declared in TableSetupColumn(). |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3021 |
// The intent is that advanced users willing to create customized headers would not need to use this helper |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3022 |
// and can create their own! For example: TableHeader() may be preceded by Checkbox() or other custom widgets. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3023 |
// See 'Demo->Tables->Custom headers' for a demonstration of implementing a custom version of this. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3024 |
// This code is intentionally written to not make much use of internal functions, to give you better direction |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3025 |
// if you need to write your own. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3026 |
// FIXME-TABLE: TableOpenContextMenu() and TableGetHeaderRowHeight() are not public. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3027 |
void ImGui::TableHeadersRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3028 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3029 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3030 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3031 |
IM_ASSERT(table != NULL && "Need to call TableHeadersRow() after BeginTable()!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3032 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3033 |
// Call layout if not already done. This is automatically done by TableNextRow: we do it here _only_ to make |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3034 |
// it easier to debug-step in TableUpdateLayout(). Your own version of this function doesn't need this. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3035 |
if (!table->IsLayoutLocked) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3036 |
TableUpdateLayout(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3037 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3038 |
// Open row |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3039 |
const float row_height = TableGetHeaderRowHeight(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3040 |
TableNextRow(ImGuiTableRowFlags_Headers, row_height); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3041 |
const float row_y1 = GetCursorScreenPos().y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3042 |
if (table->HostSkipItems) // Merely an optimization, you may skip in your own code. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3043 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3044 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3045 |
const int columns_count = TableGetColumnCount(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3046 |
for (int column_n = 0; column_n < columns_count; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3047 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3048 |
if (!TableSetColumnIndex(column_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3049 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3050 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3051 |
// Push an id to allow empty/unnamed headers. This is also idiomatic as it ensure there is a consistent ID path to access columns (for e.g. automation) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3052 |
const char* name = (TableGetColumnFlags(column_n) & ImGuiTableColumnFlags_NoHeaderLabel) ? "" : TableGetColumnName(column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3053 |
PushID(column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3054 |
TableHeader(name); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3055 |
PopID(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3056 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3057 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3058 |
// Allow opening popup from the right-most section after the last column. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3059 |
ImVec2 mouse_pos = ImGui::GetMousePos(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3060 |
if (IsMouseReleased(1) && TableGetHoveredColumn() == columns_count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3061 |
if (mouse_pos.y >= row_y1 && mouse_pos.y < row_y1 + row_height) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3062 |
TableOpenContextMenu(columns_count); // Will open a non-column-specific popup. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3063 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3064 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3065 |
// Emit a column header (text + optional sort order) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3066 |
// We cpu-clip text here so that all columns headers can be merged into a same draw call. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3067 |
// Note that because of how we cpu-clip and display sorting indicators, you _cannot_ use SameLine() after a TableHeader() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3068 |
void ImGui::TableHeader(const char* label) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3069 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3070 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3071 |
ImGuiWindow* window = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3072 |
if (window->SkipItems) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3073 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3074 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3075 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3076 |
IM_ASSERT(table != NULL && "Need to call TableHeader() after BeginTable()!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3077 |
IM_ASSERT(table->CurrentColumn != -1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3078 |
const int column_n = table->CurrentColumn; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3079 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3080 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3081 |
// Label |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3082 |
if (label == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3083 |
label = ""; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3084 |
const char* label_end = FindRenderedTextEnd(label); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3085 |
ImVec2 label_size = CalcTextSize(label, label_end, true); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3086 |
ImVec2 label_pos = window->DC.CursorPos; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3087 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3088 |
// If we already got a row height, there's use that. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3089 |
// FIXME-TABLE: Padding problem if the correct outer-padding CellBgRect strays off our ClipRect? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3090 |
ImRect cell_r = TableGetCellBgRect(table, column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3091 |
float label_height = ImMax(label_size.y, table->RowMinHeight - table->RowCellPaddingY * 2.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3092 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3093 |
// Calculate ideal size for sort order arrow |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3094 |
float w_arrow = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3095 |
float w_sort_text = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3096 |
bool sort_arrow = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3097 |
char sort_order_suf[4] = ""; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3098 |
const float ARROW_SCALE = 0.65f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3099 |
if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3100 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3101 |
w_arrow = ImTrunc(g.FontSize * ARROW_SCALE + g.Style.FramePadding.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3102 |
if (column->SortOrder != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3103 |
sort_arrow = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3104 |
if (column->SortOrder > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3105 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3106 |
ImFormatString(sort_order_suf, IM_ARRAYSIZE(sort_order_suf), "%d", column->SortOrder + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3107 |
w_sort_text = g.Style.ItemInnerSpacing.x + CalcTextSize(sort_order_suf).x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3108 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3109 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3110 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3111 |
// We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considered for merging. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3112 |
float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3113 |
column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, sort_arrow ? cell_r.Max.x : ImMin(max_pos_x, cell_r.Max.x)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3114 |
column->ContentMaxXHeadersIdeal = ImMax(column->ContentMaxXHeadersIdeal, max_pos_x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3115 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3116 |
// Keep header highlighted when context menu is open. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3117 |
ImGuiID id = window->GetID(label); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3118 |
ImRect bb(cell_r.Min.x, cell_r.Min.y, cell_r.Max.x, ImMax(cell_r.Max.y, cell_r.Min.y + label_height + g.Style.CellPadding.y * 2.0f)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3119 |
ItemSize(ImVec2(0.0f, label_height)); // Don't declare unclipped width, it'll be fed ContentMaxPosHeadersIdeal |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3120 |
if (!ItemAdd(bb, id)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3121 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3122 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3123 |
//GetForegroundDrawList()->AddRect(cell_r.Min, cell_r.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3124 |
//GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3125 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3126 |
// Using AllowOverlap mode because we cover the whole cell, and we want user to be able to submit subsequent items. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3127 |
const bool highlight = (table->HighlightColumnHeader == column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3128 |
bool hovered, held; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3129 |
bool pressed = ButtonBehavior(bb, id, &hovered, &held, ImGuiButtonFlags_AllowOverlap); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3130 |
if (held || hovered || highlight) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3131 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3132 |
const ImU32 col = GetColorU32(held ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3133 |
//RenderFrame(bb.Min, bb.Max, col, false, 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3134 |
TableSetBgColor(ImGuiTableBgTarget_CellBg, col, table->CurrentColumn); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3135 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3136 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3137 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3138 |
// Submit single cell bg color in the case we didn't submit a full header row |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3139 |
if ((table->RowFlags & ImGuiTableRowFlags_Headers) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3140 |
TableSetBgColor(ImGuiTableBgTarget_CellBg, GetColorU32(ImGuiCol_TableHeaderBg), table->CurrentColumn); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3141 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3142 |
RenderNavCursor(bb, id, ImGuiNavRenderCursorFlags_Compact | ImGuiNavRenderCursorFlags_NoRounding); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3143 |
if (held) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3144 |
table->HeldHeaderColumn = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3145 |
window->DC.CursorPos.y -= g.Style.ItemSpacing.y * 0.5f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3146 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3147 |
// Drag and drop to re-order columns. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3148 |
// FIXME-TABLE: Scroll request while reordering a column and it lands out of the scrolling zone. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3149 |
if (held && (table->Flags & ImGuiTableFlags_Reorderable) && IsMouseDragging(0) && !g.DragDropActive) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3150 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3151 |
// While moving a column it will jump on the other side of the mouse, so we also test for MouseDelta.x |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3152 |
table->ReorderColumn = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3153 |
table->InstanceInteracted = table->InstanceCurrent; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3154 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3155 |
// We don't reorder: through the frozen<>unfrozen line, or through a column that is marked with ImGuiTableColumnFlags_NoReorder. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3156 |
if (g.IO.MouseDelta.x < 0.0f && g.IO.MousePos.x < cell_r.Min.x) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3157 |
if (ImGuiTableColumn* prev_column = (column->PrevEnabledColumn != -1) ? &table->Columns[column->PrevEnabledColumn] : NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3158 |
if (!((column->Flags | prev_column->Flags) & ImGuiTableColumnFlags_NoReorder)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3159 |
if ((column->IndexWithinEnabledSet < table->FreezeColumnsRequest) == (prev_column->IndexWithinEnabledSet < table->FreezeColumnsRequest)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3160 |
table->ReorderColumnDir = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3161 |
if (g.IO.MouseDelta.x > 0.0f && g.IO.MousePos.x > cell_r.Max.x) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3162 |
if (ImGuiTableColumn* next_column = (column->NextEnabledColumn != -1) ? &table->Columns[column->NextEnabledColumn] : NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3163 |
if (!((column->Flags | next_column->Flags) & ImGuiTableColumnFlags_NoReorder)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3164 |
if ((column->IndexWithinEnabledSet < table->FreezeColumnsRequest) == (next_column->IndexWithinEnabledSet < table->FreezeColumnsRequest)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3165 |
table->ReorderColumnDir = +1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3166 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3167 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3168 |
// Sort order arrow |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3169 |
const float ellipsis_max = ImMax(cell_r.Max.x - w_arrow - w_sort_text, label_pos.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3170 |
if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3171 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3172 |
if (column->SortOrder != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3173 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3174 |
float x = ImMax(cell_r.Min.x, cell_r.Max.x - w_arrow - w_sort_text); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3175 |
float y = label_pos.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3176 |
if (column->SortOrder > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3177 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3178 |
PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_Text, 0.70f)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3179 |
RenderText(ImVec2(x + g.Style.ItemInnerSpacing.x, y), sort_order_suf); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3180 |
PopStyleColor(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3181 |
x += w_sort_text; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3182 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3183 |
RenderArrow(window->DrawList, ImVec2(x, y), GetColorU32(ImGuiCol_Text), column->SortDirection == ImGuiSortDirection_Ascending ? ImGuiDir_Up : ImGuiDir_Down, ARROW_SCALE); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3184 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3185 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3186 |
// Handle clicking on column header to adjust Sort Order |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3187 |
if (pressed && table->ReorderColumn != column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3188 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3189 |
ImGuiSortDirection sort_direction = TableGetColumnNextSortDirection(column); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3190 |
TableSetColumnSortDirection(column_n, sort_direction, g.IO.KeyShift); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3191 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3192 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3193 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3194 |
// Render clipped label. Clipping here ensure that in the majority of situations, all our header cells will |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3195 |
// be merged into a single draw call. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3196 |
//window->DrawList->AddCircleFilled(ImVec2(ellipsis_max, label_pos.y), 40, IM_COL32_WHITE); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3197 |
RenderTextEllipsis(window->DrawList, label_pos, ImVec2(ellipsis_max, label_pos.y + label_height + g.Style.FramePadding.y), ellipsis_max, ellipsis_max, label, label_end, &label_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3198 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3199 |
const bool text_clipped = label_size.x > (ellipsis_max - label_pos.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3200 |
if (text_clipped && hovered && g.ActiveId == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3201 |
SetItemTooltip("%.*s", (int)(label_end - label), label); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3202 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3203 |
// We don't use BeginPopupContextItem() because we want the popup to stay up even after the column is hidden |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3204 |
if (IsMouseReleased(1) && IsItemHovered()) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3205 |
TableOpenContextMenu(column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3206 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3207 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3208 |
// Unlike TableHeadersRow() it is not expected that you can reimplement or customize this with custom widgets. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3209 |
// FIXME: No hit-testing/button on the angled header. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3210 |
void ImGui::TableAngledHeadersRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3211 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3212 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3213 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3214 |
ImGuiTableTempData* temp_data = table->TempData; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3215 |
temp_data->AngledHeadersRequests.resize(0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3216 |
temp_data->AngledHeadersRequests.reserve(table->ColumnsEnabledCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3217 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3218 |
// Which column needs highlight? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3219 |
const ImGuiID row_id = GetID("##AngledHeaders"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3220 |
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3221 |
int highlight_column_n = table->HighlightColumnHeader; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3222 |
if (highlight_column_n == -1 && table->HoveredColumnBody != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3223 |
if (table_instance->HoveredRowLast == 0 && table->HoveredColumnBorder == -1 && (g.ActiveId == 0 || g.ActiveId == row_id || (table->IsActiveIdInTable || g.DragDropActive))) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3224 |
highlight_column_n = table->HoveredColumnBody; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3225 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3226 |
// Build up request |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3227 |
ImU32 col_header_bg = GetColorU32(ImGuiCol_TableHeaderBg); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3228 |
ImU32 col_text = GetColorU32(ImGuiCol_Text); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3229 |
for (int order_n = 0; order_n < table->ColumnsCount; order_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3230 |
if (IM_BITARRAY_TESTBIT(table->EnabledMaskByDisplayOrder, order_n)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3231 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3232 |
const int column_n = table->DisplayOrderToIndex[order_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3233 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3234 |
if ((column->Flags & ImGuiTableColumnFlags_AngledHeader) == 0) // Note: can't rely on ImGuiTableColumnFlags_IsVisible test here. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3235 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3236 |
ImGuiTableHeaderData request = { (ImGuiTableColumnIdx)column_n, col_text, col_header_bg, (column_n == highlight_column_n) ? GetColorU32(ImGuiCol_Header) : 0 }; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3237 |
temp_data->AngledHeadersRequests.push_back(request); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3238 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3239 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3240 |
// Render row |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3241 |
TableAngledHeadersRowEx(row_id, g.Style.TableAngledHeadersAngle, 0.0f, temp_data->AngledHeadersRequests.Data, temp_data->AngledHeadersRequests.Size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3242 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3243 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3244 |
// Important: data must be fed left to right |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3245 |
void ImGui::TableAngledHeadersRowEx(ImGuiID row_id, float angle, float max_label_width, const ImGuiTableHeaderData* data, int data_count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3246 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3247 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3248 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3249 |
ImGuiWindow* window = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3250 |
ImDrawList* draw_list = window->DrawList; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3251 |
IM_ASSERT(table != NULL && "Need to call TableHeadersRow() after BeginTable()!"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3252 |
IM_ASSERT(table->CurrentRow == -1 && "Must be first row"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3253 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3254 |
if (max_label_width == 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3255 |
max_label_width = TableGetHeaderAngledMaxLabelWidth(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3256 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3257 |
// Angle argument expressed in (-IM_PI/2 .. +IM_PI/2) as it is easier to think about for user. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3258 |
const bool flip_label = (angle < 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3259 |
angle -= IM_PI * 0.5f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3260 |
const float cos_a = ImCos(angle); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3261 |
const float sin_a = ImSin(angle); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3262 |
const float label_cos_a = flip_label ? ImCos(angle + IM_PI) : cos_a; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3263 |
const float label_sin_a = flip_label ? ImSin(angle + IM_PI) : sin_a; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3264 |
const ImVec2 unit_right = ImVec2(cos_a, sin_a); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3265 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3266 |
// Calculate our base metrics and set angled headers data _before_ the first call to TableNextRow() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3267 |
// FIXME-STYLE: Would it be better for user to submit 'max_label_width' or 'row_height' ? One can be derived from the other. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3268 |
const float header_height = g.FontSize + g.Style.CellPadding.x * 2.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3269 |
const float row_height = ImTrunc(ImFabs(ImRotate(ImVec2(max_label_width, flip_label ? +header_height : -header_height), cos_a, sin_a).y)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3270 |
table->AngledHeadersHeight = row_height; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3271 |
table->AngledHeadersSlope = (sin_a != 0.0f) ? (cos_a / sin_a) : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3272 |
const ImVec2 header_angled_vector = unit_right * (row_height / -sin_a); // vector from bottom-left to top-left, and from bottom-right to top-right |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3273 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3274 |
// Declare row, override and draw our own background |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3275 |
TableNextRow(ImGuiTableRowFlags_Headers, row_height); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3276 |
TableNextColumn(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3277 |
const ImRect row_r(table->WorkRect.Min.x, table->BgClipRect.Min.y, table->WorkRect.Max.x, table->RowPosY2); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3278 |
table->DrawSplitter->SetCurrentChannel(draw_list, TABLE_DRAW_CHANNEL_BG0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3279 |
float clip_rect_min_x = table->BgClipRect.Min.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3280 |
if (table->FreezeColumnsCount > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3281 |
clip_rect_min_x = ImMax(clip_rect_min_x, table->Columns[table->FreezeColumnsCount - 1].MaxX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3282 |
TableSetBgColor(ImGuiTableBgTarget_RowBg0, 0); // Cancel |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3283 |
PushClipRect(table->BgClipRect.Min, table->BgClipRect.Max, false); // Span all columns |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3284 |
draw_list->AddRectFilled(ImVec2(table->BgClipRect.Min.x, row_r.Min.y), ImVec2(table->BgClipRect.Max.x, row_r.Max.y), GetColorU32(ImGuiCol_TableHeaderBg, 0.25f)); // FIXME-STYLE: Change row background with an arbitrary color. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3285 |
PushClipRect(ImVec2(clip_rect_min_x, table->BgClipRect.Min.y), table->BgClipRect.Max, true); // Span all columns |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3286 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3287 |
ButtonBehavior(row_r, row_id, NULL, NULL); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3288 |
KeepAliveID(row_id); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3289 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3290 |
const float ascent_scaled = g.Font->Ascent * g.FontScale; // FIXME: Standardize those scaling factors better |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3291 |
const float line_off_for_ascent_x = (ImMax((g.FontSize - ascent_scaled) * 0.5f, 0.0f) / -sin_a) * (flip_label ? -1.0f : 1.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3292 |
const ImVec2 padding = g.Style.CellPadding; // We will always use swapped component |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3293 |
const ImVec2 align = g.Style.TableAngledHeadersTextAlign; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3294 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3295 |
// Draw background and labels in first pass, then all borders. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3296 |
float max_x = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3297 |
for (int pass = 0; pass < 2; pass++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3298 |
for (int order_n = 0; order_n < data_count; order_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3299 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3300 |
const ImGuiTableHeaderData* request = &data[order_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3301 |
const int column_n = request->Index; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3302 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3303 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3304 |
ImVec2 bg_shape[4]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3305 |
bg_shape[0] = ImVec2(column->MaxX, row_r.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3306 |
bg_shape[1] = ImVec2(column->MinX, row_r.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3307 |
bg_shape[2] = bg_shape[1] + header_angled_vector; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3308 |
bg_shape[3] = bg_shape[0] + header_angled_vector; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3309 |
if (pass == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3310 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3311 |
// Draw shape |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3312 |
draw_list->AddQuadFilled(bg_shape[0], bg_shape[1], bg_shape[2], bg_shape[3], request->BgColor0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3313 |
draw_list->AddQuadFilled(bg_shape[0], bg_shape[1], bg_shape[2], bg_shape[3], request->BgColor1); // Optional highlight |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3314 |
max_x = ImMax(max_x, bg_shape[3].x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3315 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3316 |
// Draw label |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3317 |
// - First draw at an offset where RenderTextXXX() function won't meddle with applying current ClipRect, then transform to final offset. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3318 |
// - Handle multiple lines manually, as we want each lines to follow on the horizontal border, rather than see a whole block rotated. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3319 |
const char* label_name = TableGetColumnName(table, column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3320 |
const char* label_name_end = FindRenderedTextEnd(label_name); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3321 |
const float line_off_step_x = (g.FontSize / -sin_a); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3322 |
const int label_lines = ImTextCountLines(label_name, label_name_end); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3323 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3324 |
// Left<>Right alignment |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3325 |
float line_off_curr_x = flip_label ? (label_lines - 1) * line_off_step_x : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3326 |
float line_off_for_align_x = ImMax((((column->MaxX - column->MinX) - padding.x * 2.0f) - (label_lines * line_off_step_x)), 0.0f) * align.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3327 |
line_off_curr_x += line_off_for_align_x - line_off_for_ascent_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3328 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3329 |
// Register header width |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3330 |
column->ContentMaxXHeadersUsed = column->ContentMaxXHeadersIdeal = column->WorkMinX + ImCeil(label_lines * line_off_step_x - line_off_for_align_x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3331 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3332 |
while (label_name < label_name_end) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3333 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3334 |
const char* label_name_eol = strchr(label_name, '\n'); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3335 |
if (label_name_eol == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3336 |
label_name_eol = label_name_end; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3337 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3338 |
// FIXME: Individual line clipping for right-most column is broken for negative angles. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3339 |
ImVec2 label_size = CalcTextSize(label_name, label_name_eol); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3340 |
float clip_width = max_label_width - padding.y; // Using padding.y*2.0f would be symmetrical but hide more text. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3341 |
float clip_height = ImMin(label_size.y, column->ClipRect.Max.x - column->WorkMinX - line_off_curr_x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3342 |
ImRect clip_r(window->ClipRect.Min, window->ClipRect.Min + ImVec2(clip_width, clip_height)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3343 |
int vtx_idx_begin = draw_list->_VtxCurrentIdx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3344 |
PushStyleColor(ImGuiCol_Text, request->TextColor); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3345 |
RenderTextEllipsis(draw_list, clip_r.Min, clip_r.Max, clip_r.Max.x, clip_r.Max.x, label_name, label_name_eol, &label_size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3346 |
PopStyleColor(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3347 |
int vtx_idx_end = draw_list->_VtxCurrentIdx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3348 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3349 |
// Up<>Down alignment |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3350 |
const float available_space = ImMax(clip_width - label_size.x + ImAbs(padding.x * cos_a) * 2.0f - ImAbs(padding.y * sin_a) * 2.0f, 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3351 |
const float vertical_offset = available_space * align.y * (flip_label ? -1.0f : 1.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3352 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3353 |
// Rotate and offset label |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3354 |
ImVec2 pivot_in = ImVec2(window->ClipRect.Min.x - vertical_offset, window->ClipRect.Min.y + label_size.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3355 |
ImVec2 pivot_out = ImVec2(column->WorkMinX, row_r.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3356 |
line_off_curr_x += flip_label ? -line_off_step_x : line_off_step_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3357 |
pivot_out += unit_right * padding.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3358 |
if (flip_label) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3359 |
pivot_out += unit_right * (clip_width - ImMax(0.0f, clip_width - label_size.x)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3360 |
pivot_out.x += flip_label ? line_off_curr_x + line_off_step_x : line_off_curr_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3361 |
ShadeVertsTransformPos(draw_list, vtx_idx_begin, vtx_idx_end, pivot_in, label_cos_a, label_sin_a, pivot_out); // Rotate and offset |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3362 |
//if (g.IO.KeyShift) { ImDrawList* fg_dl = GetForegroundDrawList(); vtx_idx_begin = fg_dl->_VtxCurrentIdx; fg_dl->AddRect(clip_r.Min, clip_r.Max, IM_COL32(0, 255, 0, 255), 0.0f, 0, 1.0f); ShadeVertsTransformPos(fg_dl, vtx_idx_begin, fg_dl->_VtxCurrentIdx, pivot_in, label_cos_a, label_sin_a, pivot_out); } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3363 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3364 |
label_name = label_name_eol + 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3365 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3366 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3367 |
if (pass == 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3368 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3369 |
// Draw border |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3370 |
draw_list->AddLine(bg_shape[0], bg_shape[3], TableGetColumnBorderCol(table, order_n, column_n)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3371 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3372 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3373 |
PopClipRect(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3374 |
PopClipRect(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3375 |
table->TempData->AngledHeadersExtraWidth = ImMax(0.0f, max_x - table->Columns[table->RightMostEnabledColumn].MaxX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3376 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3377 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3378 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3379 |
// [SECTION] Tables: Context Menu |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3380 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3381 |
// - TableOpenContextMenu() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3382 |
// - TableBeginContextMenuPopup() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3383 |
// - TableDrawDefaultContextMenu() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3384 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3385 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3386 |
// Use -1 to open menu not specific to a given column. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3387 |
void ImGui::TableOpenContextMenu(int column_n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3388 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3389 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3390 |
ImGuiTable* table = g.CurrentTable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3391 |
if (column_n == -1 && table->CurrentColumn != -1) // When called within a column automatically use this one (for consistency) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3392 |
column_n = table->CurrentColumn; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3393 |
if (column_n == table->ColumnsCount) // To facilitate using with TableGetHoveredColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3394 |
column_n = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3395 |
IM_ASSERT(column_n >= -1 && column_n < table->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3396 |
if (table->Flags & (ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3397 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3398 |
table->IsContextPopupOpen = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3399 |
table->ContextPopupColumn = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3400 |
table->InstanceInteracted = table->InstanceCurrent; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3401 |
const ImGuiID context_menu_id = ImHashStr("##ContextMenu", 0, table->ID); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3402 |
OpenPopupEx(context_menu_id, ImGuiPopupFlags_None); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3403 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3404 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3405 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3406 |
bool ImGui::TableBeginContextMenuPopup(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3407 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3408 |
if (!table->IsContextPopupOpen || table->InstanceCurrent != table->InstanceInteracted) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3409 |
return false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3410 |
const ImGuiID context_menu_id = ImHashStr("##ContextMenu", 0, table->ID); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3411 |
if (BeginPopupEx(context_menu_id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3412 |
return true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3413 |
table->IsContextPopupOpen = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3414 |
return false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3415 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3416 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3417 |
// Output context menu into current window (generally a popup) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3418 |
// FIXME-TABLE: Ideally this should be writable by the user. Full programmatic access to that data? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3419 |
// Sections to display are pulled from 'flags_for_section_to_display', which is typically == table->Flags. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3420 |
// - ImGuiTableFlags_Resizable -> display Sizing menu items |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3421 |
// - ImGuiTableFlags_Reorderable -> display "Reset Order" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3422 |
////- ImGuiTableFlags_Sortable -> display sorting options (disabled) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3423 |
// - ImGuiTableFlags_Hideable -> display columns visibility menu items |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3424 |
// It means if you have a custom context menus you can call this section and omit some sections, and add your own. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3425 |
void ImGui::TableDrawDefaultContextMenu(ImGuiTable* table, ImGuiTableFlags flags_for_section_to_display) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3426 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3427 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3428 |
ImGuiWindow* window = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3429 |
if (window->SkipItems) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3430 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3431 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3432 |
bool want_separator = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3433 |
const int column_n = (table->ContextPopupColumn >= 0 && table->ContextPopupColumn < table->ColumnsCount) ? table->ContextPopupColumn : -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3434 |
ImGuiTableColumn* column = (column_n != -1) ? &table->Columns[column_n] : NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3435 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3436 |
// Sizing |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3437 |
if (flags_for_section_to_display & ImGuiTableFlags_Resizable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3438 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3439 |
if (column != NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3440 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3441 |
const bool can_resize = !(column->Flags & ImGuiTableColumnFlags_NoResize) && column->IsEnabled; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3442 |
if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableSizeOne), NULL, false, can_resize)) // "###SizeOne" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3443 |
TableSetColumnWidthAutoSingle(table, column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3444 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3445 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3446 |
const char* size_all_desc; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3447 |
if (table->ColumnsEnabledFixedCount == table->ColumnsEnabledCount && (table->Flags & ImGuiTableFlags_SizingMask_) != ImGuiTableFlags_SizingFixedSame) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3448 |
size_all_desc = LocalizeGetMsg(ImGuiLocKey_TableSizeAllFit); // "###SizeAll" All fixed |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3449 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3450 |
size_all_desc = LocalizeGetMsg(ImGuiLocKey_TableSizeAllDefault); // "###SizeAll" All stretch or mixed |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3451 |
if (MenuItem(size_all_desc, NULL)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3452 |
TableSetColumnWidthAutoAll(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3453 |
want_separator = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3454 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3455 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3456 |
// Ordering |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3457 |
if (flags_for_section_to_display & ImGuiTableFlags_Reorderable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3458 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3459 |
if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetOrder), NULL, false, !table->IsDefaultDisplayOrder)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3460 |
table->IsResetDisplayOrderRequest = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3461 |
want_separator = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3462 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3463 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3464 |
// Reset all (should work but seems unnecessary/noisy to expose?) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3465 |
//if (MenuItem("Reset all")) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3466 |
// table->IsResetAllRequest = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3467 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3468 |
// Sorting |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3469 |
// (modify TableOpenContextMenu() to add _Sortable flag if enabling this) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3470 |
#if 0 |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3471 |
if ((flags_for_section_to_display & ImGuiTableFlags_Sortable) && column != NULL && (column->Flags & ImGuiTableColumnFlags_NoSort) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3472 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3473 |
if (want_separator) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3474 |
Separator(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3475 |
want_separator = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3476 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3477 |
bool append_to_sort_specs = g.IO.KeyShift; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3478 |
if (MenuItem("Sort in Ascending Order", NULL, column->SortOrder != -1 && column->SortDirection == ImGuiSortDirection_Ascending, (column->Flags & ImGuiTableColumnFlags_NoSortAscending) == 0)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3479 |
TableSetColumnSortDirection(table, column_n, ImGuiSortDirection_Ascending, append_to_sort_specs); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3480 |
if (MenuItem("Sort in Descending Order", NULL, column->SortOrder != -1 && column->SortDirection == ImGuiSortDirection_Descending, (column->Flags & ImGuiTableColumnFlags_NoSortDescending) == 0)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3481 |
TableSetColumnSortDirection(table, column_n, ImGuiSortDirection_Descending, append_to_sort_specs); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3482 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3483 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3484 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3485 |
// Hiding / Visibility |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3486 |
if (flags_for_section_to_display & ImGuiTableFlags_Hideable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3487 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3488 |
if (want_separator) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3489 |
Separator(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3490 |
want_separator = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3491 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3492 |
PushItemFlag(ImGuiItemFlags_AutoClosePopups, false); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3493 |
for (int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3494 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3495 |
ImGuiTableColumn* other_column = &table->Columns[other_column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3496 |
if (other_column->Flags & ImGuiTableColumnFlags_Disabled) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3497 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3498 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3499 |
const char* name = TableGetColumnName(table, other_column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3500 |
if (name == NULL || name[0] == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3501 |
name = "<Unknown>"; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3502 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3503 |
// Make sure we can't hide the last active column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3504 |
bool menu_item_active = (other_column->Flags & ImGuiTableColumnFlags_NoHide) ? false : true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3505 |
if (other_column->IsUserEnabled && table->ColumnsEnabledCount <= 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3506 |
menu_item_active = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3507 |
if (MenuItem(name, NULL, other_column->IsUserEnabled, menu_item_active)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3508 |
other_column->IsUserEnabledNextFrame = !other_column->IsUserEnabled; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3509 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3510 |
PopItemFlag(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3511 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3512 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3513 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3514 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3515 |
// [SECTION] Tables: Settings (.ini data) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3516 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3517 |
// FIXME: The binding/finding/creating flow are too confusing. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3518 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3519 |
// - TableSettingsInit() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3520 |
// - TableSettingsCalcChunkSize() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3521 |
// - TableSettingsCreate() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3522 |
// - TableSettingsFindByID() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3523 |
// - TableGetBoundSettings() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3524 |
// - TableResetSettings() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3525 |
// - TableSaveSettings() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3526 |
// - TableLoadSettings() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3527 |
// - TableSettingsHandler_ClearAll() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3528 |
// - TableSettingsHandler_ApplyAll() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3529 |
// - TableSettingsHandler_ReadOpen() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3530 |
// - TableSettingsHandler_ReadLine() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3531 |
// - TableSettingsHandler_WriteAll() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3532 |
// - TableSettingsInstallHandler() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3533 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3534 |
// [Init] 1: TableSettingsHandler_ReadXXXX() Load and parse .ini file into TableSettings. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3535 |
// [Main] 2: TableLoadSettings() When table is created, bind Table to TableSettings, serialize TableSettings data into Table. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3536 |
// [Main] 3: TableSaveSettings() When table properties are modified, serialize Table data into bound or new TableSettings, mark .ini as dirty. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3537 |
// [Main] 4: TableSettingsHandler_WriteAll() When .ini file is dirty (which can come from other source), save TableSettings into .ini file. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3538 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3539 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3540 |
// Clear and initialize empty settings instance |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3541 |
static void TableSettingsInit(ImGuiTableSettings* settings, ImGuiID id, int columns_count, int columns_count_max) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3542 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3543 |
IM_PLACEMENT_NEW(settings) ImGuiTableSettings(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3544 |
ImGuiTableColumnSettings* settings_column = settings->GetColumnSettings(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3545 |
for (int n = 0; n < columns_count_max; n++, settings_column++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3546 |
IM_PLACEMENT_NEW(settings_column) ImGuiTableColumnSettings(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3547 |
settings->ID = id; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3548 |
settings->ColumnsCount = (ImGuiTableColumnIdx)columns_count; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3549 |
settings->ColumnsCountMax = (ImGuiTableColumnIdx)columns_count_max; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3550 |
settings->WantApply = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3551 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3552 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3553 |
static size_t TableSettingsCalcChunkSize(int columns_count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3554 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3555 |
return sizeof(ImGuiTableSettings) + (size_t)columns_count * sizeof(ImGuiTableColumnSettings); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3556 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3557 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3558 |
ImGuiTableSettings* ImGui::TableSettingsCreate(ImGuiID id, int columns_count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3559 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3560 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3561 |
ImGuiTableSettings* settings = g.SettingsTables.alloc_chunk(TableSettingsCalcChunkSize(columns_count)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3562 |
TableSettingsInit(settings, id, columns_count, columns_count); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3563 |
return settings; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3564 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3565 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3566 |
// Find existing settings |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3567 |
ImGuiTableSettings* ImGui::TableSettingsFindByID(ImGuiID id) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3568 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3569 |
// FIXME-OPT: Might want to store a lookup map for this? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3570 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3571 |
for (ImGuiTableSettings* settings = g.SettingsTables.begin(); settings != NULL; settings = g.SettingsTables.next_chunk(settings)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3572 |
if (settings->ID == id) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3573 |
return settings; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3574 |
return NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3575 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3576 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3577 |
// Get settings for a given table, NULL if none |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3578 |
ImGuiTableSettings* ImGui::TableGetBoundSettings(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3579 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3580 |
if (table->SettingsOffset != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3581 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3582 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3583 |
ImGuiTableSettings* settings = g.SettingsTables.ptr_from_offset(table->SettingsOffset); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3584 |
IM_ASSERT(settings->ID == table->ID); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3585 |
if (settings->ColumnsCountMax >= table->ColumnsCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3586 |
return settings; // OK |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3587 |
settings->ID = 0; // Invalidate storage, we won't fit because of a count change |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3588 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3589 |
return NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3590 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3591 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3592 |
// Restore initial state of table (with or without saved settings) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3593 |
void ImGui::TableResetSettings(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3594 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3595 |
table->IsInitializing = table->IsSettingsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3596 |
table->IsResetAllRequest = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3597 |
table->IsSettingsRequestLoad = false; // Don't reload from ini |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3598 |
table->SettingsLoadedFlags = ImGuiTableFlags_None; // Mark as nothing loaded so our initialized data becomes authoritative |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3599 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3600 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3601 |
void ImGui::TableSaveSettings(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3602 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3603 |
table->IsSettingsDirty = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3604 |
if (table->Flags & ImGuiTableFlags_NoSavedSettings) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3605 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3606 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3607 |
// Bind or create settings data |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3608 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3609 |
ImGuiTableSettings* settings = TableGetBoundSettings(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3610 |
if (settings == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3611 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3612 |
settings = TableSettingsCreate(table->ID, table->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3613 |
table->SettingsOffset = g.SettingsTables.offset_from_ptr(settings); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3614 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3615 |
settings->ColumnsCount = (ImGuiTableColumnIdx)table->ColumnsCount; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3616 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3617 |
// Serialize ImGuiTable/ImGuiTableColumn into ImGuiTableSettings/ImGuiTableColumnSettings |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3618 |
IM_ASSERT(settings->ID == table->ID); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3619 |
IM_ASSERT(settings->ColumnsCount == table->ColumnsCount && settings->ColumnsCountMax >= settings->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3620 |
ImGuiTableColumn* column = table->Columns.Data; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3621 |
ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3622 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3623 |
bool save_ref_scale = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3624 |
settings->SaveFlags = ImGuiTableFlags_None; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3625 |
for (int n = 0; n < table->ColumnsCount; n++, column++, column_settings++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3626 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3627 |
const float width_or_weight = (column->Flags & ImGuiTableColumnFlags_WidthStretch) ? column->StretchWeight : column->WidthRequest; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3628 |
column_settings->WidthOrWeight = width_or_weight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3629 |
column_settings->Index = (ImGuiTableColumnIdx)n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3630 |
column_settings->DisplayOrder = column->DisplayOrder; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3631 |
column_settings->SortOrder = column->SortOrder; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3632 |
column_settings->SortDirection = column->SortDirection; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3633 |
column_settings->IsEnabled = column->IsUserEnabled; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3634 |
column_settings->IsStretch = (column->Flags & ImGuiTableColumnFlags_WidthStretch) ? 1 : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3635 |
if ((column->Flags & ImGuiTableColumnFlags_WidthStretch) == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3636 |
save_ref_scale = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3637 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3638 |
// We skip saving some data in the .ini file when they are unnecessary to restore our state. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3639 |
// Note that fixed width where initial width was derived from auto-fit will always be saved as InitStretchWeightOrWidth will be 0.0f. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3640 |
// FIXME-TABLE: We don't have logic to easily compare SortOrder to DefaultSortOrder yet so it's always saved when present. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3641 |
if (width_or_weight != column->InitStretchWeightOrWidth) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3642 |
settings->SaveFlags |= ImGuiTableFlags_Resizable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3643 |
if (column->DisplayOrder != n) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3644 |
settings->SaveFlags |= ImGuiTableFlags_Reorderable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3645 |
if (column->SortOrder != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3646 |
settings->SaveFlags |= ImGuiTableFlags_Sortable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3647 |
if (column->IsUserEnabled != ((column->Flags & ImGuiTableColumnFlags_DefaultHide) == 0)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3648 |
settings->SaveFlags |= ImGuiTableFlags_Hideable; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3649 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3650 |
settings->SaveFlags &= table->Flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3651 |
settings->RefScale = save_ref_scale ? table->RefScale : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3652 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3653 |
MarkIniSettingsDirty(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3654 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3655 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3656 |
void ImGui::TableLoadSettings(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3657 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3658 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3659 |
table->IsSettingsRequestLoad = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3660 |
if (table->Flags & ImGuiTableFlags_NoSavedSettings) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3661 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3662 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3663 |
// Bind settings |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3664 |
ImGuiTableSettings* settings; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3665 |
if (table->SettingsOffset == -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3666 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3667 |
settings = TableSettingsFindByID(table->ID); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3668 |
if (settings == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3669 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3670 |
if (settings->ColumnsCount != table->ColumnsCount) // Allow settings if columns count changed. We could otherwise decide to return... |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3671 |
table->IsSettingsDirty = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3672 |
table->SettingsOffset = g.SettingsTables.offset_from_ptr(settings); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3673 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3674 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3675 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3676 |
settings = TableGetBoundSettings(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3677 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3678 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3679 |
table->SettingsLoadedFlags = settings->SaveFlags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3680 |
table->RefScale = settings->RefScale; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3681 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3682 |
// Serialize ImGuiTableSettings/ImGuiTableColumnSettings into ImGuiTable/ImGuiTableColumn |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3683 |
ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3684 |
ImU64 display_order_mask = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3685 |
for (int data_n = 0; data_n < settings->ColumnsCount; data_n++, column_settings++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3686 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3687 |
int column_n = column_settings->Index; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3688 |
if (column_n < 0 || column_n >= table->ColumnsCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3689 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3690 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3691 |
ImGuiTableColumn* column = &table->Columns[column_n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3692 |
if (settings->SaveFlags & ImGuiTableFlags_Resizable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3693 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3694 |
if (column_settings->IsStretch) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3695 |
column->StretchWeight = column_settings->WidthOrWeight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3696 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3697 |
column->WidthRequest = column_settings->WidthOrWeight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3698 |
column->AutoFitQueue = 0x00; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3699 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3700 |
if (settings->SaveFlags & ImGuiTableFlags_Reorderable) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3701 |
column->DisplayOrder = column_settings->DisplayOrder; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3702 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3703 |
column->DisplayOrder = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3704 |
display_order_mask |= (ImU64)1 << column->DisplayOrder; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3705 |
column->IsUserEnabled = column->IsUserEnabledNextFrame = column_settings->IsEnabled; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3706 |
column->SortOrder = column_settings->SortOrder; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3707 |
column->SortDirection = column_settings->SortDirection; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3708 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3709 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3710 |
// Validate and fix invalid display order data |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3711 |
const ImU64 expected_display_order_mask = (settings->ColumnsCount == 64) ? ~0 : ((ImU64)1 << settings->ColumnsCount) - 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3712 |
if (display_order_mask != expected_display_order_mask) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3713 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3714 |
table->Columns[column_n].DisplayOrder = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3715 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3716 |
// Rebuild index |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3717 |
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3718 |
table->DisplayOrderToIndex[table->Columns[column_n].DisplayOrder] = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3719 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3720 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3721 |
static void TableSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3722 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3723 |
ImGuiContext& g = *ctx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3724 |
for (int i = 0; i != g.Tables.GetMapSize(); i++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3725 |
if (ImGuiTable* table = g.Tables.TryGetMapData(i)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3726 |
table->SettingsOffset = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3727 |
g.SettingsTables.clear(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3728 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3729 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3730 |
// Apply to existing windows (if any) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3731 |
static void TableSettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3732 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3733 |
ImGuiContext& g = *ctx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3734 |
for (int i = 0; i != g.Tables.GetMapSize(); i++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3735 |
if (ImGuiTable* table = g.Tables.TryGetMapData(i)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3736 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3737 |
table->IsSettingsRequestLoad = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3738 |
table->SettingsOffset = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3739 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3740 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3741 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3742 |
static void* TableSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3743 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3744 |
ImGuiID id = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3745 |
int columns_count = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3746 |
if (sscanf(name, "0x%08X,%d", &id, &columns_count) < 2) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3747 |
return NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3748 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3749 |
if (ImGuiTableSettings* settings = ImGui::TableSettingsFindByID(id)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3750 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3751 |
if (settings->ColumnsCountMax >= columns_count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3752 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3753 |
TableSettingsInit(settings, id, columns_count, settings->ColumnsCountMax); // Recycle |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3754 |
return settings; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3755 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3756 |
settings->ID = 0; // Invalidate storage, we won't fit because of a count change |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3757 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3758 |
return ImGui::TableSettingsCreate(id, columns_count); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3759 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3760 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3761 |
static void TableSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3762 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3763 |
// "Column 0 UserID=0x42AD2D21 Width=100 Visible=1 Order=0 Sort=0v" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3764 |
ImGuiTableSettings* settings = (ImGuiTableSettings*)entry; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3765 |
float f = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3766 |
int column_n = 0, r = 0, n = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3767 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3768 |
if (sscanf(line, "RefScale=%f", &f) == 1) { settings->RefScale = f; return; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3769 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3770 |
if (sscanf(line, "Column %d%n", &column_n, &r) == 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3771 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3772 |
if (column_n < 0 || column_n >= settings->ColumnsCount) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3773 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3774 |
line = ImStrSkipBlank(line + r); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3775 |
char c = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3776 |
ImGuiTableColumnSettings* column = settings->GetColumnSettings() + column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3777 |
column->Index = (ImGuiTableColumnIdx)column_n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3778 |
if (sscanf(line, "UserID=0x%08X%n", (ImU32*)&n, &r)==1) { line = ImStrSkipBlank(line + r); column->UserID = (ImGuiID)n; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3779 |
if (sscanf(line, "Width=%d%n", &n, &r) == 1) { line = ImStrSkipBlank(line + r); column->WidthOrWeight = (float)n; column->IsStretch = 0; settings->SaveFlags |= ImGuiTableFlags_Resizable; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3780 |
if (sscanf(line, "Weight=%f%n", &f, &r) == 1) { line = ImStrSkipBlank(line + r); column->WidthOrWeight = f; column->IsStretch = 1; settings->SaveFlags |= ImGuiTableFlags_Resizable; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3781 |
if (sscanf(line, "Visible=%d%n", &n, &r) == 1) { line = ImStrSkipBlank(line + r); column->IsEnabled = (ImU8)n; settings->SaveFlags |= ImGuiTableFlags_Hideable; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3782 |
if (sscanf(line, "Order=%d%n", &n, &r) == 1) { line = ImStrSkipBlank(line + r); column->DisplayOrder = (ImGuiTableColumnIdx)n; settings->SaveFlags |= ImGuiTableFlags_Reorderable; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3783 |
if (sscanf(line, "Sort=%d%c%n", &n, &c, &r) == 2) { line = ImStrSkipBlank(line + r); column->SortOrder = (ImGuiTableColumnIdx)n; column->SortDirection = (c == '^') ? ImGuiSortDirection_Descending : ImGuiSortDirection_Ascending; settings->SaveFlags |= ImGuiTableFlags_Sortable; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3784 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3785 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3786 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3787 |
static void TableSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3788 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3789 |
ImGuiContext& g = *ctx; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3790 |
for (ImGuiTableSettings* settings = g.SettingsTables.begin(); settings != NULL; settings = g.SettingsTables.next_chunk(settings)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3791 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3792 |
if (settings->ID == 0) // Skip ditched settings |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3793 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3794 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3795 |
// TableSaveSettings() may clear some of those flags when we establish that the data can be stripped |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3796 |
// (e.g. Order was unchanged) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3797 |
const bool save_size = (settings->SaveFlags & ImGuiTableFlags_Resizable) != 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3798 |
const bool save_visible = (settings->SaveFlags & ImGuiTableFlags_Hideable) != 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3799 |
const bool save_order = (settings->SaveFlags & ImGuiTableFlags_Reorderable) != 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3800 |
const bool save_sort = (settings->SaveFlags & ImGuiTableFlags_Sortable) != 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3801 |
if (!save_size && !save_visible && !save_order && !save_sort) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3802 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3803 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3804 |
buf->reserve(buf->size() + 30 + settings->ColumnsCount * 50); // ballpark reserve |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3805 |
buf->appendf("[%s][0x%08X,%d]\n", handler->TypeName, settings->ID, settings->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3806 |
if (settings->RefScale != 0.0f) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3807 |
buf->appendf("RefScale=%g\n", settings->RefScale); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3808 |
ImGuiTableColumnSettings* column = settings->GetColumnSettings(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3809 |
for (int column_n = 0; column_n < settings->ColumnsCount; column_n++, column++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3810 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3811 |
// "Column 0 UserID=0x42AD2D21 Width=100 Visible=1 Order=0 Sort=0v" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3812 |
bool save_column = column->UserID != 0 || save_size || save_visible || save_order || (save_sort && column->SortOrder != -1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3813 |
if (!save_column) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3814 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3815 |
buf->appendf("Column %-2d", column_n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3816 |
if (column->UserID != 0) { buf->appendf(" UserID=%08X", column->UserID); } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3817 |
if (save_size && column->IsStretch) { buf->appendf(" Weight=%.4f", column->WidthOrWeight); } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3818 |
if (save_size && !column->IsStretch) { buf->appendf(" Width=%d", (int)column->WidthOrWeight); } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3819 |
if (save_visible) { buf->appendf(" Visible=%d", column->IsEnabled); } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3820 |
if (save_order) { buf->appendf(" Order=%d", column->DisplayOrder); } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3821 |
if (save_sort && column->SortOrder != -1) { buf->appendf(" Sort=%d%c", column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ? 'v' : '^'); } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3822 |
buf->append("\n"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3823 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3824 |
buf->append("\n"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3825 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3826 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3827 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3828 |
void ImGui::TableSettingsAddSettingsHandler() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3829 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3830 |
ImGuiSettingsHandler ini_handler; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3831 |
ini_handler.TypeName = "Table"; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3832 |
ini_handler.TypeHash = ImHashStr("Table"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3833 |
ini_handler.ClearAllFn = TableSettingsHandler_ClearAll; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3834 |
ini_handler.ReadOpenFn = TableSettingsHandler_ReadOpen; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3835 |
ini_handler.ReadLineFn = TableSettingsHandler_ReadLine; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3836 |
ini_handler.ApplyAllFn = TableSettingsHandler_ApplyAll; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3837 |
ini_handler.WriteAllFn = TableSettingsHandler_WriteAll; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3838 |
AddSettingsHandler(&ini_handler); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3839 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3840 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3841 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3842 |
// [SECTION] Tables: Garbage Collection |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3843 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3844 |
// - TableRemove() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3845 |
// - TableGcCompactTransientBuffers() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3846 |
// - TableGcCompactSettings() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3847 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3848 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3849 |
// Remove Table (currently only used by TestEngine) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3850 |
void ImGui::TableRemove(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3851 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3852 |
//IMGUI_DEBUG_PRINT("TableRemove() id=0x%08X\n", table->ID); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3853 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3854 |
int table_idx = g.Tables.GetIndex(table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3855 |
//memset(table->RawData.Data, 0, table->RawData.size_in_bytes()); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3856 |
//memset(table, 0, sizeof(ImGuiTable)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3857 |
g.Tables.Remove(table->ID, table); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3858 |
g.TablesLastTimeActive[table_idx] = -1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3859 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3860 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3861 |
// Free up/compact internal Table buffers for when it gets unused |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3862 |
void ImGui::TableGcCompactTransientBuffers(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3863 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3864 |
//IMGUI_DEBUG_PRINT("TableGcCompactTransientBuffers() id=0x%08X\n", table->ID); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3865 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3866 |
IM_ASSERT(table->MemoryCompacted == false); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3867 |
table->SortSpecs.Specs = NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3868 |
table->SortSpecsMulti.clear(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3869 |
table->IsSortSpecsDirty = true; // FIXME: In theory shouldn't have to leak into user performing a sort on resume. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3870 |
table->ColumnsNames.clear(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3871 |
table->MemoryCompacted = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3872 |
for (int n = 0; n < table->ColumnsCount; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3873 |
table->Columns[n].NameOffset = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3874 |
g.TablesLastTimeActive[g.Tables.GetIndex(table)] = -1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3875 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3876 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3877 |
void ImGui::TableGcCompactTransientBuffers(ImGuiTableTempData* temp_data) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3878 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3879 |
temp_data->DrawSplitter.ClearFreeMemory(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3880 |
temp_data->LastTimeActive = -1.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3881 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3882 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3883 |
// Compact and remove unused settings data (currently only used by TestEngine) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3884 |
void ImGui::TableGcCompactSettings() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3885 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3886 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3887 |
int required_memory = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3888 |
for (ImGuiTableSettings* settings = g.SettingsTables.begin(); settings != NULL; settings = g.SettingsTables.next_chunk(settings)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3889 |
if (settings->ID != 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3890 |
required_memory += (int)TableSettingsCalcChunkSize(settings->ColumnsCount); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3891 |
if (required_memory == g.SettingsTables.Buf.Size) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3892 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3893 |
ImChunkStream<ImGuiTableSettings> new_chunk_stream; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3894 |
new_chunk_stream.Buf.reserve(required_memory); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3895 |
for (ImGuiTableSettings* settings = g.SettingsTables.begin(); settings != NULL; settings = g.SettingsTables.next_chunk(settings)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3896 |
if (settings->ID != 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3897 |
memcpy(new_chunk_stream.alloc_chunk(TableSettingsCalcChunkSize(settings->ColumnsCount)), settings, TableSettingsCalcChunkSize(settings->ColumnsCount)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3898 |
g.SettingsTables.swap(new_chunk_stream); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3899 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3900 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3901 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3902 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3903 |
// [SECTION] Tables: Debugging |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3904 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3905 |
// - DebugNodeTable() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3906 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3907 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3908 |
#ifndef IMGUI_DISABLE_DEBUG_TOOLS |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3909 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3910 |
static const char* DebugNodeTableGetSizingPolicyDesc(ImGuiTableFlags sizing_policy) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3911 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3912 |
sizing_policy &= ImGuiTableFlags_SizingMask_; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3913 |
if (sizing_policy == ImGuiTableFlags_SizingFixedFit) { return "FixedFit"; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3914 |
if (sizing_policy == ImGuiTableFlags_SizingFixedSame) { return "FixedSame"; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3915 |
if (sizing_policy == ImGuiTableFlags_SizingStretchProp) { return "StretchProp"; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3916 |
if (sizing_policy == ImGuiTableFlags_SizingStretchSame) { return "StretchSame"; } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3917 |
return "N/A"; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3918 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3919 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3920 |
void ImGui::DebugNodeTable(ImGuiTable* table) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3921 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3922 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3923 |
const bool is_active = (table->LastFrameActive >= g.FrameCount - 2); // Note that fully clipped early out scrolling tables will appear as inactive here. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3924 |
if (!is_active) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3925 |
bool open = TreeNode(table, "Table 0x%08X (%d columns, in '%s')%s", table->ID, table->ColumnsCount, table->OuterWindow->Name, is_active ? "" : " *Inactive*"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3926 |
if (!is_active) { PopStyleColor(); } |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3927 |
if (IsItemHovered()) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3928 |
GetForegroundDrawList()->AddRect(table->OuterRect.Min, table->OuterRect.Max, IM_COL32(255, 255, 0, 255)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3929 |
if (IsItemVisible() && table->HoveredColumnBody != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3930 |
GetForegroundDrawList()->AddRect(GetItemRectMin(), GetItemRectMax(), IM_COL32(255, 255, 0, 255)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3931 |
if (!open) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3932 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3933 |
if (table->InstanceCurrent > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3934 |
Text("** %d instances of same table! Some data below will refer to last instance.", table->InstanceCurrent + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3935 |
if (g.IO.ConfigDebugIsDebuggerPresent) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3936 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3937 |
if (DebugBreakButton("**DebugBreak**", "in BeginTable()")) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3938 |
g.DebugBreakInTable = table->ID; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3939 |
SameLine(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3940 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3941 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3942 |
bool clear_settings = SmallButton("Clear settings"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3943 |
BulletText("OuterRect: Pos: (%.1f,%.1f) Size: (%.1f,%.1f) Sizing: '%s'", table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.GetWidth(), table->OuterRect.GetHeight(), DebugNodeTableGetSizingPolicyDesc(table->Flags)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3944 |
BulletText("ColumnsGivenWidth: %.1f, ColumnsAutoFitWidth: %.1f, InnerWidth: %.1f%s", table->ColumnsGivenWidth, table->ColumnsAutoFitWidth, table->InnerWidth, table->InnerWidth == 0.0f ? " (auto)" : ""); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3945 |
BulletText("CellPaddingX: %.1f, CellSpacingX: %.1f/%.1f, OuterPaddingX: %.1f", table->CellPaddingX, table->CellSpacingX1, table->CellSpacingX2, table->OuterPaddingX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3946 |
BulletText("HoveredColumnBody: %d, HoveredColumnBorder: %d", table->HoveredColumnBody, table->HoveredColumnBorder); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3947 |
BulletText("ResizedColumn: %d, ReorderColumn: %d, HeldHeaderColumn: %d", table->ResizedColumn, table->ReorderColumn, table->HeldHeaderColumn); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3948 |
for (int n = 0; n < table->InstanceCurrent + 1; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3949 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3950 |
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3951 |
BulletText("Instance %d: HoveredRow: %d, LastOuterHeight: %.2f", n, table_instance->HoveredRowLast, table_instance->LastOuterHeight); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3952 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3953 |
//BulletText("BgDrawChannels: %d/%d", 0, table->BgDrawChannelUnfrozen); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3954 |
float sum_weights = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3955 |
for (int n = 0; n < table->ColumnsCount; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3956 |
if (table->Columns[n].Flags & ImGuiTableColumnFlags_WidthStretch) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3957 |
sum_weights += table->Columns[n].StretchWeight; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3958 |
for (int n = 0; n < table->ColumnsCount; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3959 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3960 |
ImGuiTableColumn* column = &table->Columns[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3961 |
const char* name = TableGetColumnName(table, n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3962 |
char buf[512]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3963 |
ImFormatString(buf, IM_ARRAYSIZE(buf), |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3964 |
"Column %d order %d '%s': offset %+.2f to %+.2f%s\n" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3965 |
"Enabled: %d, VisibleX/Y: %d/%d, RequestOutput: %d, SkipItems: %d, DrawChannels: %d,%d\n" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3966 |
"WidthGiven: %.1f, Request/Auto: %.1f/%.1f, StretchWeight: %.3f (%.1f%%)\n" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3967 |
"MinX: %.1f, MaxX: %.1f (%+.1f), ClipRect: %.1f to %.1f (+%.1f)\n" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3968 |
"ContentWidth: %.1f,%.1f, HeadersUsed/Ideal %.1f/%.1f\n" |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3969 |
"Sort: %d%s, UserID: 0x%08X, Flags: 0x%04X: %s%s%s..", |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3970 |
n, column->DisplayOrder, name, column->MinX - table->WorkRect.Min.x, column->MaxX - table->WorkRect.Min.x, (n < table->FreezeColumnsRequest) ? " (Frozen)" : "", |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3971 |
column->IsEnabled, column->IsVisibleX, column->IsVisibleY, column->IsRequestOutput, column->IsSkipItems, column->DrawChannelFrozen, column->DrawChannelUnfrozen, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3972 |
column->WidthGiven, column->WidthRequest, column->WidthAuto, column->StretchWeight, column->StretchWeight > 0.0f ? (column->StretchWeight / sum_weights) * 100.0f : 0.0f, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3973 |
column->MinX, column->MaxX, column->MaxX - column->MinX, column->ClipRect.Min.x, column->ClipRect.Max.x, column->ClipRect.Max.x - column->ClipRect.Min.x, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3974 |
column->ContentMaxXFrozen - column->WorkMinX, column->ContentMaxXUnfrozen - column->WorkMinX, column->ContentMaxXHeadersUsed - column->WorkMinX, column->ContentMaxXHeadersIdeal - column->WorkMinX, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3975 |
column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ? " (Asc)" : (column->SortDirection == ImGuiSortDirection_Descending) ? " (Des)" : "", column->UserID, column->Flags, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3976 |
(column->Flags & ImGuiTableColumnFlags_WidthStretch) ? "WidthStretch " : "", |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3977 |
(column->Flags & ImGuiTableColumnFlags_WidthFixed) ? "WidthFixed " : "", |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3978 |
(column->Flags & ImGuiTableColumnFlags_NoResize) ? "NoResize " : ""); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3979 |
Bullet(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3980 |
Selectable(buf); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3981 |
if (IsItemHovered()) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3982 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3983 |
ImRect r(column->MinX, table->OuterRect.Min.y, column->MaxX, table->OuterRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3984 |
GetForegroundDrawList()->AddRect(r.Min, r.Max, IM_COL32(255, 255, 0, 255)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3985 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3986 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3987 |
if (ImGuiTableSettings* settings = TableGetBoundSettings(table)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3988 |
DebugNodeTableSettings(settings); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3989 |
if (clear_settings) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3990 |
table->IsResetAllRequest = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3991 |
TreePop(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3992 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3993 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3994 |
void ImGui::DebugNodeTableSettings(ImGuiTableSettings* settings) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3995 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3996 |
if (!TreeNode((void*)(intptr_t)settings->ID, "Settings 0x%08X (%d columns)", settings->ID, settings->ColumnsCount)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3997 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3998 |
BulletText("SaveFlags: 0x%08X", settings->SaveFlags); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
3999 |
BulletText("ColumnsCount: %d (max %d)", settings->ColumnsCount, settings->ColumnsCountMax); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4000 |
for (int n = 0; n < settings->ColumnsCount; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4001 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4002 |
ImGuiTableColumnSettings* column_settings = &settings->GetColumnSettings()[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4003 |
ImGuiSortDirection sort_dir = (column_settings->SortOrder != -1) ? (ImGuiSortDirection)column_settings->SortDirection : ImGuiSortDirection_None; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4004 |
BulletText("Column %d Order %d SortOrder %d %s Vis %d %s %7.3f UserID 0x%08X", |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4005 |
n, column_settings->DisplayOrder, column_settings->SortOrder, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4006 |
(sort_dir == ImGuiSortDirection_Ascending) ? "Asc" : (sort_dir == ImGuiSortDirection_Descending) ? "Des" : "---", |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4007 |
column_settings->IsEnabled, column_settings->IsStretch ? "Weight" : "Width ", column_settings->WidthOrWeight, column_settings->UserID); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4008 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4009 |
TreePop(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4010 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4011 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4012 |
#else // #ifndef IMGUI_DISABLE_DEBUG_TOOLS |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4013 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4014 |
void ImGui::DebugNodeTable(ImGuiTable*) {} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4015 |
void ImGui::DebugNodeTableSettings(ImGuiTableSettings*) {} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4016 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4017 |
#endif |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4018 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4019 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4020 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4021 |
// [SECTION] Columns, BeginColumns, EndColumns, etc. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4022 |
// (This is a legacy API, prefer using BeginTable/EndTable!) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4023 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4024 |
// FIXME: sizing is lossy when columns width is very small (default width may turn negative etc.) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4025 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4026 |
// - SetWindowClipRectBeforeSetChannel() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4027 |
// - GetColumnIndex() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4028 |
// - GetColumnsCount() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4029 |
// - GetColumnOffset() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4030 |
// - GetColumnWidth() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4031 |
// - SetColumnOffset() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4032 |
// - SetColumnWidth() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4033 |
// - PushColumnClipRect() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4034 |
// - PushColumnsBackground() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4035 |
// - PopColumnsBackground() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4036 |
// - FindOrCreateColumns() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4037 |
// - GetColumnsID() [Internal] |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4038 |
// - BeginColumns() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4039 |
// - NextColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4040 |
// - EndColumns() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4041 |
// - Columns() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4042 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4043 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4044 |
// [Internal] Small optimization to avoid calls to PopClipRect/SetCurrentChannel/PushClipRect in sequences, |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4045 |
// they would meddle many times with the underlying ImDrawCmd. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4046 |
// Instead, we do a preemptive overwrite of clipping rectangle _without_ altering the command-buffer and let |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4047 |
// the subsequent single call to SetCurrentChannel() does it things once. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4048 |
void ImGui::SetWindowClipRectBeforeSetChannel(ImGuiWindow* window, const ImRect& clip_rect) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4049 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4050 |
ImVec4 clip_rect_vec4 = clip_rect.ToVec4(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4051 |
window->ClipRect = clip_rect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4052 |
window->DrawList->_CmdHeader.ClipRect = clip_rect_vec4; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4053 |
window->DrawList->_ClipRectStack.Data[window->DrawList->_ClipRectStack.Size - 1] = clip_rect_vec4; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4054 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4055 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4056 |
int ImGui::GetColumnIndex() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4057 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4058 |
ImGuiWindow* window = GetCurrentWindowRead(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4059 |
return window->DC.CurrentColumns ? window->DC.CurrentColumns->Current : 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4060 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4061 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4062 |
int ImGui::GetColumnsCount() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4063 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4064 |
ImGuiWindow* window = GetCurrentWindowRead(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4065 |
return window->DC.CurrentColumns ? window->DC.CurrentColumns->Count : 1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4066 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4067 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4068 |
float ImGui::GetColumnOffsetFromNorm(const ImGuiOldColumns* columns, float offset_norm) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4069 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4070 |
return offset_norm * (columns->OffMaxX - columns->OffMinX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4071 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4072 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4073 |
float ImGui::GetColumnNormFromOffset(const ImGuiOldColumns* columns, float offset) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4074 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4075 |
return offset / (columns->OffMaxX - columns->OffMinX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4076 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4077 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4078 |
static const float COLUMNS_HIT_RECT_HALF_THICKNESS = 4.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4079 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4080 |
static float GetDraggedColumnOffset(ImGuiOldColumns* columns, int column_index) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4081 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4082 |
// Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4083 |
// window creates a feedback loop because we store normalized positions. So while dragging we enforce absolute positioning. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4084 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4085 |
ImGuiWindow* window = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4086 |
IM_ASSERT(column_index > 0); // We are not supposed to drag column 0. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4087 |
IM_ASSERT(g.ActiveId == columns->ID + ImGuiID(column_index)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4088 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4089 |
float x = g.IO.MousePos.x - g.ActiveIdClickOffset.x + ImTrunc(COLUMNS_HIT_RECT_HALF_THICKNESS * g.CurrentDpiScale) - window->Pos.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4090 |
x = ImMax(x, ImGui::GetColumnOffset(column_index - 1) + g.Style.ColumnsMinSpacing); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4091 |
if ((columns->Flags & ImGuiOldColumnFlags_NoPreserveWidths)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4092 |
x = ImMin(x, ImGui::GetColumnOffset(column_index + 1) - g.Style.ColumnsMinSpacing); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4093 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4094 |
return x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4095 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4096 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4097 |
float ImGui::GetColumnOffset(int column_index) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4098 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4099 |
ImGuiWindow* window = GetCurrentWindowRead(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4100 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4101 |
if (columns == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4102 |
return 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4103 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4104 |
if (column_index < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4105 |
column_index = columns->Current; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4106 |
IM_ASSERT(column_index < columns->Columns.Size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4107 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4108 |
const float t = columns->Columns[column_index].OffsetNorm; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4109 |
const float x_offset = ImLerp(columns->OffMinX, columns->OffMaxX, t); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4110 |
return x_offset; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4111 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4112 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4113 |
static float GetColumnWidthEx(ImGuiOldColumns* columns, int column_index, bool before_resize = false) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4114 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4115 |
if (column_index < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4116 |
column_index = columns->Current; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4117 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4118 |
float offset_norm; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4119 |
if (before_resize) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4120 |
offset_norm = columns->Columns[column_index + 1].OffsetNormBeforeResize - columns->Columns[column_index].OffsetNormBeforeResize; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4121 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4122 |
offset_norm = columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4123 |
return ImGui::GetColumnOffsetFromNorm(columns, offset_norm); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4124 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4125 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4126 |
float ImGui::GetColumnWidth(int column_index) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4127 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4128 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4129 |
ImGuiWindow* window = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4130 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4131 |
if (columns == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4132 |
return GetContentRegionAvail().x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4133 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4134 |
if (column_index < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4135 |
column_index = columns->Current; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4136 |
return GetColumnOffsetFromNorm(columns, columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4137 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4138 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4139 |
void ImGui::SetColumnOffset(int column_index, float offset) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4140 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4141 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4142 |
ImGuiWindow* window = g.CurrentWindow; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4143 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4144 |
IM_ASSERT(columns != NULL); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4145 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4146 |
if (column_index < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4147 |
column_index = columns->Current; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4148 |
IM_ASSERT(column_index < columns->Columns.Size); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4149 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4150 |
const bool preserve_width = !(columns->Flags & ImGuiOldColumnFlags_NoPreserveWidths) && (column_index < columns->Count - 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4151 |
const float width = preserve_width ? GetColumnWidthEx(columns, column_index, columns->IsBeingResized) : 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4152 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4153 |
if (!(columns->Flags & ImGuiOldColumnFlags_NoForceWithinWindow)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4154 |
offset = ImMin(offset, columns->OffMaxX - g.Style.ColumnsMinSpacing * (columns->Count - column_index)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4155 |
columns->Columns[column_index].OffsetNorm = GetColumnNormFromOffset(columns, offset - columns->OffMinX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4156 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4157 |
if (preserve_width) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4158 |
SetColumnOffset(column_index + 1, offset + ImMax(g.Style.ColumnsMinSpacing, width)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4159 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4160 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4161 |
void ImGui::SetColumnWidth(int column_index, float width) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4162 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4163 |
ImGuiWindow* window = GetCurrentWindowRead(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4164 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4165 |
IM_ASSERT(columns != NULL); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4166 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4167 |
if (column_index < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4168 |
column_index = columns->Current; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4169 |
SetColumnOffset(column_index + 1, GetColumnOffset(column_index) + width); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4170 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4171 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4172 |
void ImGui::PushColumnClipRect(int column_index) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4173 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4174 |
ImGuiWindow* window = GetCurrentWindowRead(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4175 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4176 |
if (column_index < 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4177 |
column_index = columns->Current; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4178 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4179 |
ImGuiOldColumnData* column = &columns->Columns[column_index]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4180 |
PushClipRect(column->ClipRect.Min, column->ClipRect.Max, false); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4181 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4182 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4183 |
// Get into the columns background draw command (which is generally the same draw command as before we called BeginColumns) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4184 |
void ImGui::PushColumnsBackground() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4185 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4186 |
ImGuiWindow* window = GetCurrentWindowRead(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4187 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4188 |
if (columns->Count == 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4189 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4190 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4191 |
// Optimization: avoid SetCurrentChannel() + PushClipRect() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4192 |
columns->HostBackupClipRect = window->ClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4193 |
SetWindowClipRectBeforeSetChannel(window, columns->HostInitialClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4194 |
columns->Splitter.SetCurrentChannel(window->DrawList, 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4195 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4196 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4197 |
void ImGui::PopColumnsBackground() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4198 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4199 |
ImGuiWindow* window = GetCurrentWindowRead(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4200 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4201 |
if (columns->Count == 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4202 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4203 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4204 |
// Optimization: avoid PopClipRect() + SetCurrentChannel() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4205 |
SetWindowClipRectBeforeSetChannel(window, columns->HostBackupClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4206 |
columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4207 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4208 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4209 |
ImGuiOldColumns* ImGui::FindOrCreateColumns(ImGuiWindow* window, ImGuiID id) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4210 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4211 |
// We have few columns per window so for now we don't need bother much with turning this into a faster lookup. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4212 |
for (int n = 0; n < window->ColumnsStorage.Size; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4213 |
if (window->ColumnsStorage[n].ID == id) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4214 |
return &window->ColumnsStorage[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4215 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4216 |
window->ColumnsStorage.push_back(ImGuiOldColumns()); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4217 |
ImGuiOldColumns* columns = &window->ColumnsStorage.back(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4218 |
columns->ID = id; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4219 |
return columns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4220 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4221 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4222 |
ImGuiID ImGui::GetColumnsID(const char* str_id, int columns_count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4223 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4224 |
ImGuiWindow* window = GetCurrentWindow(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4225 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4226 |
// Differentiate column ID with an arbitrary prefix for cases where users name their columns set the same as another widget. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4227 |
// In addition, when an identifier isn't explicitly provided we include the number of columns in the hash to make it uniquer. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4228 |
PushID(0x11223347 + (str_id ? 0 : columns_count)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4229 |
ImGuiID id = window->GetID(str_id ? str_id : "columns"); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4230 |
PopID(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4231 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4232 |
return id; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4233 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4234 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4235 |
void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiOldColumnFlags flags) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4236 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4237 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4238 |
ImGuiWindow* window = GetCurrentWindow(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4239 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4240 |
IM_ASSERT(columns_count >= 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4241 |
IM_ASSERT(window->DC.CurrentColumns == NULL); // Nested columns are currently not supported |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4242 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4243 |
// Acquire storage for the columns set |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4244 |
ImGuiID id = GetColumnsID(str_id, columns_count); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4245 |
ImGuiOldColumns* columns = FindOrCreateColumns(window, id); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4246 |
IM_ASSERT(columns->ID == id); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4247 |
columns->Current = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4248 |
columns->Count = columns_count; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4249 |
columns->Flags = flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4250 |
window->DC.CurrentColumns = columns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4251 |
window->DC.NavIsScrollPushableX = false; // Shortcut for NavUpdateCurrentWindowIsScrollPushableX(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4252 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4253 |
columns->HostCursorPosY = window->DC.CursorPos.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4254 |
columns->HostCursorMaxPosX = window->DC.CursorMaxPos.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4255 |
columns->HostInitialClipRect = window->ClipRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4256 |
columns->HostBackupParentWorkRect = window->ParentWorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4257 |
window->ParentWorkRect = window->WorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4258 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4259 |
// Set state for first column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4260 |
// We aim so that the right-most column will have the same clipping width as other after being clipped by parent ClipRect |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4261 |
const float column_padding = g.Style.ItemSpacing.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4262 |
const float half_clip_extend_x = ImTrunc(ImMax(window->WindowPadding.x * 0.5f, window->WindowBorderSize)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4263 |
const float max_1 = window->WorkRect.Max.x + column_padding - ImMax(column_padding - window->WindowPadding.x, 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4264 |
const float max_2 = window->WorkRect.Max.x + half_clip_extend_x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4265 |
columns->OffMinX = window->DC.Indent.x - column_padding + ImMax(column_padding - window->WindowPadding.x, 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4266 |
columns->OffMaxX = ImMax(ImMin(max_1, max_2) - window->Pos.x, columns->OffMinX + 1.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4267 |
columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4268 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4269 |
// Clear data if columns count changed |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4270 |
if (columns->Columns.Size != 0 && columns->Columns.Size != columns_count + 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4271 |
columns->Columns.resize(0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4272 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4273 |
// Initialize default widths |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4274 |
columns->IsFirstFrame = (columns->Columns.Size == 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4275 |
if (columns->Columns.Size == 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4276 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4277 |
columns->Columns.reserve(columns_count + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4278 |
for (int n = 0; n < columns_count + 1; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4279 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4280 |
ImGuiOldColumnData column; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4281 |
column.OffsetNorm = n / (float)columns_count; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4282 |
columns->Columns.push_back(column); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4283 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4284 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4285 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4286 |
for (int n = 0; n < columns_count; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4287 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4288 |
// Compute clipping rectangle |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4289 |
ImGuiOldColumnData* column = &columns->Columns[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4290 |
float clip_x1 = IM_ROUND(window->Pos.x + GetColumnOffset(n)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4291 |
float clip_x2 = IM_ROUND(window->Pos.x + GetColumnOffset(n + 1) - 1.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4292 |
column->ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4293 |
column->ClipRect.ClipWithFull(window->ClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4294 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4295 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4296 |
if (columns->Count > 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4297 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4298 |
columns->Splitter.Split(window->DrawList, 1 + columns->Count); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4299 |
columns->Splitter.SetCurrentChannel(window->DrawList, 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4300 |
PushColumnClipRect(0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4301 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4302 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4303 |
// We don't generally store Indent.x inside ColumnsOffset because it may be manipulated by the user. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4304 |
float offset_0 = GetColumnOffset(columns->Current); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4305 |
float offset_1 = GetColumnOffset(columns->Current + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4306 |
float width = offset_1 - offset_0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4307 |
PushItemWidth(width * 0.65f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4308 |
window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4309 |
window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4310 |
window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4311 |
window->WorkRect.Max.y = window->ContentRegionRect.Max.y; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4312 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4313 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4314 |
void ImGui::NextColumn() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4315 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4316 |
ImGuiWindow* window = GetCurrentWindow(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4317 |
if (window->SkipItems || window->DC.CurrentColumns == NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4318 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4319 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4320 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4321 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4322 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4323 |
if (columns->Count == 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4324 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4325 |
window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4326 |
IM_ASSERT(columns->Current == 0); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4327 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4328 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4329 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4330 |
// Next column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4331 |
if (++columns->Current == columns->Count) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4332 |
columns->Current = 0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4333 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4334 |
PopItemWidth(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4335 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4336 |
// Optimization: avoid PopClipRect() + SetCurrentChannel() + PushClipRect() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4337 |
// (which would needlessly attempt to update commands in the wrong channel, then pop or overwrite them), |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4338 |
ImGuiOldColumnData* column = &columns->Columns[columns->Current]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4339 |
SetWindowClipRectBeforeSetChannel(window, column->ClipRect); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4340 |
columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4341 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4342 |
const float column_padding = g.Style.ItemSpacing.x; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4343 |
columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4344 |
if (columns->Current > 0) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4345 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4346 |
// Columns 1+ ignore IndentX (by canceling it out) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4347 |
// FIXME-COLUMNS: Unnecessary, could be locked? |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4348 |
window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + column_padding; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4349 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4350 |
else |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4351 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4352 |
// New row/line: column 0 honor IndentX. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4353 |
window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4354 |
window->DC.IsSameLine = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4355 |
columns->LineMinY = columns->LineMaxY; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4356 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4357 |
window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4358 |
window->DC.CursorPos.y = columns->LineMinY; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4359 |
window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4360 |
window->DC.CurrLineTextBaseOffset = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4361 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4362 |
// FIXME-COLUMNS: Share code with BeginColumns() - move code on columns setup. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4363 |
float offset_0 = GetColumnOffset(columns->Current); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4364 |
float offset_1 = GetColumnOffset(columns->Current + 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4365 |
float width = offset_1 - offset_0; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4366 |
PushItemWidth(width * 0.65f); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4367 |
window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4368 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4369 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4370 |
void ImGui::EndColumns() |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4371 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4372 |
ImGuiContext& g = *GImGui; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4373 |
ImGuiWindow* window = GetCurrentWindow(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4374 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4375 |
IM_ASSERT(columns != NULL); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4376 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4377 |
PopItemWidth(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4378 |
if (columns->Count > 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4379 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4380 |
PopClipRect(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4381 |
columns->Splitter.Merge(window->DrawList); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4382 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4383 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4384 |
const ImGuiOldColumnFlags flags = columns->Flags; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4385 |
columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4386 |
window->DC.CursorPos.y = columns->LineMaxY; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4387 |
if (!(flags & ImGuiOldColumnFlags_GrowParentContentsSize)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4388 |
window->DC.CursorMaxPos.x = columns->HostCursorMaxPosX; // Restore cursor max pos, as columns don't grow parent |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4389 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4390 |
// Draw columns borders and handle resize |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4391 |
// The IsBeingResized flag ensure we preserve pre-resize columns width so back-and-forth are not lossy |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4392 |
bool is_being_resized = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4393 |
if (!(flags & ImGuiOldColumnFlags_NoBorder) && !window->SkipItems) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4394 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4395 |
// We clip Y boundaries CPU side because very long triangles are mishandled by some GPU drivers. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4396 |
const float y1 = ImMax(columns->HostCursorPosY, window->ClipRect.Min.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4397 |
const float y2 = ImMin(window->DC.CursorPos.y, window->ClipRect.Max.y); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4398 |
int dragging_column = -1; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4399 |
for (int n = 1; n < columns->Count; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4400 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4401 |
ImGuiOldColumnData* column = &columns->Columns[n]; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4402 |
float x = window->Pos.x + GetColumnOffset(n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4403 |
const ImGuiID column_id = columns->ID + ImGuiID(n); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4404 |
const float column_hit_hw = ImTrunc(COLUMNS_HIT_RECT_HALF_THICKNESS * g.CurrentDpiScale); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4405 |
const ImRect column_hit_rect(ImVec2(x - column_hit_hw, y1), ImVec2(x + column_hit_hw, y2)); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4406 |
if (!ItemAdd(column_hit_rect, column_id, NULL, ImGuiItemFlags_NoNav)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4407 |
continue; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4408 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4409 |
bool hovered = false, held = false; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4410 |
if (!(flags & ImGuiOldColumnFlags_NoResize)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4411 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4412 |
ButtonBehavior(column_hit_rect, column_id, &hovered, &held); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4413 |
if (hovered || held) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4414 |
SetMouseCursor(ImGuiMouseCursor_ResizeEW); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4415 |
if (held && !(column->Flags & ImGuiOldColumnFlags_NoResize)) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4416 |
dragging_column = n; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4417 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4418 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4419 |
// Draw column |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4420 |
const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4421 |
const float xi = IM_TRUNC(x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4422 |
window->DrawList->AddLine(ImVec2(xi, y1 + 1.0f), ImVec2(xi, y2), col); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4423 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4424 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4425 |
// Apply dragging after drawing the column lines, so our rendered lines are in sync with how items were displayed during the frame. |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4426 |
if (dragging_column != -1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4427 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4428 |
if (!columns->IsBeingResized) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4429 |
for (int n = 0; n < columns->Count + 1; n++) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4430 |
columns->Columns[n].OffsetNormBeforeResize = columns->Columns[n].OffsetNorm; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4431 |
columns->IsBeingResized = is_being_resized = true; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4432 |
float x = GetDraggedColumnOffset(columns, dragging_column); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4433 |
SetColumnOffset(dragging_column, x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4434 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4435 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4436 |
columns->IsBeingResized = is_being_resized; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4437 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4438 |
window->WorkRect = window->ParentWorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4439 |
window->ParentWorkRect = columns->HostBackupParentWorkRect; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4440 |
window->DC.CurrentColumns = NULL; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4441 |
window->DC.ColumnsOffset.x = 0.0f; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4442 |
window->DC.CursorPos.x = IM_TRUNC(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4443 |
NavUpdateCurrentWindowIsScrollPushableX(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4444 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4445 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4446 |
void ImGui::Columns(int columns_count, const char* id, bool borders) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4447 |
{ |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4448 |
ImGuiWindow* window = GetCurrentWindow(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4449 |
IM_ASSERT(columns_count >= 1); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4450 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4451 |
ImGuiOldColumnFlags flags = (borders ? 0 : ImGuiOldColumnFlags_NoBorder); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4452 |
//flags |= ImGuiOldColumnFlags_NoPreserveWidths; // NB: Legacy behavior |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4453 |
ImGuiOldColumns* columns = window->DC.CurrentColumns; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4454 |
if (columns != NULL && columns->Count == columns_count && columns->Flags == flags) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4455 |
return; |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4456 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4457 |
if (columns != NULL) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4458 |
EndColumns(); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4459 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4460 |
if (columns_count != 1) |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4461 |
BeginColumns(id, columns_count, flags); |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4462 |
} |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4463 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4464 |
//------------------------------------------------------------------------- |
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4465 |
|
| 1193b4be |
Poul Sander |
2025-02-03 21:28 |
4466 |
#endif // #ifndef IMGUI_DISABLE |
|
|
1970-01-01 00:00 |
4467 |
|