diff --git a/sources/core/Stride.Core.Mathematics/Size2.cs b/sources/core/Stride.Core.Mathematics/Size2.cs
index 0b48147581..8280d5380d 100644
--- a/sources/core/Stride.Core.Mathematics/Size2.cs
+++ b/sources/core/Stride.Core.Mathematics/Size2.cs
@@ -21,7 +21,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
@@ -68,6 +67,35 @@ public Size2(int width, int height)
[DataMember(1)]
public int Height;
+ ///
+ /// Gets or sets the component at the specified index.
+ ///
+ /// The value of the Width or Height component, depending on the index.
+ /// The index of the component to access. Use 0 for the Width component and 1 for the Height component.
+ /// The value of the component at the specified index.
+ /// Thrown when the is out of the range [0, 1].
+ public int this[int index]
+ {
+ readonly get
+ {
+ return index switch
+ {
+ 0 => Width,
+ 1 => Height,
+ _ => throw new ArgumentOutOfRangeException(nameof(index), "Indices for Size2 run from 0 to 1, inclusive."),
+ };
+ }
+ set
+ {
+ switch (index)
+ {
+ case 0: Width = value; break;
+ case 1: Height = value; break;
+ default: throw new ArgumentOutOfRangeException(nameof(index), "Indices for Size2 run from 0 to 1, inclusive.");
+ }
+ }
+ }
+
///
/// Determines whether the specified is equal to this instance.
///
diff --git a/sources/core/Stride.Core.Mathematics/Size2F.cs b/sources/core/Stride.Core.Mathematics/Size2F.cs
index 19819e0f75..65976f291a 100644
--- a/sources/core/Stride.Core.Mathematics/Size2F.cs
+++ b/sources/core/Stride.Core.Mathematics/Size2F.cs
@@ -21,8 +21,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Stride.Core.Mathematics;
@@ -56,6 +56,16 @@ public Size2F(float width, float height)
Height = height;
}
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The width and height of the .
+ public Size2F(float uniform)
+ {
+ Width = uniform;
+ Height = uniform;
+ }
+
///
/// Width.
///
@@ -68,6 +78,35 @@ public Size2F(float width, float height)
[DataMember(1)]
public float Height;
+ ///
+ /// Gets or sets the component at the specified index.
+ ///
+ /// The value of the Width or Height component, depending on the index.
+ /// The index of the component to access. Use 0 for the Width component and 1 for the Height component.
+ /// The value of the component at the specified index.
+ /// Thrown when the is out of the range [0, 1].
+ public float this[int index]
+ {
+ readonly get
+ {
+ return index switch
+ {
+ 0 => Width,
+ 1 => Height,
+ _ => throw new ArgumentOutOfRangeException(nameof(index), "Indices for Size2F run from 0 to 1, inclusive."),
+ };
+ }
+ set
+ {
+ switch (index)
+ {
+ case 0: Width = value; break;
+ case 1: Height = value; break;
+ default: throw new ArgumentOutOfRangeException(nameof(index), "Indices for Size2F run from 0 to 1, inclusive.");
+ }
+ }
+ }
+
///
/// Determines whether the specified is equal to this instance.
///
@@ -118,6 +157,124 @@ public override readonly int GetHashCode()
return !left.Equals(right);
}
+ ///
+ /// Implements the operator /, component wise.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static Size2F operator /(Size2F left, Size2F right)
+ {
+ return new Size2F(left.Width / right.Width, left.Height / right.Height);
+ }
+
+ ///
+ /// Implements the operator /, component wise.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static Size2F operator /(Size2F left, float right)
+ {
+ return new Size2F(left.Width / right, left.Height / right);
+ }
+
+ ///
+ /// Implements the operator *, component wise.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static Size2F operator *(Size2F left, Size2F right)
+ {
+ return new Size2F(left.Width * right.Width, left.Height * right.Height);
+ }
+
+ ///
+ /// Implements the operator *, component wise.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static Size2F operator *(Size2F left, float right)
+ {
+ return new Size2F(left.Width * right, left.Height * right);
+ }
+
+ ///
+ /// Implements the operator +, component wise.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static Size2F operator +(Size2F left, Size2F right)
+ {
+ return new Size2F(left.Width + right.Width, left.Height + right.Height);
+ }
+
+ ///
+ /// Implements the operator -, component wise.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static Size2F operator -(Size2F left, Size2F right)
+ {
+ return new Size2F(left.Width + right.Width, left.Height + right.Height);
+ }
+
+ ///
+ /// Returns a size containing the largest components of the specified sizes.
+ ///
+ /// The first source size.
+ /// The second source size.
+ /// A size containing the largest components of the source size.
+ public static Size2F Max(Size2F left, Size2F right)
+ {
+ return new Size2F(Math.Max(left.Width, right.Width), Math.Max(left.Height, right.Height));
+ }
+
+ ///
+ /// Returns a size containing the smallest components of the specified sizes.
+ ///
+ /// The first source size.
+ /// The second source size.
+ /// A size containing the smallest components of the source size.
+ public static Size2F Min(Size2F left, Size2F right)
+ {
+ return new Size2F(Math.Min(left.Width, right.Width), Math.Min(left.Height, right.Height));
+ }
+
+ ///
+ /// Casts from to .
+ ///
+ /// Value to cast.
+ public static explicit operator Size2F(Vector2 vector)
+ {
+ return Unsafe.BitCast(vector);
+ }
+
+ ///
+ /// Casts from to .
+ ///
+ /// Value to cast.
+ public static explicit operator Vector2(Size2F size)
+ {
+ return Unsafe.BitCast(size);
+ }
+
///
public override readonly string ToString()
{
diff --git a/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/AdornerBase.cs b/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/AdornerBase.cs
index 3de91cf960..1abb37308c 100644
--- a/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/AdornerBase.cs
+++ b/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/AdornerBase.cs
@@ -20,7 +20,7 @@ internal interface IAdornerBase
void Show();
- void Update(Vector3 position);
+ void Update(Vector2 position);
}
///
@@ -77,7 +77,7 @@ public void Show()
Visual.Visibility = Visibility.Visible;
}
- public abstract void Update(Vector3 position);
+ public abstract void Update(Vector2 position);
protected void InitializeAttachedProperties()
{
diff --git a/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/BorderAdorner.cs b/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/BorderAdorner.cs
index e14a574fc0..a39e8b2236 100644
--- a/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/BorderAdorner.cs
+++ b/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/BorderAdorner.cs
@@ -13,7 +13,7 @@ namespace Stride.Assets.Presentation.AssetEditors.UIEditor.Adorners
internal abstract class BorderAdorner : AdornerBase
{
private float borderThickness;
- private Vector3 size;
+ private Size2F size;
protected BorderAdorner(UIEditorGameAdornerService service, UIElement gameSideElement)
: base(service, gameSideElement)
@@ -50,7 +50,7 @@ public float BorderThickness
}
}
- public Vector3 Size
+ public Size2F Size
{
get { return size; }
set
@@ -64,13 +64,13 @@ public Vector3 Size
protected virtual void UpdateBorderThickness()
{
- Visual.BorderThickness = Thickness.UniformCuboid(borderThickness);
+ Visual.BorderThickness = Thickness.Uniform(borderThickness);
}
protected virtual void UpdateSize()
{
// border thickness is added to the total size
- Visual.Size = size + new Vector3(BorderThickness*2);
+ Visual.Size = size + new Size2F(BorderThickness*2);
}
}
}
diff --git a/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/HighlightAdorner.cs b/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/HighlightAdorner.cs
index 2487e63f51..d0f09dfdda 100644
--- a/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/HighlightAdorner.cs
+++ b/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/HighlightAdorner.cs
@@ -36,7 +36,7 @@ public void Unlit()
Visual.Opacity = 0.0f;
}
- public override void Update(Vector3 position)
+ public override void Update(Vector2 position)
{
UpdateFromSettings();
Size = GameSideElement.RenderSize;
@@ -45,7 +45,7 @@ public override void Update(Vector3 position)
protected override void UpdateSize()
{
base.UpdateSize();
- Visual.Margin = Thickness.UniformCuboid(-BorderThickness);
+ Visual.Margin = Thickness.Uniform(-BorderThickness);
}
private void UpdateFromSettings()
diff --git a/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/MarginAdorner.cs b/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/MarginAdorner.cs
index 4baf76539b..149a408941 100644
--- a/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/MarginAdorner.cs
+++ b/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Adorners/MarginAdorner.cs
@@ -14,10 +14,8 @@ internal enum MarginEdge
{
Left,
Top,
- Back,
Right,
- Bottom,
- Front
+ Bottom
}
internal sealed class MarginAdorner : AdornerBase