-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: [UI] Add gap support to layout panels #2855
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
feat: [UI] Add gap support to layout panels #2855
Conversation
…onality - Introduced ColumnGap, RowGap, and LayerGap properties in GridBase to manage spacing between elements. - Updated Grid and UniformGrid to account for gaps during measurement and arrangement, ensuring proper layout calculations. - Enhanced UniformGrid tests to validate behavior with gaps, including tests for spanned elements and various configurations. - Modified StackPanel to include a gap property, affecting the arrangement and measurement of child elements. - Improved overall layout logic to ensure gaps are considered in both 2D and 3D grid scenarios.
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.
Pull Request Overview
This PR introduces gap functionality to layout panels (Grid, UniformGrid, and StackPanel) to provide spacing between child elements, similar to CSS gap properties. The implementation adds column, row, and layer gap properties to grid-based panels and a general gap property to StackPanel.
Key changes:
- Added
ColumnGap,RowGap, andLayerGapproperties toGridBaseclass - Implemented gap support in both
GridandUniformGridclasses with proper measure and arrange logic - Added
Gapproperty toStackPanelwith support for virtualization - Comprehensive test coverage for all gap functionality including edge cases
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
GridBase.cs |
Introduces gap properties and helper methods for grid-based panels |
Grid.cs |
Implements gap logic in measure/arrange cycles and strip positioning |
UniformGrid.cs |
Adds gap support for uniform grid layout with spanned elements |
StackPanel.cs |
Implements gap property with virtualization support |
GridTests.cs |
Comprehensive test coverage for Grid gap functionality |
UniformGridTests.cs |
Test coverage for UniformGrid gap features |
StackPanelTests.cs |
Test coverage for StackPanel gap functionality |
Co-authored-by: Copilot <[email protected]>
Eideren
left a comment
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.
Sorry for the delay, this is great, just one minor nitpick - I understand that some part of those are there to mirror's how the previous logic was setup, but prefer vector operation over per component operation.
var x = new Vector3(v.X/v2.X, v.Y/v2.Y, v.Z/v2.Z);
// into
var x = v / v2;I'll mark areas where this could be improved below.
| var totalGapSize = new Vector3( | ||
| CalculateTotalGapSize(0, Columns), | ||
| CalculateTotalGapSize(1, Rows), | ||
| CalculateTotalGapSize(2, Layers)); | ||
|
|
||
| var availableForCells = availableSizeWithoutMargins - totalGapSize; | ||
| var availableForOneCell = new Vector3( | ||
| availableForCells.X / gridSize.X, | ||
| availableForCells.Y / gridSize.Y, | ||
| availableForCells.Z / gridSize.Z); |
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.
CalculateTotalGapSize could take and return vectors, and the per component division could be a vector / vector
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.
Done.
| var availableForChildWithMargin = new Vector3( | ||
| CalculateSpannedSize(availableForOneCell.X, (int)childSpans.X, 0), | ||
| CalculateSpannedSize(availableForOneCell.Y, (int)childSpans.Y, 1), | ||
| CalculateSpannedSize(availableForOneCell.Z, (int)childSpans.Z, 2)); |
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.
CalculateSpannedSize could take and return vectors
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.
CalculateSpannedSize accepts now two vectors for the cell size and gaps.
| var totalGapSize = new Vector3( | ||
| CalculateTotalGapSize(0, Columns), | ||
| CalculateTotalGapSize(1, Rows), | ||
| CalculateTotalGapSize(2, Layers)); | ||
|
|
||
| var availableForCells = finalSizeWithoutMargins - totalGapSize; | ||
| finalForOneCell = new Vector3( | ||
| availableForCells.X / gridSize.X, | ||
| availableForCells.Y / gridSize.Y, | ||
| availableForCells.Z / gridSize.Z); |
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.
Same here
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.
Done.
| var finalForChildWithMargin = new Vector3( | ||
| CalculateSpannedSize(finalForOneCell.X, (int)childSpans.X, 0), | ||
| CalculateSpannedSize(finalForOneCell.Y, (int)childSpans.Y, 1), | ||
| CalculateSpannedSize(finalForOneCell.Z, (int)childSpans.Z, 2)); |
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.
And here
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.
Use simplified CalculateSpannedSize too.
Introduces a new `GetGaps` method in `GridBase.cs` to calculate spacing gaps as a `Vector3`. Updates `CalculateSpannedSize` in `UniformGrid.cs` to accept `Vector3` parameters for improved handling of dimensions. Refactors available space calculations and child measurement logic to utilize the new methods, enhancing readability and maintainability. Overall, these changes improve the grid layout functionality and encapsulation of gap calculations.
|
@Eideren thank you for your review. I applied all suggestions. |
|
Thanks for going through it, just one question stride/sources/engine/Stride.UI/Panels/UniformGrid.cs Lines 93 to 97 in 3a6ab04
This doesn't seem right to me, but I might not fully understand the method, are you sure you want to always return a size >= Vector3.One here ? |
Normalized the `span` parameter to ensure it is at least `Vector3.One`, preventing issues with spans less than one. Adjusted the calculation of `gaps` to use the normalized span for accurate gap computation. The return value now reflects these changes while maintaining similar functionality.
|
There was an issue after refactoring what I fixed now. The function calculates the size of a spanned element, including the gaps between the columns, rows, and layers. Originally the function has returned the size of the element in one dimension when the span is less than or equal to one, because there are no gaps to add in this case. I restored this behavior by normalizing the span parameter to make all dimensions at least one. |
|
Thanks ! |
PR Details
Introduced gap functionality to Grid, UniformGrid and StackPanel similar to the
gapin CSS.Add
ColumnGap,RowGap, andLayerGapproperties in GridBase for Grid and UniformGrid to manage spacing between elements. Extend the StackPanel to include a gap property.Related Issue
Closes #2852
Types of changes
Checklist