diff options
Diffstat (limited to 'V3/Widgets/VerticalMenu.cs')
-rw-r--r-- | V3/Widgets/VerticalMenu.cs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/V3/Widgets/VerticalMenu.cs b/V3/Widgets/VerticalMenu.cs new file mode 100644 index 0000000..bc18439 --- /dev/null +++ b/V3/Widgets/VerticalMenu.cs @@ -0,0 +1,42 @@ +using Microsoft.Xna.Framework; +using System.Linq; + +namespace V3.Widgets +{ + /// <summary> + /// A simple menu with vertically arranged widgets. All widgets are made + /// the same size (the maximum widget size). + /// </summary> + // ReSharper disable once ClassNeverInstantiated.Global + public sealed class VerticalMenu : AbstractMenu + { + private float mPadding = 10; + + public VerticalMenu(GraphicsDeviceManager graphicsDeviceManager) : base(graphicsDeviceManager) + { + } + + protected override void UpdateWidgetRelativePositions() + { + var y = 0f; + foreach (var widget in Widgets) + { + widget.Position = new Vector2(0, y); + y += widget.Size.Y; + y += mPadding; + } + } + + protected override Vector2 GetTotalSize() + { + var totalX = Widgets.Max(w => w.Size.X); + var totalY = (Widgets.Count - 1) * mPadding + Widgets.Sum(w => w.Size.Y); + return new Vector2(totalX, totalY); + } + + protected override void UpdateWidgetSizes() + { + MakeWidgetsSameSize(Widgets); + } + } +} |