Skip to content
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

[DockPanel] Add Spacing properties #17977

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Poker-sang
Copy link

@Poker-sang Poker-sang commented Jan 15, 2025

What does the pull request do?

Add HorizontalSpacing, VerticalSpacing properties for DockPanel

What is the current behavior?

DockPanel only has LastChildFill property

What is the updated/expected behavior with this PR?

Add HorizontalSpacing, VerticalSpacing Property
image

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

None

Obsoletions / Deprecations

None

Fixed issues

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054301-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Jan 15, 2025

  • All contributors have signed the CLA.

@Poker-sang
Copy link
Author

@cla-avalonia agree

@rabbitism
Copy link
Contributor

by convention panel should not have padding.

@Poker-sang
Copy link
Author

Poker-sang commented Jan 15, 2025

Thanks for quick response. But I saw a Grid in WinUI3 has padding

anyway I can remove that property if needed

@timunie timunie added feature needs-api-review The PR adds new public APIs that should be reviewed. labels Jan 15, 2025
@MrJul
Copy link
Member

MrJul commented Jan 20, 2025

Diff for API review:

 namespace Avalonia.Controls
 {
     public class DockPanel
     {
+        public static readonly StyledProperty<Thickness> PaddingProperty;
+        public static readonly StyledProperty<double> HorizontalSpacingProperty;
+        public static readonly StyledProperty<double> VerticalSpacingProperty;
+        public Thickness Padding { get; set; }
+        public double HorizontalSpacing { get; set; }
+        public double VerticalSpacing { get; set; }
     }
 }

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

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

Notes from the API review meeting:

Remove Padding. Other Panel implementations don't have this property (and don't need to - they also don't have a concept of border, radius, etc.).

Regarding HorizontalSpacing and VerticalSpacing, we couldn't really see the use cases here.

Most panels are displaying a series of items, and spacing makes perfect sense there: the user doesn't need to add a margin to each item, with special handling of the first or last ones.

DockPanel is different, is that there's usually only one "fill" child, and a fixed number of children with specific dock positions. As such, we don't see what Spacing would bring to the table that isn't easily doable with Margin on children.

Could you please provide use cases?

@Poker-sang
Copy link
Author

Poker-sang commented Jan 21, 2025

Thanks for reviewing.

For any Panel, the Margin of the child items can be used to achieve a similar effect to Spacing, so for any Panel, Spacing is not required, but a more convenient option.

To answer your question. This is an example that use DockPanel and need Spacing:

image

Also, generally DockPanel is used to simplify the writing of parts of the Grid. And many people have a need for Spacing on the Grid, so of course they should have a need for Spacing on the DockPanel.

@MrJul MrJul added api-change-requested The new public APIs need some changes. and removed needs-api-review The PR adds new public APIs that should be reviewed. labels Jan 21, 2025
@Poker-sang
Copy link
Author

Padding property is removed

@Poker-sang Poker-sang changed the title [DockPanel] Add Spacing and Padding properties [DockPanel] Add Spacing properties Jan 21, 2025
@Poker-sang Poker-sang requested a review from MrJul January 21, 2025 16:20
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054379-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@robloo
Copy link
Contributor

robloo commented Jan 21, 2025

@MrJul

Remove Padding. Other Panel implementations don't have this property (and don't need to - they also don't have a concept of border, radius, etc.).

Padding is actually required to fully support all spacing cases. Existing Spacing properties only control what is between children. If you want to have spacing at the start or the end that's why Padding is there. Microsoft realized it's the same concept as the existing Padding property used for layout so didn't add anything new. But Padding+Spacing very much does go together and is there to support all cases.

I also agree with the above use-case justification. It seems obvious how this is useful in other panels (StackPanel, Grid, etc.) and will be useful here. By this same logic you are using I can say get rid of DockPanel and lets just use a Grid for everything. Of course it's possible, it just isn't as fast or convenient. This is a pretty common use-case so was pulled out as it's own control.

This also aligns pretty closely with WrapPanel in the community toolkit: https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/wrappanel#properties

@MrJul
Copy link
Member

MrJul commented Jan 22, 2025

Padding is actually required to fully support all spacing cases. Existing Spacing properties only control what is between children. If you want to have spacing at the start or the end that's why Padding is there.

The point is that this isn't specific to DockPanel but to all panels. If we chose to add Padding, it should probably be on Panel directly. Let's keep this PR focused on spacing.

To answer your question. This is an example that use DockPanel and need Spacing:

Thank you. I guess none of us in the team really use DockPanel that way - hence the ask for use cases. (I would definitely model that image as a Grid.) The use case is perfectly valid. We've been adding spacing on most panels, DockPanel shouldn't be an exception.

@MrJul MrJul added api-approved The new public APIs have been approved. and removed api-change-requested The new public APIs need some changes. labels Jan 22, 2025
@Poker-sang
Copy link
Author

Poker-sang commented Jan 22, 2025

Thank you @robloo for your long reply, you expressed exactly what I had in mind about Padding. ❤️

And yes @MrJul, I also think it's better to add the Padding property directly on the Panel, it should be shared by all Panels.

@Poker-sang
Copy link
Author

Poker-sang commented Jan 22, 2025

But the specific implementation of Padding lies in each individual Panel. i think if i remove the Padding from the DockPanel, it will take more effort to add it back next time. Whereas if I keep it, we can just extract the Padding to the base class in the future with no breaking changes.

It's just my opinion, but all in all I'll follow the advice of the Avalonia team.

@MrJul
Copy link
Member

MrJul commented Jan 22, 2025

i think if i remove the Padding from the DockPanel, it will take more effort to add it back next time

Padding is trivial to implement: it's deflating the available bounds before doing anything else. We could even have it in the base Panel class if we choose to add it. But there's absolutely no rush: it's so easy for the user to have padding by wrapping the panel inside a Border. If the panel doesn't have any Background, simply setting the Margin also works as a substitute.

Please, let's keep this PR focused on DockPanel spacing. If you wish, feel free to open an issue to discuss adding Padding to panels.

@robloo
Copy link
Contributor

robloo commented Jan 22, 2025

Please, let's keep this PR focused on DockPanel spacing.

My point is Padding is related to Spacing in this context. Padding+Spacing go together. We ARE focusing on DockPanel spacing.

Since not all panels support Spacing there is no reason to pull this out into the base class yet. Although, I agree it could go there in the future.

You are also correct that it's simple to work around this. However, you missed some things in the API review so it's worth revisiting. I'm pretty sure everywhere in WinUI you see Spacing properties you will also find Padding.

@maxkatz6
Copy link
Member

However, you missed some things in the API review so it's worth revisiting. I'm pretty sure everywhere in WinUI you see Spacing properties you will also find Padding.

I am pretty sure general rule of a thumb is adding Padding to controls that have BorderBrush/Thickness, and not Spacing.
As it makes a lot of sense to adjust border padding when you have one.

Avalonia panels don't have any border properties except Background. Which can be discussed as a feature on itself separately.

@robloo
Copy link
Contributor

robloo commented Jan 22, 2025

@maxkatz6 Yes, historically that's true.

But my argument is simply Padding is now dual-use for controls that also have Spacing properties. Spacing controls distance between items, Padding controls distance outside items.

Edit: I'm really not sure why this isn't being understood or acknowledged. Even if you disagree. But it seems the two are related which is why I don't want to separate this out as a new topic and then apply it to all panels. Not all panels need it yet. The argument that it's better to add the property incrementally for controls (like this one) that can use it now is pretty strong as well. Then it can be moved to the base class as a non (API) breaking change when the time is right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved The new public APIs have been approved. feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants