Beispiel #1
0
            public DropListOption(Rectangle bounds, int index, string label, TValue value, SpriteFont font)
                : base(bounds, index.ToString(), label)
            {
                Index = index;
                Value = value;

                var labelSize = font.MeasureString(label);

                LabelWidth  = RenderHelpers.GetLabelWidth(font) - 10;
                LabelHeight = (int)labelSize.Y;
            }
Beispiel #2
0
        public DropdownList(TValue selectedValue, TValue[] items, Func <TValue, string> getLabel, int x, int y,
                            SpriteFont font)
            : base(new Rectangle(), nameof(DropdownList <TValue>))
        {
            _options = items
                       .Select((i, index) => new DropListOption(Rectangle.Empty, index, getLabel(i), i, font))
                       .ToArray();

            _font       = font;
            _labelWidth = RenderHelpers.GetLabelWidth(_font);

            MaxLabelHeight = _options.Max(p => p.LabelHeight);

            var selectedIndex = Array.IndexOf(items, selectedValue);

            _selectedOption = selectedIndex >= 0 ? _options[selectedIndex] : _options.First();

            bounds.X = x;
            bounds.Y = y;

            ReinitializeComponents();
        }