diff --git a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs index a25a98c86..1c8e646e3 100644 --- a/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/HorizontalPanel.cs @@ -80,6 +80,24 @@ namespace FlaxEngine.GUI size.Y = maxHeight; Size = size; } + else if (_alignment != TextAlignment.Near && hasAnyLeft) + { + // Apply layout alignment + var offset = Width - left - _margin.Right; + if (_alignment == TextAlignment.Center) + offset *= 0.5f; + for (int i = 0; i < _children.Count; i++) + { + Control c = _children[i]; + if (c.Visible) + { + if (Mathf.IsZero(c.AnchorMin.X) && Mathf.IsZero(c.AnchorMax.X)) + { + c.X += offset; + } + } + } + } } } } diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index 071f0ccf2..18bd1a52d 100644 --- a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs +++ b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs @@ -30,6 +30,11 @@ namespace FlaxEngine.GUI /// protected Float2 _offset; + /// + /// The child controls alignment within layout area. + /// + protected TextAlignment _alignment = TextAlignment.Near; + /// /// Gets or sets the left margin. /// @@ -172,6 +177,23 @@ namespace FlaxEngine.GUI } } + /// + /// Gets or sets the child controls alignment within layout area. + /// + [EditorOrder(50), VisibleIf(nameof(AutoSize), true)] + public TextAlignment Alignment + { + get => _alignment; + set + { + if (_alignment != value) + { + _alignment = value; + PerformLayout(); + } + } + } + /// /// Initializes a new instance of the class. /// diff --git a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs index 9ee2a2297..aae95bd43 100644 --- a/Source/Engine/UI/GUI/Panels/VerticalPanel.cs +++ b/Source/Engine/UI/GUI/Panels/VerticalPanel.cs @@ -80,6 +80,24 @@ namespace FlaxEngine.GUI size.X = maxWidth; Size = size; } + else if (_alignment != TextAlignment.Near && hasAnyTop) + { + // Apply layout alignment + var offset = Height - top - _margin.Bottom; + if (_alignment == TextAlignment.Center) + offset *= 0.5f; + for (int i = 0; i < _children.Count; i++) + { + Control c = _children[i]; + if (c.Visible) + { + if (Mathf.IsZero(c.AnchorMin.Y) && Mathf.IsZero(c.AnchorMax.Y)) + { + c.Y += offset; + } + } + } + } } } }