Skip to content

Fix tab header measured hit testing#8

Merged
SteffenCarlsen merged 2 commits into
mainfrom
feature/tab-measured-header-sizing
Jun 18, 2026
Merged

Fix tab header measured hit testing#8
SteffenCarlsen merged 2 commits into
mainfrom
feature/tab-measured-header-sizing

Conversation

@SteffenCarlsen

Copy link
Copy Markdown
Owner

Summary

  • Fix TabControl header hit testing to use the widths measured during rendering.
  • Cache rendered tab header widths/texts so pointer hit zones stay aligned with the visible header text.
  • Add a regression where wide measured text extends beyond the old heuristic header width.

Root cause

TabControl.RenderCore drew headers with measured text width but sized header rectangles and pointer hit zones with Header.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 trx
  • git diff --check

@SteffenCarlsen SteffenCarlsen force-pushed the feature/tab-measured-header-sizing branch from 1f1e901 to 2060676 Compare June 5, 2026 13:21
@SteffenCarlsen SteffenCarlsen marked this pull request as ready for review June 5, 2026 13:21
Copilot AI review requested due to automatic review settings June 5, 2026 13:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SteffenCarlsen SteffenCarlsen merged commit 7071bbf into main Jun 18, 2026
1 check passed
@SteffenCarlsen SteffenCarlsen deleted the feature/tab-measured-header-sizing branch June 18, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants