コード例 #1
0
        void OnVerticalValueChange(ChangeEvent <string> evt)
        {
            var newValue = evt.newValue + "-" + m_HorizontalButtonStrip.value;

            evt.StopPropagation();
            value = newValue;
        }
コード例 #2
0
 protected void ValueChanged(ChangeEvent <T> e)
 {
     e.StopPropagation();
     if (!m_IgnoreNotification)
     {
         SetValueAndNotify(e.newValue);
     }
 }
コード例 #3
0
 void OnControlChange(ChangeEvent <U> e)
 {
     e.StopPropagation();
     using (ChangeEvent <U> evt = ChangeEvent <U> .GetPooled(e.previousValue, e.newValue))
     {
         evt.target = this;
         SendEvent(evt);
     }
 }
コード例 #4
0
        void OnToggleChanged(ChangeEvent <bool> evt)
        {
            if (evt.target is Toggle t)
            {
                evt.StopPropagation();

                if (evt.newValue == false)
                {
                    t.SetValueWithoutNotify(true);
                    return;
                }

                var currentSelectedItem = default(Toggle);
                var newSelectedItem     = default(Toggle);;
                var list = m_ToggleQuery.ToList();

                foreach (var toggle in list)
                {
                    if (currentSelectedItem != null && newSelectedItem != null)
                    {
                        break;
                    }

                    if (ReferenceEquals(t, toggle))
                    {
                        newSelectedItem = toggle;
                    }

                    if (toggle.value && !ReferenceEquals(t, toggle))
                    {
                        toggle.SetValueWithoutNotify(false);
                        currentSelectedItem = toggle;
                    }
                }

                using (var newEvent = ChangeEvent <Toggle> .GetPooled(currentSelectedItem, newSelectedItem))
                {
                    newEvent.target = this;
                    SendEvent(newEvent);
                }
            }
        }
コード例 #5
0
            protected virtual void OnTextChange(ChangeEvent <string> e)
            {
                m_Options.Clear();
                BuildList(e.newValue, m_Options);

                int optionsCount = Mathf.Min(m_Options.Count, 4);

                if (m_Labels.Count > optionsCount)
                {
                    for (int i = optionsCount; i < m_Labels.Count; i++)
                    {
                        Remove(m_Labels[i]);
                        m_Labels[i] = null;
                    }
                }
                else if (m_Labels.Count < optionsCount)
                {
                    for (int i = m_Labels.Count; i < optionsCount; i++)
                    {
                        var label = new Label();
                        label.AddToClassList("auto-complete");
                        int index = i;
                        label.RegisterCallback <MouseDownEvent>(evt =>
                        {
                            SetValue(index);
                            e.StopPropagation();
                        });
                        m_Labels.Add(label);
                        Add(label);
                    }
                }

                m_Labels.RemoveAll(l => l == null);

                for (int i = 0; i < m_Labels.Count; i++)
                {
                    m_Labels[i].text = m_Options[i];
                }
            }
コード例 #6
0
 public void AddTask(ChangeEvent <string> e)
 {
     AddTask();
     // Prevent the text field from handling this key.
     e.StopPropagation();
 }
コード例 #7
0
 private void OnRootRotationChanged(ChangeEvent <Vector3> evt)
 {
     //      this.MoveAction.Invoke(evt.newValue);
     evt.StopPropagation();
 }
コード例 #8
0
 private void OnRootPositionChanged(ChangeEvent <Vector3> evt)
 {
     this.MoveAction.Invoke(evt.newValue - evt.previousValue);
     evt.StopPropagation();
 }
コード例 #9
0
 private void OnFoldableChange(ChangeEvent <bool> evt)
 {
     InnerElement.style.display = evt.newValue ? DisplayStyle.Flex : DisplayStyle.None;
     evt.StopPropagation();
 }
コード例 #10
0
        void FoldoutNumberFieldOnValueChange(ChangeEvent <string> evt)
        {
            var target         = evt.target as TextField;
            var foldoutElement = target.GetFirstAncestorOfType <FoldoutNumberField>();

            if (!string.IsNullOrEmpty(evt.newValue))
            {
                if (foldoutElement.IsValidInput(evt.newValue))
                {
                    foldoutElement.header.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName);
                    foldoutElement.headerInputField.value = foldoutElement.GetFormattedInputString();
                    for (int i = 0; i < foldoutElement.bindingPathArray.Length; i++)
                    {
                        var styleName = foldoutElement.bindingPathArray[i];

                        var styleProperty = GetStylePropertyByStyleName(styleName);

#if UNITY_2019_3_OR_NEWER
                        var field = FindStylePropertyInfo(styleName);

                        // We don't care which element we get the value for here as we're only interested
                        // in the type of Enum it might be (and for validation), but not it's actual value.
                        var val = field?.GetValue(foldoutElement.computedStyle, null);

                        if ((val != null && val is StyleLength) ||
                            BuilderConstants.SpecialSnowflakeLengthSytles.Contains(foldoutElement.bindingPathArray[i]))
                        {
                            var newValue = 0;
                            // TryParse to check if fieldValue is not a style string like "auto"
                            if (Int32.TryParse(foldoutElement.fieldValues[i], out newValue))
                            {
                                var isNewValue = styleProperty.values.Length == 0;

                                // If the current style property is saved as a float instead of a dimension,
                                // it means it's a user file where they left out the unit. We need to resave
                                // it here as a dimension to create final proper uss.
                                if (!isNewValue && styleProperty.values[0].valueType != StyleValueType.Dimension)
                                {
                                    styleProperty.values = new StyleValueHandle[0];
                                    isNewValue           = true;
                                }

                                var dimension = new Dimension();
                                dimension.unit  = Dimension.Unit.Pixel;
                                dimension.value = newValue;

                                if (isNewValue)
                                {
                                    styleSheet.AddValue(styleProperty, dimension);
                                }
                                else // TODO: Assume only one value.
                                {
                                    styleSheet.SetValue(styleProperty.values[0], dimension);
                                }
                            }
                        }
                        else
#endif
                        {
                            var newValue = 0;
                            // TryParse to check if fieldValue is not a style string like "auto"
                            if (Int32.TryParse(foldoutElement.fieldValues[i], out newValue))
                            {
                                var convertedFloat = (float)newValue;

                                if (styleProperty.values.Length == 0)
                                {
                                    styleSheet.AddValue(styleProperty, convertedFloat);
                                }
                                else // TODO: Assume only one value.
                                {
                                    styleSheet.SetValue(styleProperty.values[0], convertedFloat);
                                }
                            }
                        }

                        NotifyStyleChanges();
                    }

                    // Remove temporary min-size class on VisualElement.
                    currentVisualElement.RemoveMinSizeSpecialElement();

                    m_Inspector.StylingChanged(foldoutElement.bindingPathArray.ToList());
                }
                else
                {
                    foldoutElement.headerInputField.SetValueWithoutNotify(foldoutElement.lastValidInput);
                }
            }

            evt.StopPropagation();
        }