private void ShowDropdown(float x, float y, float width, GUIStyle buttonStyle)
        {
            var rect = GUIUtil.R(x, y, width, _viewModel.Options.Count * GUIUtil.RowHeight > MaxHeight ? MaxHeight : _viewModel.Options.Count * GUIUtil.RowHeight);

            GUILayout.BeginArea(rect, GUIUtil.NoSpacingBoxStyle);
            _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, GUIStyle.none);

            var style = _viewModel.CurrentSelection == null ? GUIUtil.NoMarginButtonPressedStyle : GUIUtil.NoMarginButtonStyle;

            if (GUILayout.Button(_unselect, style, null))
            {
                _viewModel.Select(null);
                _isShown = false;
            }

            foreach (var option in _viewModel.Options)
            {
                style       = option.IsSelected() ? GUIUtil.NoMarginButtonPressedStyle : GUIUtil.NoMarginButtonStyle;
                GUI.enabled = option?.IsEnabled() ?? true;
                if (GUILayout.Button(option.Text, style, null))
                {
                    _viewModel.Select(option);
                    _isShown = false;
                }
                GUI.enabled = true;
            }

            GUILayout.EndScrollView();
            GUILayout.EndArea();
        }
        public void OnGUI()
        {
            bool clicked = GUI.Button(GUIUtil.R(_x, _y, _width, GUIUtil.RowHeight), _viewModel.CurrentSelection?.Text ?? _noSelection, _isShown ? GUIUtil.NoMarginButtonPressedStyle : GUI.skin.button);

            if (clicked)
            {
                _isShown = !_isShown;
            }

            if (_isShown)
            {
                ShowDropdown(_x, _y + GUIUtil.RowHeight, _width, GUI.skin.button);
            }

            if (!clicked && Event.current.isMouse)
            {
                _isShown = false;
            }
        }
        public bool OnGUI(bool enabled)
        {
            var previouslyEnabled = GUI.enabled;

            try
            {
                GUI.enabled = enabled;

                bool clicked = GUI.Button(GUIUtil.R(_x, _y, _width, GUIUtil.RowHeight), _viewModel.CurrentSelection?.Text ?? _noSelection, _isShown ? GUIUtil.NoMarginButtonPressedStyle : GUI.skin.button);
                if (clicked)
                {
                    _isShown = !_isShown;
                }

                if (!enabled)
                {
                    _isShown = false;
                }

                if (_isShown)
                {
                    ShowDropdown(_x, _y + GUIUtil.RowHeight, _width, GUI.skin.button);
                }

                if (!clicked && Event.current.isMouse)
                {
                    _isShown = false;
                }

                return(_isShown);
            }
            finally
            {
                GUI.enabled = previouslyEnabled;
            }
        }