Beispiel #1
0
        public override void OnMouseDown(MouseButton button, int x, int y)
        {
            if (ScrollThumbRect.Translated(0, TranslateY).Contains(x, y))
            {
                _scrolling = true;

                _lastMouseY = y;
            }
            else
            {
                if (HoveredIndex > -1)
                {
                    if (HoveredIndex == SelectedIndex)
                    {
                        SelectedIndex = -1;
                    }
                    else
                    {
                        SelectedIndex = HoveredIndex;

                        SelectedItem = Items[SelectedIndex];
                        OnSelect?.Invoke(SelectedItem);
                    }
                }
            }
        }
Beispiel #2
0
        public override void OnMouseMove(int x, int y)
        {
            if (_scrolling)
            {
                HoveredIndex = -1;

                var delta_y = y - _lastMouseY;

                TranslateY += delta_y;

                if (TranslateY < 0)
                {
                    TranslateY = 0;
                }

                if (TranslateY > _maxTranslateY)
                {
                    TranslateY = _maxTranslateY;
                }

                _lastMouseY = y;
            }
            else
            {
                if (ScrollThumbRect.Translated(0, TranslateY).Contains(x, y))
                {
                    HoveredIndex = -1;
                }
                else
                {
                    HoveredIndex = (y + TranslateY) / RowHeight;

                    if (HoveredIndex > Items.Count - 1 || HoveredIndex < 0)
                    {
                        HoveredIndex = -1;
                    }
                }
            }
        }