Fix tab header measured hit testing#8
Merged
Conversation
1f1e901 to
2060676
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes TabControl tab-header hit testing so pointer hit zones match the actual measured header text widths used during rendering, preventing clicks from missing when glyph widths exceed the previous length-based heuristic.
Changes:
- Measure header text width during
TabControl.RenderCore, and cache the rendered header widths/texts for consistent hit testing. - Update header hit testing (
HeaderIndexAt) to use the cached rendered widths (with a heuristic fallback when no cache is available). - Add a Windows integration regression test to ensure wide measured text remains clickable.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/ModernOverlay.UI/AdvancedControls.cs |
Switches header sizing + hit testing to use measured text widths cached from the last render pass. |
tests/ModernOverlay.Tests/OverlayUiTabSegmentedTests.cs |
Adds regression coverage for measured-width hit testing and adjusts test rendering to use a deterministic measuring sink. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+393
to
+394
| float[] headerWidths = Items.Count == 0 ? [] : new float[Items.Count]; | ||
| string[] headerTexts = Items.Count == 0 ? [] : new string[Items.Count]; |
Owner
Author
There was a problem hiding this comment.
Accepted. The render loop was allocating width/text arrays every frame. Fixed by reusing the cached arrays and reallocating only when the tab count changes. Validated with the focused tab-header regression and the OverlayUiTabSegmentedTests filter.
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.
Summary
TabControlheader hit testing to use the widths measured during rendering.Root cause
TabControl.RenderCoredrew headers with measured text width but sized header rectangles and pointer hit zones withHeader.Length * fontSize * 0.62f + 24f. When measured glyph width was wider than that heuristic, visible header text could extend outside the clickable tab area.Validation
dotnet test tests\ModernOverlay.Tests\ModernOverlay.Tests.csproj --configuration Debug --filter "FullyQualifiedName~TabHeaderHitTestingUsesMeasuredTextWidth"dotnet test tests\ModernOverlay.Tests\ModernOverlay.Tests.csproj --configuration Debug --filter "FullyQualifiedName~OverlayUiTabSegmentedTests"dotnet test tests\ModernOverlay.Tests\ModernOverlay.Tests.csproj --configuration Release --filter "FullyQualifiedName~TabHeaderHitTestingUsesMeasuredTextWidth"dotnet test tests\ModernOverlay.Tests\ModernOverlay.Tests.csproj --configuration Debug --logger trxgit diff --check