diff --git a/Source/Engine/UI/GUI/CanvasRootControl.cs b/Source/Engine/UI/GUI/CanvasRootControl.cs
index db6722090..2fe3d0355 100644
--- a/Source/Engine/UI/GUI/CanvasRootControl.cs
+++ b/Source/Engine/UI/GUI/CanvasRootControl.cs
@@ -197,6 +197,14 @@ namespace FlaxEngine.GUI
&& (_canvas.TestCanvasIntersection == null || _canvas.TestCanvasIntersection(ref location));
}
+ ///
+ public override void GetDesireClientArea(out Rectangle rect)
+ {
+ var size = Size;
+ var viewportRect = _canvas.ViewportRect;
+ rect = new Rectangle(size * new Float2(viewportRect.X, viewportRect.Y), size * new Float2(viewportRect.Z, viewportRect.W));
+ }
+
///
public override void Update(float deltaTime)
{
diff --git a/Source/Engine/UI/GUI/Control.Bounds.cs b/Source/Engine/UI/GUI/Control.Bounds.cs
index 079530c50..0e27aaa5f 100644
--- a/Source/Engine/UI/GUI/Control.Bounds.cs
+++ b/Source/Engine/UI/GUI/Control.Bounds.cs
@@ -708,5 +708,22 @@ namespace FlaxEngine.GUI
}
}
}
+
+ ///
+ /// Sets the anchors for the control.
+ ///
+ /// The minimum anchors point to use.
+ /// The maximum anchors point to use.
+ /// True if preserve current control bounds, otherwise will align control position accordingly to the anchor location.
+ public void SetAnchors(Float2 anchorMin, Float2 anchorMax, bool preserveBounds)
+ {
+ var bounds = _bounds;
+ _anchorMin = anchorMin;
+ _anchorMax = anchorMax;
+ if (preserveBounds)
+ Bounds = bounds;
+ else
+ UpdateBounds();
+ }
}
}
diff --git a/Source/Engine/UI/UICanvas.cs b/Source/Engine/UI/UICanvas.cs
index d5a18a58b..ff7f3eb8b 100644
--- a/Source/Engine/UI/UICanvas.cs
+++ b/Source/Engine/UI/UICanvas.cs
@@ -1,6 +1,7 @@
// Copyright (c) Wojciech Figat. All rights reserved.
using System;
+using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Text;
@@ -114,6 +115,7 @@ namespace FlaxEngine
private readonly CanvasRootControl _guiRoot;
private CanvasRenderer _renderer;
private bool _isLoading, _isRegisteredForTick, _isRegisteredForOnDraw;
+ private Float4 _viewportRect = new Float4(0, 0, 1, 1);
///
/// Gets or sets the canvas rendering mode.
@@ -222,6 +224,21 @@ namespace FlaxEngine
[EditorOrder(70), NoSerialize, EditorDisplay("Canvas"), VisibleIf("Editor_IsGPUTexture")]
public GPUTexture OutputTexture { get; set; }
+ ///
+ /// Four values that define where on the screen this canvas should be drawn. Measured in normalized coordinates (range 0-1). Order: X, Y, Width, Height. For example (0, 0, 1, 1) means full screen, (0, 0, 0.5, 1) means left half of the screen and (0.5, 0, 0.5, 1) means right half of the screen.
+ ///
+ [EditorOrder(80), EditorDisplay("Canvas"), Limit(0, 1, 0.001f)]
+ [DefaultValue(typeof(Float4), "0,0,1,1")]
+ public Float4 ViewportRect
+ {
+ get => _viewportRect;
+ set
+ {
+ _viewportRect = value;
+ _guiRoot.PerformLayout();
+ }
+ }
+
///
/// Gets the canvas GUI root control.
///
@@ -688,6 +705,21 @@ namespace FlaxEngine
jsonWriter.WriteValue(Distance);
}
+ if (noOther || _viewportRect != other._viewportRect)
+ {
+ jsonWriter.WritePropertyName("ViewportRect");
+ jsonWriter.WriteStartObject();
+ jsonWriter.WritePropertyName("X");
+ jsonWriter.WriteValue(_viewportRect.X);
+ jsonWriter.WritePropertyName("Y");
+ jsonWriter.WriteValue(_viewportRect.Y);
+ jsonWriter.WritePropertyName("Z");
+ jsonWriter.WriteValue(_viewportRect.Z);
+ jsonWriter.WritePropertyName("W");
+ jsonWriter.WriteValue(_viewportRect.W);
+ jsonWriter.WriteEndObject();
+ }
+
bool saveSize = RenderMode == CanvasRenderMode.WorldSpace || RenderMode == CanvasRenderMode.WorldSpaceFaceCamera;
if (!noOther)
saveSize = (saveSize || other.RenderMode == CanvasRenderMode.WorldSpace || other.RenderMode == CanvasRenderMode.WorldSpaceFaceCamera) && Size != other.Size;