Exemplo n.º 1
0
        public Listbox(int dropDownLength, int width, IResourceCache resourceCache,
                       List <string> initialOptions = null)
        {
            _resourceCache = resourceCache;

            _width        = width;
            _listboxLeft  = _resourceCache.GetSprite("button_left");
            _listboxMain  = _resourceCache.GetSprite("button_middle");
            _listboxRight = _resourceCache.GetSprite("button_right");

            _selectedLabel = new TextSprite("ListboxLabel", "", _resourceCache.GetResource <FontResource>(@"Fonts/CALIBRI.TTF").Font)
            {
                Color = Color4.Black
            };

            _dropDown = new ScrollableContainer("ListboxContents", new Vector2i(width, dropDownLength), _resourceCache);
            _dropDown.SetVisible(false);

            if (initialOptions != null)
            {
                _contentStrings = initialOptions;
                RebuildList();
            }

            Update(0);
        }
Exemplo n.º 2
0
        private void SetItem(Label toSet, bool raiseEvent = false)
        {
            if (ItemSelected != null && raiseEvent)
            {
                ItemSelected(toSet, this);
            }

            CurrentlySelected   = toSet;
            _selectedLabel.Text = toSet.Text.Text;
            _dropDown.SetVisible(false);

            ((ListboxItem)toSet).Selected = true;
            IEnumerable <ListboxItem> notSelected = from ListboxItem item in _dropDown.components
                                                    where item != toSet
                                                    select item;

            foreach (ListboxItem curr in notSelected)
            {
                curr.Selected = false;
            }
        }