Exemplo n.º 1
0
        /// <summary>
        /// Called every frame after update.
        /// DropDown entity override this function to close the list if necessary and to remove the selected item panel from self.
        /// </summary>
        override protected void DoAfterUpdate()
        {
            // if list currently visible we want to check if we need to close it
            if (ListVisible)
            {
                // check if mouse down and not inside list
                var mousePosition = GetMousePos();
                if (MouseInput.AnyMouseButtonPressed() && !IsTouching(mousePosition))
                {
                    ListVisible = false;
                }
            }

            // call base do-before-update
            base.DoAfterUpdate();

            // do we have a selected item?
            if (HasSelectedValue)
            {
                // trigger per-item events, but only if value changed
                if (SelectedIndex != _lastSelected)
                {
                    System.Action callback = null;
                    if (_perItemCallbacks.TryGetValue(_selectList.SelectedValue, out callback))
                    {
                        callback.Invoke();
                    }
                }

                // if set to not keep selected value, return to original placeholder
                if (DontKeepSelection && SelectedIndex != -1)
                {
                    Unselect();
                }
            }

            // store last known index
            _lastSelected = SelectedIndex;
        }