-
Notifications
You must be signed in to change notification settings - Fork 782
Add WrapPanel API Spec based on Windows Community Toolkit (WCT) #10858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ol for Public Review
|
How about changing |
Not sure I agree, as because "Lined" is in the name, the Line spacing makes more sense, and has context which does not exist with a wrap panel. |
This is discussed previously in AvaloniaUI/Avalonia#18079. I think |
You could do maybe Row spacing, and Item spacing, which may make sense, but HorizontalSpacing and VerticalSpacing is consistent with many other controls, and should still be relevant regardless of orientation. You could also have ItemHorizontalSpacing and ItemVerticalSpacing, which should also be agnostic regardless of the panel's Orientation. |
@mdtauk RowSpacing, and ItemSpacing, make more sense than H/V Spacing, but not as good as LineSpacing. If you set Orientation to Horizontal, the Line is a Column. And ItemHorizontalSpacing and ItemVerticalSpacing is a even worse naming than H/V spacing. First, it's tied to direction, causing confusion when switching Orientation. Second, the word
|
@mdtauk the current behavior of the WrapPanel (which is the same as it is in the Windows Community Toolkit) is that each row's height is calculated from the largest item in that row. You can see that with the random image sizes in the sample gallery:
So, I think that would cover your scenario? Unless I'm misunderstanding. But it should be called out within the spec somewhere on these expectations. |
|
@zxbmmmmmmmmm thanks to the link to the Avalonia discussion, that's useful context. I'll take a look. |
Can the items stretch to match the height of the tallest item, to fill the "row height"? |
IMO a more complete version of this ask is: |
|
Thanks @neerajmsgithub for the review, I was a bit confused at first until I just referenced existing similar classes in the main idl file ( Also, for future reference, you can make suggestions directly as edits that I could accept in the file with this toolbar button:
That'll also allow me to easily credit your account for the suggestions within the commit. |
Co-authored-by: neerajmsgithub <[email protected]>
|  | ||
|
|
||
| In a WrapPanel, if a child element's size is not set explicitly, it will be given the minimal amount | ||
| of space for layout. In this example, the size of the rectangles are explicitly set, if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should clarify that it is not required that every element has an explicit Width and Height set on it. A Button with some Content would render at the minimal size required to display that Button. The text as given right now makes it sounds like you MUST set an explicit Width and Height on every element in the WrapPanel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks; "minimal amount" was confusing as well. It's the "minimal size for the element" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: Clarify "minimal size" term. Wrap panel doesn't enforce any sizing.
Recommend: Draw analogy with auto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the element's sort of "natural size", the size that would be used by RowDefinition Height=Auto?
| The WrapPanel is a layout panel that arranges child elements in a sequential position from left to right, | ||
| items overflowing the line will break to the next line automatically at the edge of the containing panel. | ||
|
|
||
|  |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for including images. It makes understanding the text much easier.
One suggestion: Show some images of heterogeneous elements of different sizes. That will demonstrate the usefulness of WrapPanel. With the current images, it is not immediately obvious why one would use WrapPanel over Grid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example image for now, does it help to have it be practical example like this, or would it be better to use the colored rectangles?
One of the main differences with Grid, is that a Grid is very rigid and fixed and requires things like VisualStateManager and manipulation of attached properties of the elements within it to adapt to different sizes when your app size is changed. A WrapPanel adapts automatically and is commonly used for any small-medium sized collection of things which need to just flow with a document-style layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: Should remove "remove" text?
Recommend: Remove text from "Remove" from image.
|  | ||
|
|
||
| In a WrapPanel, if a child element's size is not set explicitly, it will be given the minimal amount | ||
| of space for layout. In this example, the size of the rectangles are explicitly set, if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks; "minimal amount" was confusing as well. It's the "minimal size for the element" ?
|
|
||
| ## WrapPanel class | ||
|
|
||
| The WrapPanel is a layout panel that arranges child elements in a sequential position from left to right, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a flag for "right to left" layout for languages where that's the natural direction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's handled implicitly by the framework, as we inherit from Panel which is a FrameworkElement with FlowDirection.
And then toggling flow direction:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change required.
| StretchChild StretchChild; | ||
| Double VerticalSpacing; | ||
|
|
||
| static Microsoft.UI.Xaml.DependencyProperty HorizontalSpacingProperty { get; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say I want to have a 6 items in my panel. They're all buttons whose minimum size is 30. My wrap panel is autoresized to be width 360 (2x the required size to display all six buttons in a row.) With StretchChild=Last, I see (for widths, in a single row) 30, 30, 30, 30, 30, 210.
Is there a way to have all the items in the row expand to fit equal amounts, so I'd see 60, 60, 60, 60, 60, 60? Or if my width was 240, have it produce {60, 60, 60, 60},{120, 120}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have an EqualPanel as a separate base panel for the Segmented control in the Toolkit which is more the first scenario of evenly spacing elements across the available size, but it doesn't handle wrapping. Your second scenario is kind of a combination of both, but I would imagine instead be {80, 80, 80},{80, 80, 80}. The difference with the EqualPanel is its enforcing the size on the child, where the WrapPanel does not and adapts to the measure provided by its children.
We don't expose the EqualPanel as a general panel at the moment in the Toolkit, but I would think your scenarios here would be an element of that panel where we'd investigate allowing it to wrap if constrained by a max boundary (e.g. Width if Horizontal). The question of how to distribute space and handle a row beyond the first in those scenarios seems like a tricky one though.
For historical context on why this property/behavior of StretchChild was added (specifically for Last) was for the TokenizingTextBox where there was a series of some number of tokens in the box, and then we'd want the final input box to take up the remaining available space. We just made it a enum for future proofing for further scenarios, but hadn't encountered any worth investigating in the last few years.
Example of StretchChild=Last from the TokenizingTextBox in the WCT Gallery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: Should panel handle layout like distribute proportionally? Do we need more control on how layout is handled in wrap panel? Should wrap panel cover those layout cases?
Current behavior is filling from left to right and wrap when required based on size. It is simple implementation and want to keep it that way.
No feature change required.
| static Microsoft.UI.Xaml.DependencyProperty VerticalSpacingProperty { get; }; | ||
| } | ||
|
|
||
| enum StretchChild |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe StretchChildren?
StretchChildren.None
StretchChildren.Last
StretchChildren.Proportional (possible future)
Also, this stretches only in the layout direction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: None means don't stretch any children. Can it be seen as extra space distribution algorithm?
Recommend: Change to StretchChildren.
|  | ||
|
|
||
| In a WrapPanel, if a child element's size is not set explicitly, it will be given the minimal amount | ||
| of space for layout. In this example, the size of the rectangles are explicitly set, if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: Clarify "minimal size" term. Wrap panel doesn't enforce any sizing.
Recommend: Draw analogy with auto.
|
|
||
| ## WrapPanel class | ||
|
|
||
| The WrapPanel is a layout panel that arranges child elements in a sequential position from left to right, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change required.
| The WrapPanel is a layout panel that arranges child elements in a sequential position from left to right, | ||
| items overflowing the line will break to the next line automatically at the edge of the containing panel. | ||
|
|
||
|  |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: Should remove "remove" text?
Recommend: Remove text from "Remove" from image.
| then wraps the Green box around to the next line due to the Width constraint on the WrapPanel: | ||
|
|
||
| ```xml | ||
| <controls:WrapPanel Width="132" HorizontalSpacing="16"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend: Add boxes with text may be alphabets to highlight size impact.
| StretchChild StretchChild; | ||
| Double VerticalSpacing; | ||
|
|
||
| static Microsoft.UI.Xaml.DependencyProperty HorizontalSpacingProperty { get; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: Should panel handle layout like distribute proportionally? Do we need more control on how layout is handled in wrap panel? Should wrap panel cover those layout cases?
Current behavior is filling from left to right and wrap when required based on size. It is simple implementation and want to keep it that way.
No feature change required.
| static Microsoft.UI.Xaml.DependencyProperty OrientationProperty { get; }; | ||
| static Microsoft.UI.Xaml.DependencyProperty PaddingProperty { get; }; | ||
| static Microsoft.UI.Xaml.DependencyProperty StretchChildProperty { get; }; | ||
| static Microsoft.UI.Xaml.DependencyProperty VerticalSpacingProperty { get; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: Property name should be row/col spacing or horizontal/vertical spacing, line item spacing?
Flex calls it row/col gap.
Consider: Line spacing and item spacing is better choice.
| static Microsoft.UI.Xaml.DependencyProperty VerticalSpacingProperty { get; }; | ||
| } | ||
|
|
||
| enum StretchChild |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: None means don't stretch any children. Can it be seen as extra space distribution algorithm?
Recommend: Change to StretchChildren.







This PR adds the dev and functional spec for WinUI WrapPanel (from Windows Community Toolkit).
Community members can provide feedback by commenting directly on the PR, or through a code suggestion with GitHub tools.
Feedback should be constructive and specific, addressing potential use cases, design concerns, and functionality.
This PR will be open for feedback for a month: October 27th – November 27th
For more info on the public api review process: https://aka.ms/winappsdk/api-specs-review