4 using System.Diagnostics;
6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Mathematics;
9 namespace SiliconStudio.
Paradox.UI.Panels
14 [DebuggerDisplay(
"UniformGrid - Name={Name}")]
35 private Vector3 finalForOneCell;
37 private static void InvalidateGridMeasure(
object propertyOwner,
PropertyKey<int> propertyKey,
int propertyOldValue)
40 element.InvalidateMeasure();
43 private static void GridSizeValidator(ref
int value)
46 throw new ArgumentOutOfRangeException(
"value");
55 get {
return DependencyProperties.Get(ColumnsPropertyKey); }
56 set { DependencyProperties.Set(ColumnsPropertyKey, value); }
65 get {
return DependencyProperties.Get(RowsPropertyKey); }
66 set { DependencyProperties.Set(RowsPropertyKey, value); }
75 get {
return DependencyProperties.Get(LayersPropertyKey); }
76 set { DependencyProperties.Set(LayersPropertyKey, value); }
82 var gridSize =
new Vector3(Columns, Rows, Layers);
83 var availableForOneCell =
new Vector3(availableSizeWithoutMargins.
X / gridSize.X, availableSizeWithoutMargins.
Y / gridSize.Y, availableSizeWithoutMargins.
Z / gridSize.Z);
86 var neededForOneCell = Vector3.Zero;
87 foreach (var child
in VisualChildrenCollection)
90 var childSpans = GetElementSpanValuesAsFloat(child);
91 var availableForChildWithMargin = Vector3.Modulate(childSpans, availableForOneCell);
93 child.Measure(availableForChildWithMargin);
96 Math.Max(neededForOneCell.X, child.DesiredSizeWithMargins.X / childSpans.X),
97 Math.Max(neededForOneCell.Y, child.DesiredSizeWithMargins.Y / childSpans.Y),
98 Math.Max(neededForOneCell.Z, child.DesiredSizeWithMargins.Z / childSpans.Z));
101 return Vector3.Modulate(gridSize, neededForOneCell);
107 var gridSize =
new Vector3(Columns, Rows, Layers);
108 finalForOneCell =
new Vector3(finalSizeWithoutMargins.
X / gridSize.X, finalSizeWithoutMargins.
Y / gridSize.Y, finalSizeWithoutMargins.
Z / gridSize.Z);
111 foreach (var child
in VisualChildrenCollection)
114 var childSpans = GetElementSpanValuesAsFloat(child);
115 var finalForChildWithMargin = Vector3.Modulate(childSpans, finalForOneCell);
118 var childOffsets = GetElementGridPositionsAsFloat(child);
119 child.DependencyProperties.Set(PanelArrangeMatrixPropertyKey, Matrix.Translation(Vector3.Modulate(childOffsets, finalForOneCell) - finalSizeWithoutMargins / 2));
122 child.Arrange(finalForChildWithMargin, IsCollapsed);
125 return finalSizeWithoutMargins;
128 private void CalculateDistanceToSurroundingModulo(
float position,
float modulo,
float elementCount, out
Vector2 distances)
132 distances = Vector2.Zero;
136 var validPosition = Math.Max(0, Math.Min(position, elementCount * modulo));
137 var inferiorQuotient = Math.Min(elementCount - 1, (float)Math.Floor(validPosition / modulo));
139 distances.X = (inferiorQuotient+0) * modulo - validPosition;
140 distances.Y = (inferiorQuotient+1) * modulo - validPosition;
146 var gridElements =
new Vector3(Columns, Rows, Layers);
148 CalculateDistanceToSurroundingModulo(position, finalForOneCell[(
int)direction], gridElements[(
int)direction], out distances);
Provides a base class for all the User Interface elements in Paradox applications.
float Y
The Y component of the vector.
Represents a two dimensional mathematical vector.
Orientation
Defines the different orientations that a control or layout can have.
float X
The X component of the vector.
Represents a three dimensional mathematical vector.
Represents the base primitive for all the grid-like controls
SiliconStudio.Core.Mathematics.Vector3 Vector3
float Z
The Z component of the vector.
A class that represents a tag propety.