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

add spacing to uniform grid - issue 8406 #17993

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Enzx
Copy link

@Enzx Enzx commented Jan 18, 2025

What does the pull request do?

This pull request addresses this Issue:
#8406 (Marked as Enhancement)

This pull request adds RowSpacing and ColumnSpacing properties to the UniformGrid control in Avalonia. These properties allow developers to define the spacing between rows and columns, making creating consistent and flexible layouts easier. This update addresses limitations in the current UniformGrid implementation, such as the lack of built-in support for spacing, which previously required cumbersome workarounds.

What is the current behavior?

Currently, UniformGrid does not support row or column spacing. Developers often use workarounds such as:

  • Adding fake spacing rows/columns in Grid.
  • Manually adjusting Margin values for individual children.
    These methods are error-prone, hard to maintain, and do not scale well for larger layouts.

What is the updated/expected behavior with this PR?

With this PR, developers can set the RowSpacing and ColumnSpacing properties directly on UniformGrid. The grid will automatically apply the specified spacing while maintaining uniform child sizes and alignment.

How to test the PR:

  1. Add a UniformGrid with various children.
  2. Set RowSpacing and ColumnSpacing to non-zero values.
  3. Verify that:
    • Spacing is applied correctly between rows and columns.
    • Child elements remain uniformly sized and aligned.
    • Invisible children are ignored while maintaining the proper layout.

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

  • New Properties: Added RowSpacing and ColumnSpacing as styled properties with a default value of 0.
  • MeasureOverride: Adjusts available size for children to account for spacing when calculating the desired size.
  • ArrangeOverride: Includes spacing when positioning children within the grid.
  • UpdateRowsAndColumns: Ensures spacing compatibility with dynamically calculated row/column counts.
  • Unit Tests: Added extensive tests to verify layout behavior with and without spacing.

Checklist

Breaking changes

None. The default values for RowSpacing and ColumnSpacing are 0, preserving existing behavior for layouts that do not use these properties.

Obsoletions / Deprecations

None.

Fixed issues

#8406

@avaloniaui-bot
Copy link

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

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Jan 18, 2025

  • All contributors have signed the CLA.

@Enzx
Copy link
Author

Enzx commented Jan 18, 2025

@cla-avalonia agree

@DoubleDBE
Copy link

Awesome! These properties are for certain missing on a regular Grid as well. But, yeah... 🙄

#5152
#8406

@Enzx Enzx marked this pull request as ready for review January 18, 2025 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants