Exemple #1
0
 /// <summary>
 /// Initialize the layout grid.
 /// </summary>
 /// <param name="gui">The GUI that this layout will be a part of.</param>
 /// <param name="position">The position of this layout.</param>
 /// <param name="height">The height of this layout.</param>
 /// <param name="width">The width of this layout.</param>
 private void Initialize(GraphicalUserInterface gui, Vector2 position, float width, float height)
 {
     //Initialize some variables.
     _GUI = gui;
     _IsEnabled = true;
     _Position = position;
     _Width = width;
     _Height = height;
     _MaxColumns = 3;
     _MaxRows = 12;
     _Padding = 5;
     _Margin = 5;
     _Grid = new LayoutCell[_MaxColumns, _MaxRows];
     _SizeStyle = LayoutSizeStyle.Evenly;
     _LayoutFlow = LayoutFlowStyle.Vertically;
     _VerticalAlignment = LayoutVerticalAlignment.TopDown;
     _HorizontalAlignment = LayoutHorizontalAlignment.LeftToRight;
     _IsDirty = false;
 }
Exemple #2
0
        /// <summary>
        /// Get the available space for a row or column based upon padding, margin, the number of elements and their current size.
        /// </summary>
        /// <param name="index">The index of the row or column.</param>
        /// <param name="structure">Whether it is a row or column we are checking.</param>
        /// <param name="sizeStyle">Whether we want to distribute the available size evenly or to the cell first in line.</param>
        /// <returns>The amount of 'free' space available for the given row or column.</returns>
        private float GetAvailableSpace(int index, LayoutStructure structure, LayoutSizeStyle sizeStyle)
        {
            //Whether to check a row or column.
            switch (structure)
            {
                case (LayoutStructure.Row):
                    {
                        //The space available.
                        float available = AvailableWidth - ((RowCount(index) - 1) * _Margin);

                        //Subtract the width of all cells.
                        if (sizeStyle == LayoutSizeStyle.FirstInLine)
                        {
                            for (int x = 0; x < _Grid.GetLength(0); x++) { if (_Grid[x, index] != null) { available -= _Grid[x, index].GoalWidth; } }
                        }

                        //Return the available space.
                        return available;
                    }
                case (LayoutStructure.Column):
                    {
                        //The space available.
                        float available = AvailableHeight - ((ColumnCount(index) - 1) * _Margin);

                        //Subtract the height of all cells.
                        if (sizeStyle == LayoutSizeStyle.FirstInLine)
                        {
                            for (int y = 0; y < _Grid.GetLength(1); y++) { if (_Grid[index, y] != null) { available -= _Grid[index, y].GoalHeight; } }
                        }

                        //Return the available space.
                        return available;
                    }
                default: { return 0; }
            }
        }