summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/source/MonoGame.Extended.Gui/Controls/ListBox.cs
blob: d456e0730d719327654d83f1eb45e6231f7f3282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Microsoft.Xna.Framework;

namespace MonoGame.Extended.Gui.Controls
{
    public class ListBox : SelectorControl
    {
        public ListBox()
        {
        }

        public override Size GetContentSize(IGuiContext context)
        {
            var width = 0;
            var height = 0;

            foreach (var item in Items)
            {
                var itemSize = GetItemSize(context, item);

                if (itemSize.Width > width)
                    width = itemSize.Width;

                height += itemSize.Height;
            }

            return new Size(width + ClipPadding.Width, height + ClipPadding.Height);
        }

        public override void Draw(IGuiContext context, IGuiRenderer renderer, float deltaSeconds)
        {
            base.Draw(context, renderer, deltaSeconds);

            ScrollIntoView(context);
            DrawItemList(context, renderer);
        }

        protected override Rectangle GetListAreaRectangle(IGuiContext context)
        {
            return ContentRectangle;
        }
    }
}