Repository navigation
table: Fit a column to its content on double-click of its resize handle - #3489
Merged
Merged
Conversation
miimsam
force-pushed
the
table-fit-column-to-content
branch
from
October 13, 2026 12:08
b36e234 to
aac32a0
Compare
Double-clicking a column's resize handle asks the new `TableDelegate::fit_column` hook for the width the column's content needs, adds the cell padding, clamps it to the column's min and max width and emits `ColumnWidthsChanged`. The hook returns `None` by default, so existing tables are unchanged. The width is rounded up to whole device pixels: layout rounds to the nearest device pixel, and text a fraction of a pixel wider than its cell is truncated. Also adds `TableState::fit_col` and `TableState::col_width`. The Data Table story fits its columns by measuring the same text its cells draw, and the docs cover the hook in both locales.
miimsam
force-pushed
the
table-fit-column-to-content
branch
from
October 13, 2026 12:28
aac32a0 to
bf30574
Compare
miimsam
marked this pull request as ready for review
October 13, 2026 12:30
Use table_cell_size for measurement and synchronize the story delegate size on size changes. Include the extra header inset for columns with custom padding. Co-authored-by: Codex <codex@openai.com>
huacnlee
enabled auto-merge (squash)
October 13, 2026 15:00
Member
|
Thank you, we need this feature very much. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Double-clicking a column's resize handle now fits the column to its content, as spreadsheets and macOS table views do. The table can't measure what a delegate draws, so it asks the new
TableDelegate::fit_columnhook for the content width. The table then adds the cell padding, limits the result to the column'smin_widthandmax_width, and emitsTableEvent::ColumnWidthsChangedwhen the width changes. The hook returnsNoneby default, so existing tables behave as before.The fitted width is rounded up to whole device pixels. Layout rounds widths to the nearest device pixel, and text even a fraction of a pixel wider than its cell gets truncated. Each part (content and both paddings) is rounded separately, and at fractional scale factors the content is bumped one more device pixel when dividing back lands just below it.
The second press of a double-click also starts a drag on the handle, which would snap the fitted edge back under the pointer. Resize drags on a fitted column are ignored until the next single press.
The Data Table story implements the hook. One
format_cellfunction now produces the text for bothrender_tdandfit_column, so a fit measures exactly what is drawn. English and Chinese docs describe the hook,fit_colandcol_width.Before:
Screen.Recording.2026-10-13.at.12.18.45.mov
After:
Screen.Recording.2026-10-13.at.12.11.33.mov
Public API
gpui-component
TableDelegate::fit_column(&mut self, col_ix: usize, window: &mut Window, cx: &mut Context<TableState<Self>>) -> Option<Pixels>: returns the width columncol_ix's content needs (widest cell or header, as drawn), orNoneto leave the column unchanged. Called on a double-click of the column's resize handle; returnsNoneby default.TableState::fit_col(&mut self, col_ix: usize, window: &mut Window, cx: &mut Context<Self>) -> bool: fits a column from code, the same as a double-click. Returns whether the delegate gave a width (falsefor a non-resizable column or aNoneanswer).TableState::col_width(&self, col_ix: usize) -> Option<Pixels>: the width a column is drawn at now, following drags and fits;Nonepast the last column.How to Test
cargo test -p gpui-component --test integration -- table_fit_column::Manually, in cargo run → Data Table:
Checklist
cargo runfor story tests related to the changes.Tested only on macOSAI-assisted: implementation, tests and documentation drafted with Claude Code, then reviewed and revised by me.