mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 20:12:23 +00:00
* Adding in changes to deal with custom control types for loading from a GuiScreen, also adding in block text if a width for the element exists. Adding in Padding to some elements to give the developer some more options in styles. Adding in some changes to the textbox to deal with selecting a section of text. * Adding in a few changes to deal with propagation down the GuiControl tree, this was added to most events. Also, adding in the idea of a form and submit button to deal with keyboard controls when inside of a form. This gives simalar behavier to how forms work in the browser. * Adding in the enter key skip for the textbox.
86 lines
3.0 KiB
C#
86 lines
3.0 KiB
C#
using System;
|
|
|
|
namespace MonoGame.Extended.Gui.Controls
|
|
{
|
|
public class GuiStackPanel : GuiLayoutControl
|
|
{
|
|
public GuiStackPanel()
|
|
: this(null)
|
|
{
|
|
}
|
|
|
|
public GuiStackPanel(GuiSkin skin)
|
|
: base(skin)
|
|
{
|
|
HorizontalAlignment = HorizontalAlignment.Centre;
|
|
VerticalAlignment = VerticalAlignment.Centre;
|
|
}
|
|
|
|
public GuiOrientation Orientation { get; set; } = GuiOrientation.Vertical;
|
|
|
|
public Thickness Padding { get; set; }
|
|
|
|
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}");
|
|
}
|
|
}
|
|
|
|
width += Padding.Left + Padding.Right;
|
|
height += Padding.Top + Padding.Bottom;
|
|
|
|
return new Size2(width, height);
|
|
}
|
|
|
|
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;
|
|
availableSize.Height -= desiredSize.Height;
|
|
break;
|
|
case GuiOrientation.Horizontal:
|
|
control.HorizontalAlignment = HorizontalAlignment.Left;
|
|
|
|
PlaceControl(context, control, x, 0f, desiredSize.Width, Height);
|
|
x += desiredSize.Width;
|
|
availableSize.Height -= desiredSize.Height;
|
|
break;
|
|
default:
|
|
throw new InvalidOperationException($"Unexpected orientation {Orientation}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|