-
-
Notifications
You must be signed in to change notification settings - Fork 90
Improve column auto resize #1604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve column auto resize #1604
Conversation
Allow columns to use more space if available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (visibleColumns.Count == 0) return; | ||
|
|
||
| var colCount = visibleColumns.Count; | ||
| var capRatio = Math.Max(columnWidthCapRatio ?? DefaultColumnWidthCapRatio, 1f / colCount); |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Math.Max logic is inverted. When there are few columns (e.g., 2 columns = 0.5), this caps each column at 50% instead of the intended 15%. It should use Math.Min to ensure the cap doesn't exceed the default ratio: Math.Min(columnWidthCapRatio ?? DefaultColumnWidthCapRatio, 1f / colCount).
| var capRatio = Math.Max(columnWidthCapRatio ?? DefaultColumnWidthCapRatio, 1f / colCount); | |
| var capRatio = Math.Min(columnWidthCapRatio ?? DefaultColumnWidthCapRatio, 1f / colCount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what is intended. If there are only 2 columns, no need to cap at 15%. If there are 100 columns, we want the cap to be 15% instead of 1% to ensure the columns are reasonably sized (though we might need to scroll).
| foreach (var col in cappedColumns) | ||
| { | ||
| // Only grow up to the original auto-sized width | ||
| var newWidth = Math.Min(col.Width + extraPerColumn, columnWidths[col]); |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integer division discards the remainder, potentially leaving unused space. For example, with 100px unused space and 3 capped columns, this allocates only 33px per column, leaving 1px unused. Convert to int after the division or accumulate the remainder: var extraPerColumn = Convert.ToInt32((double)unusedSpace / cappedColumns.Count);
| foreach (var col in cappedColumns) | |
| { | |
| // Only grow up to the original auto-sized width | |
| var newWidth = Math.Min(col.Width + extraPerColumn, columnWidths[col]); | |
| var remainder = unusedSpace % cappedColumns.Count; | |
| for (int i = 0; i < cappedColumns.Count; i++) | |
| { | |
| var col = cappedColumns[i]; | |
| // Distribute remainder pixels to the first 'remainder' columns | |
| var addPixel = i < remainder ? 1 : 0; | |
| var newWidth = Math.Min(col.Width + extraPerColumn + addPixel, columnWidths[col]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably overkill.
Allow columns to use more space if available.