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();
        }
Esempio n. 2
0
 public DropdownOptionViewModel(string text, Func <bool> isSelected, Func <bool> isEnabled, TSelection selection)
 {
     Text       = GUIUtil.CreateContent(text);
     IsSelected = isSelected;
     IsEnabled  = isEnabled;
     Selection  = selection;
 }
 public ToggleViewModel(string text, string enabledTooltip, string disabledTooltip, Action onToggled, Func <bool> isToggled, bool enabled = true)
 {
     _enabled  = GUIUtil.CreateContent(text, enabledTooltip);
     _disabled = GUIUtil.CreateContent(text, disabledTooltip);
     OnToggled = onToggled;
     IsToggled = isToggled;
     Enabled   = enabled;
 }
        public DropdownGUI(float x, float y, float width, DropdownViewModel <TDropdownOptionViewModel, TSelection> viewModel)
        {
            _x           = x;
            _y           = y;
            _width       = width;
            _noSelection = GUIUtil.CreateContent(viewModel.NoSelection, viewModel.NoSelectionTooltip);
            _unselect    = GUIUtil.CreateContent(viewModel.Unselect, viewModel.UnselectTooltip);

            _viewModel = viewModel;
        }
Esempio n. 5
0
 public TranslatorDropdownOptionViewModel(bool fallback, Func <bool> isSelected, TranslationEndpointManager selection) : base(selection.Endpoint.FriendlyName, isSelected, () => selection.Error == null, selection)
 {
     if (fallback)
     {
         _selected = GUIUtil.CreateContent(selection.Endpoint.FriendlyName, $"<b>CURRENT FALLBACK TRANSLATOR</b>\n{selection.Endpoint.FriendlyName} is the currently selected fallback translator that will be used to perform translations when the primary translator fails.");
         _disabled = GUIUtil.CreateContent(selection.Endpoint.FriendlyName, $"<b>CANNOT SELECT FALLBACK TRANSLATOR</b>\n{selection.Endpoint.FriendlyName} cannot be selected because the initialization failed. {selection.Error?.Message}");
         _normal   = GUIUtil.CreateContent(selection.Endpoint.FriendlyName, $"<b>SELECT FALLBACK TRANSLATOR</b>\n{selection.Endpoint.FriendlyName} will be selected as fallback translator.");
     }
     else
     {
         _selected = GUIUtil.CreateContent(selection.Endpoint.FriendlyName, $"<b>CURRENT TRANSLATOR</b>\n{selection.Endpoint.FriendlyName} is the currently selected translator that will be used to perform translations.");
         _disabled = GUIUtil.CreateContent(selection.Endpoint.FriendlyName, $"<b>CANNOT SELECT TRANSLATOR</b>\n{selection.Endpoint.FriendlyName} cannot be selected because the initialization failed. {selection.Error?.Message}");
         _normal   = GUIUtil.CreateContent(selection.Endpoint.FriendlyName, $"<b>SELECT TRANSLATOR</b>\n{selection.Endpoint.FriendlyName} will be selected as translator.");
     }
 }
        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;
            }
        }
 public ButtonViewModel(string text, string tooltip, Action onClicked, Func <bool> canClick)
 {
     Text      = GUIUtil.CreateContent(text, tooltip);
     OnClicked = onClicked;
     CanClick  = canClick;
 }