Exemplo n.º 1
0
        public override void Layout(IGuiContext context, RectangleF rectangle)
        {
            var x             = 0f;
            var y             = 0f;
            var availableSize = rectangle.Size;

            foreach (var control in Controls)
            {
                var desiredSize = GuiLayoutHelper.GetSizeWithMargins(control, context, availableSize);

                switch (Orientation)
                {
                case GuiOrientation.Vertical:
                    PlaceControl(context, control, x, y, Width, desiredSize.Height);
                    y += desiredSize.Height;
                    availableSize.Height -= desiredSize.Height;
                    break;

                case GuiOrientation.Horizontal:
                    PlaceControl(context, control, x, y, desiredSize.Width, Height);
                    x += desiredSize.Width;
                    availableSize.Height -= desiredSize.Height;
                    break;

                default:
                    throw new InvalidOperationException($"Unexpected orientation {Orientation}");
                }
            }
        }
Exemplo n.º 2
0
        protected override Size2 CalculateDesiredSize(IGuiContext context, Size2 availableSize)
        {
            var width  = 0f;
            var height = 0f;

            foreach (var control in Controls)
            {
                var desiredSize = GuiLayoutHelper.GetSizeWithMargins(control, context, availableSize);

                switch (Orientation)
                {
                case GuiOrientation.Horizontal:
                    width += desiredSize.Width;
                    height = desiredSize.Height > height ? desiredSize.Height : height;
                    break;

                case GuiOrientation.Vertical:
                    width   = desiredSize.Width > width ? desiredSize.Width : width;
                    height += desiredSize.Height;
                    break;

                default:
                    throw new InvalidOperationException($"Unexpected orientation {Orientation}");
                }
            }

            return(new Size2(width, height));
        }
Exemplo n.º 3
0
        public override void Layout(IGuiContext context, RectangleF rectangle)
        {
            var x             = (float)Padding.Left;
            var y             = (float)Padding.Top;
            var availableSize = rectangle.Size;

            foreach (var control in Controls)
            {
                var desiredSize = GuiLayoutHelper.GetSizeWithMargins(control, context, availableSize);

                switch (Orientation)
                {
                case GuiOrientation.Vertical:
                    control.VerticalAlignment = VerticalAlignment.Top;

                    PlaceControl(context, control, 0f, y, Width, desiredSize.Height);
                    y += desiredSize.Height + Spacing;
                    availableSize.Height -= desiredSize.Height;
                    break;

                case GuiOrientation.Horizontal:
                    control.HorizontalAlignment = HorizontalAlignment.Left;

                    PlaceControl(context, control, x, 0f, desiredSize.Width, Height);
                    x += desiredSize.Width + Spacing;
                    availableSize.Height -= desiredSize.Height;
                    break;

                default:
                    throw new InvalidOperationException($"Unexpected orientation {Orientation}");
                }
            }
        }
Exemplo n.º 4
0
        protected override Size2 CalculateDesiredSize(IGuiContext context, Size2 availableSize)
        {
            var sizes  = Controls.Select(control => GuiLayoutHelper.GetSizeWithMargins(control, context, availableSize)).ToArray();
            var width  = sizes.Max(s => s.Width);
            var height = sizes.Max(s => s.Height);

            return(new Size2(width, height) + Padding.Size);
        }
Exemplo n.º 5
0
        private GridInfo CalculateGridInfo(IGuiContext context, Size2 availableSize)
        {
            var columns       = Columns == 0 ? (int)Math.Ceiling(Math.Sqrt(Controls.Count)) : Columns;
            var rows          = Rows == 0 ? (int)Math.Ceiling((float)Controls.Count / columns) : Rows;
            var maxCellWidth  = availableSize.Width / columns;
            var maxCellHeight = availableSize.Height / rows;
            var sizes         = Controls
                                .Select(control => GuiLayoutHelper.GetSizeWithMargins(control, context, new Size2(maxCellWidth, maxCellHeight)))
                                .ToArray();
            var maxControlWidth  = sizes.Length == 0 ? 0 : sizes.Max(s => s.Width);
            var maxControlHeight = sizes.Length == 0 ? 0 : sizes.Max(s => s.Height);

            return(new GridInfo
            {
                Columns = columns,
                Rows = rows,
                MinCellWidth = Math.Min(maxControlWidth, maxCellWidth),
                MinCellHeight = Math.Min(maxControlHeight, maxCellHeight),
                MaxCellWidth = maxCellWidth,
                MaxCellHeight = maxCellHeight
            });
        }