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