// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved. namespace FlaxEngine.GUI { /// /// This panel arranges child controls horizontally. /// /// public class HorizontalPanel : PanelWithMargins { /// /// Initializes a new instance of the class. /// public HorizontalPanel() { } /// protected override void PerformLayoutBeforeChildren() { base.PerformLayoutBeforeChildren(); // Pre-set height of all controls float h = Height - _margin.Height; for (int i = 0; i < _children.Count; i++) { Control c = _children[i]; if (c.Visible) { c.Height = h; } } } /// protected override void PerformLayoutAfterChildren() { // Sort controls from left to right float x = _margin.Left; float h = Height - _margin.Height; bool hasAnyItem = false; for (int i = 0; i < _children.Count; i++) { Control c = _children[i]; if (c.Visible) { var w = c.Width; c.Bounds = new Rectangle(x + _offset.X, _margin.Top + _offset.Y, h, w); x = c.Right + _spacing; hasAnyItem = true; } } if (hasAnyItem) x -= _spacing; x += _margin.Right; // Update size if (_autoSize) Width = x; } } }