Added pivot relative resizing to GUI Controls
This commit is contained in:
@@ -169,6 +169,12 @@ namespace FlaxEngine.GUI
|
|||||||
set => Bounds = new Rectangle(value + (_parent != null ? _parent.Bounds.Size * (_anchorMax + _anchorMin) * 0.5f : Float2.Zero) - _bounds.Size * _pivot, _bounds.Size);
|
set => Bounds = new Rectangle(value + (_parent != null ? _parent.Bounds.Size * (_anchorMax + _anchorMin) * 0.5f : Float2.Zero) - _bounds.Size * _pivot, _bounds.Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to resize the UI Control based on where the pivot is rather than just the top-left.
|
||||||
|
/// </summary>
|
||||||
|
[ExpandGroups, EditorDisplay("Transform"), EditorOrder(1060)]
|
||||||
|
public bool PivotRelative = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets width of the control.
|
/// Gets or sets width of the control.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -180,7 +186,13 @@ namespace FlaxEngine.GUI
|
|||||||
{
|
{
|
||||||
if (Mathf.NearEqual(_bounds.Size.X, value))
|
if (Mathf.NearEqual(_bounds.Size.X, value))
|
||||||
return;
|
return;
|
||||||
var bounds = new Rectangle(_bounds.Location, value, _bounds.Size.Y);
|
var rectLocation = _bounds.Location;
|
||||||
|
if (PivotRelative)
|
||||||
|
{
|
||||||
|
var delta = _bounds.Size.X - value;
|
||||||
|
rectLocation.X += delta * Pivot.X;
|
||||||
|
}
|
||||||
|
var bounds = new Rectangle(rectLocation, value, _bounds.Size.Y);
|
||||||
SetBounds(ref bounds);
|
SetBounds(ref bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,7 +208,13 @@ namespace FlaxEngine.GUI
|
|||||||
{
|
{
|
||||||
if (Mathf.NearEqual(_bounds.Size.Y, value))
|
if (Mathf.NearEqual(_bounds.Size.Y, value))
|
||||||
return;
|
return;
|
||||||
var bounds = new Rectangle(_bounds.Location, _bounds.Size.X, value);
|
var rectLocation = _bounds.Location;
|
||||||
|
if (PivotRelative)
|
||||||
|
{
|
||||||
|
var delta = _bounds.Size.Y - value;
|
||||||
|
rectLocation.Y += delta * Pivot.Y;
|
||||||
|
}
|
||||||
|
var bounds = new Rectangle(rectLocation, _bounds.Size.X, value);
|
||||||
SetBounds(ref bounds);
|
SetBounds(ref bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user