MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / TableSetColumnWidth

Method TableSetColumnWidth

KBotExt/imgui/imgui_tables.cpp:2144–2223  ·  view source on GitHub ↗

'width' = inner column width, without padding

Source from the content-addressed store, hash-verified

2142
2143// 'width' = inner column width, without padding
2144void ImGui::TableSetColumnWidth(int column_n, float width)
2145{
2146 ImGuiContext& g = *GImGui;
2147 ImGuiTable* table = g.CurrentTable;
2148 IM_ASSERT(table != NULL && table->IsLayoutLocked == false);
2149 IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
2150 ImGuiTableColumn* column_0 = &table->Columns[column_n];
2151 float column_0_width = width;
2152
2153 // Apply constraints early
2154 // Compare both requested and actual given width to avoid overwriting requested width when column is stuck (minimum size, bounded)
2155 IM_ASSERT(table->MinColumnWidth > 0.0f);
2156 const float min_width = table->MinColumnWidth;
2157 const float max_width = ImMax(min_width, TableGetMaxColumnWidth(table, column_n));
2158 column_0_width = ImClamp(column_0_width, min_width, max_width);
2159 if (column_0->WidthGiven == column_0_width || column_0->WidthRequest == column_0_width)
2160 return;
2161
2162 //IMGUI_DEBUG_PRINT("TableSetColumnWidth(%d, %.1f->%.1f)\n", column_0_idx, column_0->WidthGiven, column_0_width);
2163 ImGuiTableColumn* column_1 = (column_0->NextEnabledColumn != -1) ? &table->Columns[column_0->NextEnabledColumn] : NULL;
2164
2165 // In this surprisingly not simple because of how we support mixing Fixed and multiple Stretch columns.
2166 // - All fixed: easy.
2167 // - All stretch: easy.
2168 // - One or more fixed + one stretch: easy.
2169 // - One or more fixed + more than one stretch: tricky.
2170 // Qt when manual resize is enabled only supports a single _trailing_ stretch column, we support more cases here.
2171
2172 // When forwarding resize from Wn| to Fn+1| we need to be considerate of the _NoResize flag on Fn+1.
2173 // FIXME-TABLE: Find a way to rewrite all of this so interactions feel more consistent for the user.
2174 // Scenarios:
2175 // - F1 F2 F3 resize from F1| or F2| --> ok: alter ->WidthRequested of Fixed column. Subsequent columns will be offset.
2176 // - F1 F2 F3 resize from F3| --> ok: alter ->WidthRequested of Fixed column. If active, ScrollX extent can be altered.
2177 // - 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.
2178 // - F1 F2 W3 resize from W3| --> ok: no-op (disabled by Resize Rule 1)
2179 // - W1 W2 W3 resize from W1| or W2| --> ok
2180 // - W1 W2 W3 resize from W3| --> ok: no-op (disabled by Resize Rule 1)
2181 // - W1 F2 F3 resize from F3| --> ok: no-op (disabled by Resize Rule 1)
2182 // - W1 F2 resize from F2| --> ok: no-op (disabled by Resize Rule 1)
2183 // - W1 W2 F3 resize from W1| or W2| --> ok
2184 // - W1 F2 W3 resize from W1| or F2| --> ok
2185 // - F1 W2 F3 resize from W2| --> ok
2186 // - F1 W3 F2 resize from W3| --> ok
2187 // - W1 F2 F3 resize from W1| --> ok: equivalent to resizing |F2. F3 will not move.
2188 // - W1 F2 F3 resize from F2| --> ok
2189 // All resizes from a Wx columns are locking other columns.
2190
2191 // Possible improvements:
2192 // - 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.
2193 // - 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.
2194
2195 // [Resize Rule 1] Can't resize from right of right-most visible column if there is any Stretch column. Implemented in TableUpdateLayout().
2196
2197 // 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.
2198 // This is the preferred resize path
2199 if (column_0->Flags & ImGuiTableColumnFlags_WidthFixed)
2200 if (!column_1 || table->LeftMostStretchedColumn == -1 || table->Columns[table->LeftMostStretchedColumn].DisplayOrder >= column_0->DisplayOrder)
2201 {

Callers

nothing calls this directly

Calls 2

ImMaxFunction · 0.85
ImClampFunction · 0.85

Tested by

no test coverage detected