Skip to content

fix(StackPanel): Correct gap spacing when children are collapsed - #3298

Open
bai-chi-xing wants to merge 1 commit into
stride3d:masterfrom
bai-chi-xing:fix/stackpanel-scroll-gap
Open

fix(StackPanel): Correct gap spacing when children are collapsed#3298
bai-chi-xing wants to merge 1 commit into
stride3d:masterfrom
bai-chi-xing:fix/stackpanel-scroll-gap

Conversation

@bai-chi-xing

Copy link
Copy Markdown

PR Details

  • Introduce GetSafeChildAndGapSize method to replace GetSafeChildSize for proper gap handling
  • Modify measure logic to correctly compute gaps when children are collapsed
  • Update arrange logic to properly allocate gaps in the presence of collapsed elements
  • Fix gap handling in scrolling positioning calculations
  • Add test cases to verify support for collapsed child elements

My English is not very good, so this description was translated with AI — I hope it conveys my intention clearly.

This PR fixes a bug I discovered: when a StackPanel with a non-zero Gap is placed inside a ScrollViewer, dragging the scrollbar becomes janky and difficult to control.

While investigating, I noticed that gap handling was problematic in several places throughout StackPanel. When collapsed (non-occupying) children were present, gaps were still being included in both measure and arrange calculations — even the final DesiredSize was incorrect.

To fix this, I consolidated gap sizes into the preceding sibling element of each visible child (regardless of whether that sibling is collapsed or not). This ensures smooth scrolling behavior. However, this changed the meaning of ScrollPosition, which previously did not account for gaps at all. I've updated the XML documentation comments to clarify the new behavior and warn about potential pitfalls.

I've tested the changes locally and confirmed that the scrolling issue is resolved. Since these changes only affect gap handling, I extended the existing tests rather than adding new test files.

This is my first time submitting a PR, so please let me know if I've missed any guidelines or conventions. I'm happy to revise.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

…hildren

- Introduce GetSafeChildAndGapSize method to replace GetSafeChildSize for proper gap handling
- Modify measure logic to correctly compute gaps when children are collapsed
- Update arrange logic to properly allocate gaps in the presence of collapsed elements
- Fix gap handling in scrolling positioning calculations
- Add test cases to verify support for collapsed child elements
@bai-chi-xing

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

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.

1 participant