Class CanvasScaler
UI canvas scaling component for user interface that targets multiple different game resolutions (eg. mobile screens).
Implements
Namespace: FlaxEngine.GUI
Assembly: FlaxEngine.CSharp.dll
Syntax
[ActorToolbox("GUI")]
public class CanvasScaler : ContainerControl, IComparable, IDrawable
Constructors
CanvasScaler()
Fields
DpiCurve
The UI Canvas scaling curve based on screen DPI (key is DPI, value is scale factor). Used only in ScaleWithDpi mode.
Declaration
[EditorOrder(150)]
[EditorDisplay("Canvas Scaler", null)]
[VisibleIf("IsScaleWithDpi", false)]
public LinearCurve<float> DpiCurve
Field Value
LinearCurve<System.Single>
|
ResolutionCurve
The UI Canvas scaling curve based on screen resolution - shortest/longest/vertical/horizontal (key is resolution, value is scale factor). Clear keyframes to skip using it and follow min/max rules only. Used only in ScaleWithResolution mode.
Declaration
[EditorOrder(140)]
[EditorDisplay("Canvas Scaler", null)]
[VisibleIf("IsScaleWithResolution", false)]
public LinearCurve<float> ResolutionCurve
Field Value
LinearCurve<System.Single>
|
Properties
CurrentScale
Gets the current UI scale. Computed based on the setup when performing layout.
Declaration
public float CurrentScale { get; }
Property Value
System.Single
|
EditorBounds
Bounds rectangle for editor UI.
Declaration
public override Rectangle EditorBounds { get; }
Property Value
Rectangle
|
Overrides
PhysicalUnit
The UI Canvas physical unit to use for scaling via PhysicalUnitSize. Used only in ConstantPhysicalSize mode.
Declaration
[EditorOrder(100)]
[EditorDisplay("Canvas Scaler", null)]
[VisibleIf("IsConstantPhysicalSize", false)]
public CanvasScaler.PhysicalUnitMode PhysicalUnit { get; set; }
Property Value
CanvasScaler.PhysicalUnitMode
|
PhysicalUnitSize
The UI Canvas physical unit value. Used only in ConstantPhysicalSize mode.
Declaration
[EditorOrder(110)]
[EditorDisplay("Canvas Scaler", null)]
[Limit(1E-06F, 1000000F, 0F)]
[VisibleIf("IsConstantPhysicalSize", false)]
public float PhysicalUnitSize { get; set; }
Property Value
System.Single
|
ResolutionMax
The UI Canvas maximum resolution. If the screen has higher size, then the interface will be scaled accordingly. Used only in ScaleWithResolution mode.
Declaration
[EditorOrder(130)]
[EditorDisplay("Canvas Scaler", null)]
[VisibleIf("IsScaleWithResolution", false)]
public Float2 ResolutionMax { get; set; }
Property Value
Float2
|
ResolutionMin
The UI Canvas minimum resolution. If the screen has lower size, then the interface will be scaled accordingly. Used only in ScaleWithResolution mode.
Declaration
[EditorOrder(120)]
[EditorDisplay("Canvas Scaler", null)]
[VisibleIf("IsScaleWithResolution", false)]
public Float2 ResolutionMin { get; set; }
Property Value
Float2
|
ResolutionMode
The UI Canvas resolution scaling mode. Controls min/max resolutions usage in relation to the current screen resolution to compute the UI scale. Used only in ScaleWithResolution mode.
Declaration
[EditorOrder(120)]
[EditorDisplay("Canvas Scaler", null)]
[VisibleIf("IsScaleWithResolution", false)]
public CanvasScaler.ResolutionScalingMode ResolutionMode { get; set; }
Property Value
CanvasScaler.ResolutionScalingMode
|
ScaleFactor
The UI Canvas scale. Applied in all scaling modes for custom UI sizing.
Declaration
[EditorOrder(10)]
[EditorDisplay("Canvas Scaler", null)]
[Limit(0.001F, 1000F, 0.01F)]
public float ScaleFactor { get; set; }
Property Value
System.Single
|
Scaling
The UI Canvas scaling mode.
Declaration
[EditorOrder(0)]
[EditorDisplay("Canvas Scaler", null)]
[ExpandGroups]
public CanvasScaler.ScalingMode Scaling { get; set; }
Property Value
CanvasScaler.ScalingMode
|
Methods
ContainsPoint(ref Float2, Boolean)
Checks if this control contains given point in local Control Space.
Declaration
public override bool ContainsPoint(ref Float2 location, bool precise = false)
Parameters
Float2
location
Point location in Control Space to check |
System.Boolean
precise
True if perform precise intersection test against the control content (eg. with hit mask or transparency threshold). Otherwise, only simple bounds-check will be performed. |
Returns
System.Boolean
True if point is inside control's area, otherwise false. |
Overrides
Draw()
Draw the control and the children.
Declaration
public override void Draw()
Overrides
GetDesireClientArea(out Rectangle)
Gets the desire client area rectangle for all the controls.
Declaration
public override void GetDesireClientArea(out Rectangle rect)
Parameters
Rectangle
rect
The client area rectangle for child controls. |
Overrides
IntersectsChildContent(Control, Float2, out Float2)
Checks if given point in this container control space intersects with the child control content. Also calculates result location in child control space which can be used to feed control with event at that point.
Declaration
public override bool IntersectsChildContent(Control child, Float2 location, out Float2 childSpaceLocation)
Parameters
Control
child
The child control to check. |
Float2
location
The location in this container control space. |
Float2
childSpaceLocation
The output location in child control space. |
Returns
System.Boolean
True if point is over the control content, otherwise false. |
Overrides
IntersectsContent(ref Float2, out Float2)
Checks if given location point in Parent Space intersects with the control content and calculates local position.
Declaration
public override bool IntersectsContent(ref Float2 locationParent, out Float2 location)
Parameters
Float2
locationParent
The location in Parent Space. |
Float2
location
The location of intersection in Control Space. |
Returns
System.Boolean
True if given point in Parent Space intersects with this control content, otherwise false. |
Overrides
PerformLayoutBeforeChildren()
Perform layout for that container control before performing it for child controls.
Declaration
protected override void PerformLayoutBeforeChildren()
Overrides
PointFromParent(ref Float2)
Converts point in parent control coordinates into local control's space.
Declaration
public override Float2 PointFromParent(ref Float2 location)
Parameters
Float2
location
|
Returns
Float2
The converted point location in control's space. |
Overrides
PointToParent(ref Float2)
Converts point in local control's space into parent control coordinates.
Declaration
public override Float2 PointToParent(ref Float2 location)
Parameters
Float2
location
The input location of the point to convert. |
Returns
Float2
The converted point location in parent control coordinates. |
Overrides
RayCast(ref Float2, out Control)
Performs a raycast against UI controls hierarchy to find any intersecting control content. Uses ContainsPoint(ref Float2, Boolean) with precise check (skips transparent surfaces and empty panels).
Declaration
public override bool RayCast(ref Float2 location, out Control hit)
Parameters
Float2
location
The position to intersect UI with. |
Control
hit
The result control that intersects with the raycast. |
Returns
System.Boolean
True if ray hits any matching control, otherwise false. |
Overrides
UpdateScale()
Updates the scaler for the current setup.
Declaration
public void UpdateScale()