Fix border inner rounded clip#20647
Fix border inner rounded clip#20647wieslawsoltes wants to merge 16 commits intoAvaloniaUI:masterfrom
Conversation
|
You can test this PR using the following package version. |
|
You can test this PR using the following package version. |
|
Awesome! Thanks so much for picking this up. Will definitely dig into the details for my own experience as well. |
src/Avalonia.Controls/Border.cs
Outdated
| bool IVisualWithChildClip.TryGetChildClip(out RoundedRect clip) | ||
| { | ||
| var bounds = new Rect(Bounds.Size); | ||
| var keypoints = GeometryBuilder.CalculateRoundedCornersRectangleWinUI( | ||
| bounds, | ||
| LayoutThickness, | ||
| CornerRadius, | ||
| BackgroundSizing.InnerBorderEdge); | ||
| clip = keypoints.ToRoundedRect(); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
I know this is still draft so won't comment heavily. But should we try to support ALL geometries rather than just RoundedRect here? If someone creates a star-shaped control and needs to clip children this API won't work.
Note: The geometries can get crazy even in WinUI but I guess theoretically for a border are always some form of RoundedRect.
Note: We also need to support clipping in
ContentPresenter
There was a problem hiding this comment.
Also note WPF supports arbitrary geometry here as well: https://learn.microsoft.com/en-us/dotnet/api/system.windows.uielement.getlayoutclip
| } | ||
| } | ||
|
|
||
| public Thickness BorderThickness |
There was a problem hiding this comment.
Side comment: BackgroundSizing should be added too I think for border visuals to render the same. This is unrelated to the changes here though.
|
You can test this PR using the following package version. |
|
You can test this PR using the following package version. |
PR Summary: Child-Only Layout Clipping, Composition Parity, and Samples
What
UIElement.GetLayoutClip.BorderandContentPresenterwhenClipToBoundsis enabled.BackgroundSizingonBorderandContentPresenter.ContentPresenterrounded clipping.BackgroundSizingparity.How
Visual.GetLayoutClip(Size layoutSlotSize)andTryGetChildClipCore(...)to provide child-only clips.Layoutable.Arrangeand used it when computing layout clips.BorderandContentPresenteroverrideTryGetChildClipCoreto return a rounded inner-edgeRoundedRectusingGeometryBuilder.CalculateRoundedCornersRectangleWinUIwithBackgroundSizing.InnerBorderEdge.ClipToBoundsand without clamping to visual bounds.BackgroundSizingto match immediate rendering.Why
GetLayoutClipbehavior should be based on layout slot size and independent fromClipToBounds.Behavioral Notes
GetLayoutClipaffects only children; the visual's own rendering is not clipped.ClipToBounds = trueonBorder/ContentPresenteryields rounded inner-edge child clipping.ClipToBounds = falsedoes not prevent layout clips provided byGetLayoutClip.Test Coverage
GeometryChildClip_Clips_ChildGeometryChildClip_Clips_When_ClipToBounds_FalseGeometryChildClip_Uses_LayoutSlotSizeContentPresenter_RoundedClip_Clips_ChildBorder_BackgroundSizing_OuterBorderEdgeContentPresenter_BackgroundSizing_OuterBorderEdgeSample Coverage
Border.ContentPresenter.ClipToBounds.Fixes #2105