Beispiel #1
0
        public SearchPopup(VisualElement _rootElement, List <TItem> _listItems, Vector2 _position, Vector2 _parentMinMaxX)
        {
            style.position = Position.Absolute;

            style.maxWidth  = MAX_WIDTH;
            style.maxHeight = MAX_HEIGHT;

            float xPosition;

            if (_position.x + MAX_WIDTH < _parentMinMaxX.y)
            {
                xPosition = _position.x;
            }
            else
            {
                if (_position.x - MAX_WIDTH > _parentMinMaxX.x)
                {
                    xPosition = _position.x - MAX_WIDTH;
                }
                else
                {
                    float DifferenceToMax = _position.x + MAX_WIDTH - _parentMinMaxX.y;

                    xPosition = _position.x - (DifferenceToMax + 10);
                }
            }

            style.top    = _position.y;
            style.bottom = 0;
            style.left   = xPosition;
            style.right  = 0;

            AddToClassList(USS_CLASS_NAME);
            AddToClassList("lightBackground");

            m_SearchField.AddToClassList(USS_CLASS_NAME_SEARCHFIELD);
            Add(m_SearchField);
            m_SearchField.RegisterCallback <ChangeEvent <string> >(SearchFieldChanged);

            foreach (var item in _listItems)
            {
                var basicListItem = new BasicListItem <TItem>(_description: item,
                                                              _useDeleteContextManipulator: false,
                                                              _useDuplicateManipulator: false);

                m_ListItems.Add(basicListItem);
            }

            m_ListItems = m_ListItems.OrderBy(_entry => _entry.GetDescription().DisplayName).ToList();

            SearchFieldChanged(new ChangeEvent <string>());

            m_ScrollView.AddToClassList(USS_CLASS_NAME_SCROLLVIEW);
            Add(m_ScrollView);

            m_RootElement = _rootElement;
            m_RootElement.RegisterCallback <MouseDownEvent>(ClickedInWindow);
            m_RootElement.RegisterCallback <GeometryChangedEvent>(WindowGeometryChanged);
        }
Beispiel #2
0
        private void UpdateSelectedItem(BasicListItem <TItem> _item)
        {
            if (m_SelectedItem != null)
            {
                m_SelectedItem.RemoveFromClassList("selected");
            }

            _item.AddToClassList("selected");
            m_SelectedItem = _item;
        }