Repository navigation
feat: add AutoFitColumns and AutoFitColumnsAsync to fit every column in one call (#380) - #515
Open
michaelstonis wants to merge 4 commits into
Open
michaelstonis wants to merge 4 commits into
michaelstonis wants to merge 4 commits into
Conversation
| public void AllRows_FindsARowOutsideTheSample() | ||
| { | ||
| var grid = Grid(rows: 1000); | ||
| var items = (ObservableCollection<Row>)grid.ItemsSource!; |
Comment on lines
+71
to
+72
| foreach (var column in shown) | ||
| if (column.IsVisible && (wanted is null || wanted.Contains(column))) targets.Add(column); |
Comment on lines
+71
to
+72
| foreach (var column in shown) | ||
| if (column.IsVisible && (wanted is null || wanted.Contains(column))) targets.Add(column); |
This branch has not been deployed
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.
Closes #380.
Changes
Adds a grid-wide auto-fit: one call sizes every visible column (or the ones passed) to its header and content, makes the widths explicit and switches Star/Auto columns to
Fixed, exactly as a resize-grip double-click does for one column.KumikoLayoutEngine: newCalculateAutoFitWidth(column, source, ctx, style, firstVisibleRow, lastVisibleRow, KumikoAutoFitScope scope).AllRowswalks every row once per column, skips group header and summary rows (IsNonDataRow), reads display text throughKumikoSource.GetCellDisplayText(the cell text cache), reuses one measuring paint. Boolean, image, progress bar and selection columns and columns with a custom cell renderer fit their header only. Internal chunk helpers (MeasureAllRowsText,FinishAutoFitWidth) serve the async path.KumikoRenderer.AutoFit.cs(new partial file, delegates to the layout engine;KumikoRenderer.csis untouched):AutoFitColumns(...)andAutoFitColumnsAsync(...). The async variant measures about 2,000 cells per turn, yields withTask.Yield()(so the host's UI context keeps the source on its own thread), applies all widths at the end, throwsOperationCanceledExceptionleaving every width as it was, and restarts once if the view is rebuilt while measuring (second change returnsfalse).AutoFitColumns(scope = Sampled, columns = null)returnsfalsebefore the grid has a size;AutoFitColumnsAsync(scope = AllRows, columns = null, cancellationToken = default). The measuring-surface creation is now one privateAutoFitMeasurerhelper per host, shared with the existingOnAutoFitColumnRequested(grip double-click path unchanged in behavior; the input controller is not touched).LargeDataPagein both sample apps (AutoFitColumnsAsync(AllRows)).Public API added (recorded in
PublicAPI.Unshipped.txtfor Core, Maui, Uno):KumikoUI.Core.Models.KumikoAutoFitScope(Sampled,AllRows)KumikoRenderer.AutoFitColumns(IReadOnlyList<KumikoColumn>, KumikoSource, IDrawingContext, KumikoStyle, KumikoAutoFitScope) -> intKumikoRenderer.AutoFitColumnsAsync(..., KumikoAutoFitScope, CancellationToken) -> Task<bool>KumikoLayoutEngine.CalculateAutoFitWidth(..., int, int, KumikoAutoFitScope) -> floatKumikoDataGrid.AutoFitColumnsandAutoFitColumnsAsyncLeft for follow-up (issue marks them optional or open questions): the "Auto-fit all columns" header-menu item (needs a
KumikoInputController.ColumnMenuchange, which is off-limits for this batch), aColumnsAutoFittedevent, andICellRenderer.Measurefor template columns.Acceptance criteria
AutoFitColumnsfits every visible column (or the given ones) in one redraw, withSampledmatching today's double-click result (test compares per-columnAutoFitColumnwithAutoFitColumns(Sampled)).AllRowsmeasures every data row;AutoFitColumnsAsyncyields between 2,000-cell chunks (a test asserts the host queue is serviced between every chunk on 80,000 cells) and honors cancellation without leaving partial widths. A literal 100K-row responsiveness run on a real UI thread was not done; the guarantee is the chunk-and-yield design above.KumikoLayoutState.Capture/ApplyTo(tested in Core).tests/KumikoUI.Core.Tests/Rendering/AutoFitColumnsTests.cs(a new file next toColumnSizingTests/AutoFitTimingTests, which are unchanged) and MAUI host tests for sync, async and cancellation. No Uno host tests: the Uno grid cannot be constructed in the test project; the Uno host is a line-for-line mirror and is covered by the Core tests and a successful build.PublicAPI.Unshipped.txtupdated (by hand from the analyzer's RS0016 list, becauseeng/update-public-api.shemptied the Core file without refilling it in this environment; the diff is only the six/two added lines per project)._lastFirstRow/_lastLastRoware only read).Verification
dotnet build src/KumikoUI.Core,src/KumikoUI.SkiaSharp: 0 warnings, 0 errors.dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst: 0 warnings, 0 errors.dotnet build src/KumikoUI.Uno -f net10.0-desktop: 0 errors (two existing Uno0001 "not implemented in Uno" warnings in untouched files).dotnet build samples/SampleApp.Uno -f net10.0-desktop: 0 errors, 0 warnings.dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst: fails at restore with NU1605 (Microsoft.Maui.Controls 10.0.110 vs 10.0.41 downgrade), a package-version issue in the sample project that this change does not touch; the MAUI sample edit is a mirror of the Uno one and could not be compiled here.dotnet test tests/KumikoUI.Core.Tests: 4373 passed, 5 skipped, 0 failed (12 new tests; the async ones ran 5 times in a row without a failure).dotnet test tests/KumikoUI.Maui.Tests: 455 passed (6 new).dotnet test tests/KumikoUI.Uno.Tests: 321 passed.dotnet test tests/KumikoUI.SkiaSharp.Tests: 42 passed.Note for Foundations (#446)
The new
AutoFitColumns/AutoFitColumnsAsyncentry points live in a separate partial file,src/KumikoUI.Core/KumikoRenderer.AutoFit.cs, next to the shippedAutoFitColumn. They use the renderer's last-drawn visible row range, asAutoFitColumndoes, and contain no drawing code;KumikoRenderer.csis unchanged. The painter split should place them alongsideAutoFitColumn.kumikoandemployeesand declares the token source, so both documentation snippet projects build with 0 errors.