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}");
                }
            }
        }
        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));
        }
Esempio 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}");
                }
            }
        }
Esempio 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);
        }
Esempio n. 5
0
        protected TextInfo GetTextInfo(IGuiContext context, string text, Rectangle targetRectangle, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Rectangle?clippingRectangle = null)
        {
            var font                 = Font ?? context.DefaultFont;
            var textSize             = font.GetStringRectangle(text ?? string.Empty, Vector2.Zero).Size;
            var destinationRectangle = GuiLayoutHelper.AlignRectangle(horizontalAlignment, verticalAlignment, textSize, targetRectangle);
            var textPosition         = destinationRectangle.Location.ToVector2();
            var textInfo             = new TextInfo(text, font, textPosition, textSize, TextColor, clippingRectangle ?? ClippingRectangle);

            return(textInfo);
        }
        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
            });
        }
 protected static void PlaceControl(IGuiContext context, GuiControl control, float x, float y, float width, float height)
 {
     GuiLayoutHelper.PlaceControl(context, control, x, y, width, height);
 }