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

[Grid] Add RowSpacing and ColumnSpacing #18077

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

Conversation

zxbmmmmmmmmm
Copy link

What does the pull request do?

Add RowSpacing and ColumnSpacing properties for Grid, just like in UWP and WinUI 3.
image

What is the updated/expected behavior with this PR?

  1. Add a Grid with various children.
  2. Arrange children in different row and columns.
  3. Set RowSpacing and ColumnSpacing to non-zero values.

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

Add the corresponding spacing before calculating the position of each RowDefinition or ColumnDefinition.
Subtract spacing before calculating stars when GridUnitType=star.

Checklist

Breaking changes

None

Obsoletions / Deprecations

None

Fixed issues

Fixes #5152

@avaloniaui-bot
Copy link

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

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Jan 30, 2025

  • All contributors have signed the CLA.

@zxbmmmmmmmmm
Copy link
Author

@cla-avalonia agree

/// Defines the <see cref="ColumnSpacing"/> property.
/// </summary>
public static readonly StyledProperty<double> ColumnSpacingProperty =
AvaloniaProperty.Register<Grid, double>(nameof(ColumnSpacingProperty));
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to add coercion for negative values? Or does UWP support them?

Copy link
Contributor

Choose a reason for hiding this comment

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

negative spacing is not recommended feature, but it is supported in uwp/winui3. And so do this PR. This PR support negative spacing, too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think we should support negative Spacing if possible. It matches with what is allowed for Margin/Padding which can be negative.

There are some rare layout cases it's useful and by default the math usually supports negatives for free.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now both the spacing in uwp/winui3 and in these 3 PRs don't support negative values in principle, but in practice they do support (

@robloo
Copy link
Contributor

robloo commented Jan 30, 2025

Great work! This has been a nice to have for a long time.

@MrJul
Copy link
Member

MrJul commented Feb 1, 2025

I'm marking this PR with needs-api-review for the sake of it but we were fine with this for UniformGrid in #17993 (comment) so I really don't see it being rejected.

@MrJul MrJul added the needs-api-review The PR adds new public APIs that should be reviewed. label Feb 1, 2025
@robloo
Copy link
Contributor

robloo commented Feb 1, 2025

I'm marking this PR with needs-api-review for the sake of it but we were fine with this for UniformGrid... so I really don't see it being rejected.

It also matches UWP/WinUI as-is and I've never heard of concerns with that API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature needs-api-review The PR adds new public APIs that should be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grid: Add RowSpacing and ColumnSpacing
7 participants