From ced3d03bdb3ce866d832e03fb212865140905a9a Mon Sep 17 00:00:00 2001 From: Thomas Leyh Date: Sun, 24 Jul 2016 08:14:18 +0200 Subject: Add project files. --- V3/Widgets/VerticalMenu.cs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 V3/Widgets/VerticalMenu.cs (limited to 'V3/Widgets/VerticalMenu.cs') 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 +{ + /// + /// A simple menu with vertically arranged widgets. All widgets are made + /// the same size (the maximum widget size). + /// + // 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); + } + } +} -- cgit v1.2.1