void OnBackgroundImageScaleModeChange(ChangeEvent <string> evt)
        {
            var newValue  = BuilderNameUtilities.ConvertDashToHungarian(evt.newValue);
            var enumValue = (ScaleMode)Enum.Parse(typeof(ScaleMode), newValue);

            settings.CanvasBackgroundImageScaleMode = enumValue;
            PostSettingsChange();
            ApplyBackgroundOptions();
        }
        void OnFieldValueChange(ChangeEvent <string> e, string styleName)
        {
            var field = e.target as VisualElement;

            // HACK: For some reason, when using "Pick Element" feature of Debugger and
            // hovering over the button strips, we get bogus value change events with
            // empty strings.
            if (field is IToggleButtonStrip && string.IsNullOrEmpty(e.newValue))
            {
                return;
            }

            var styleProperty = GetStylePropertyByStyleName(styleName);
            var isNewValue    = styleProperty.values.Length == 0;

            if (field is IToggleButtonStrip)
            {
                var newValue        = e.newValue;
                var newEnumValueStr = BuilderNameUtilities.ConvertDashToHungarian(newValue);
                var enumType        = (field as IToggleButtonStrip).enumType;
                var newEnumValue    = Enum.Parse(enumType, newEnumValueStr) as Enum;

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

                // The state of Flex Direction can affect many other Flex-related fields.
                if (styleName == "flex-direction")
                {
                    updateFlexColumnGlobalState?.Invoke(newEnumValue);
                }
            }
            else
            {
                if (isNewValue)
                {
                    styleSheet.AddValue(styleProperty, e.newValue);
                }
                else // TODO: Assume only one value.
                {
                    styleSheet.SetValue(styleProperty.values[0], e.newValue);
                }
            }

            PostStyleFieldSteps(e.target as VisualElement, styleName, isNewValue);
        }
        void OnBackgroundImageScaleModeChange(ChangeEvent <string> evt)
        {
            var newValue  = BuilderNameUtilities.ConvertDashToHungarian(evt.newValue);
            var enumValue = (ScaleMode)Enum.Parse(typeof(ScaleMode), newValue);

            settings.CanvasBackgroundImageScaleMode = enumValue;
            PostSettingsChange();

            if (settings.CanvasBackgroundMode != BuilderCanvasBackgroundMode.Image)
            {
                return;
            }

            customBackgroundElement.style.unityBackgroundScaleMode = enumValue;
        }
        public void RefreshStyleField(string styleName, VisualElement fieldElement)
        {
            var field = FindStylePropertyInfo(styleName);

            if (field == null)
            {
                return;
            }

            var val             = field.GetValue(currentVisualElement.computedStyle, null);
            var valType         = val.GetType();
            var cSharpStyleName = ConvertUssStyleNameToCSharpStyleName(styleName);
            var styleProperty   = GetStyleProperty(currentRule, cSharpStyleName);

            if (val is StyleFloat && fieldElement is FloatField)
            {
                var style   = (StyleFloat)val;
                var uiField = fieldElement as FloatField;

                var value = style.value;
                if (styleProperty != null)
                {
                    value = styleSheet.GetFloat(styleProperty.values[0]);
                }

                uiField.SetValueWithoutNotify(value);
            }
            else if (val is StyleFloat && fieldElement is IntegerField)
            {
                var style   = (StyleFloat)val;
                var uiField = fieldElement as IntegerField;

                var value = (int)style.value;
                if (styleProperty != null)
                {
                    value = (int)styleSheet.GetFloat(styleProperty.values[0]);
                }

                uiField.SetValueWithoutNotify(value);
            }
            else if (val is StyleFloat && fieldElement is PercentSlider)
            {
                var style   = (StyleFloat)val;
                var uiField = fieldElement as PercentSlider;

                var value = style.value;
                if (styleProperty != null)
                {
                    value = styleSheet.GetFloat(styleProperty.values[0]);
                }

                uiField.SetValueWithoutNotify(value);
            }
            else if (val is StyleInt && fieldElement is IntegerField)
            {
                var style   = (StyleInt)val;
                var uiField = fieldElement as IntegerField;

                var value = style.value;
                if (styleProperty != null)
                {
                    value = styleSheet.GetInt(styleProperty.values[0]);
                }

                uiField.SetValueWithoutNotify(value);
            }
            else if (val is StyleLength && fieldElement is IntegerField)
            {
                var style   = (StyleLength)val;
                var uiField = fieldElement as IntegerField;

                var value = (int)style.value.value;
                if (styleProperty != null)
#if UNITY_2019_3_OR_NEWER
                { value = (int)styleSheet.GetDimension(styleProperty.values[0]).value; }
#else
                { value = styleSheet.GetInt(styleProperty.values[0]); }
#endif

                uiField.SetValueWithoutNotify(value);
            }
            else if (val is StyleColor && fieldElement is ColorField)
            {
                var style   = (StyleColor)val;
                var uiField = fieldElement as ColorField;

                var value = style.value;
                if (styleProperty != null)
                {
                    value = styleSheet.GetColor(styleProperty.values[0]);
                }

                // We keep falling into the alpha==0 trap. This patches the issue a little.
                if (value.a < 0.1f)
                {
                    value.a = 255.0f;
                }

                uiField.SetValueWithoutNotify(value);
            }
            else if (val is StyleFont && fieldElement is ObjectField)
            {
                var style   = (StyleFont)val;
                var uiField = fieldElement as ObjectField;

                var value = style.value;
                if (styleProperty != null)
                {
                    value = styleSheet.GetAsset(styleProperty.values[0]) as Font;
                }

                uiField.SetValueWithoutNotify(value);
            }
            else if (val is StyleBackground && fieldElement is ObjectField)
            {
                var style   = (StyleBackground)val;
                var uiField = fieldElement as ObjectField;

                var value = style.value;
                if (styleProperty != null)
                {
                    value.texture = styleSheet.GetAsset(styleProperty.values[0]) as Texture2D;
                }

                uiField.SetValueWithoutNotify(value.texture);
            }
            else if (val is StyleCursor && fieldElement is ObjectField)
            {
                var style   = (StyleCursor)val;
                var uiField = fieldElement as ObjectField;

                var value = style.value;
                if (styleProperty != null)
                {
                    value.texture = styleSheet.GetAsset(styleProperty.values[0]) as Texture2D;
                }

                uiField.SetValueWithoutNotify(value.texture);
            }
            else if (valType.IsGenericType && valType.GetGenericArguments()[0].IsEnum)
            {
                var propInfo  = valType.GetProperty("value");
                var enumValue = propInfo.GetValue(val, null) as Enum;

                if (styleProperty != null)
                {
                    var enumStr          = styleSheet.GetEnum(styleProperty.values[0]);
                    var enumStrHungarian = BuilderNameUtilities.ConvertDashToHungarian(enumStr);
                    var enumObj          = Enum.Parse(enumValue.GetType(), enumStrHungarian);
                    enumValue = enumObj as Enum;
                }

                // The state of Flex Direction can affect many other Flex-related fields.
                if (styleName == "flex-direction")
                {
                    updateFlexColumnGlobalState?.Invoke(enumValue);
                }

                if (fieldElement is EnumField)
                {
                    var uiField = fieldElement as EnumField;
                    uiField.SetValueWithoutNotify(enumValue);
                }
                else if (fieldElement is IToggleButtonStrip)
                {
                    var enumStr = BuilderNameUtilities.ConvertCamelToDash(enumValue.ToString());
                    var uiField = fieldElement as IToggleButtonStrip;
                    uiField.SetValueWithoutNotify(enumStr);
                }
                else
                {
                    // Unsupported style value type.
                    return;
                }
            }
            else
            {
                // Unsupported style value type.
                return;
            }

            // Add override style to field if it is overwritten.
            var styleRow = fieldElement.GetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName) as BuilderStyleRow;
            Assert.IsNotNull(styleRow);
            if (styleRow == null)
            {
                return;
            }
            var styleFields = styleRow.Query <BindableElement>().ToList();

            bool isRowOverride = false;
            foreach (var styleField in styleFields)
            {
                var cShartStyleName = ConvertUssStyleNameToCSharpStyleName(styleField.bindingPath);
                if (GetStyleProperty(currentRule, cShartStyleName) != null)
                {
                    isRowOverride = true;
                    styleField.RemoveFromClassList(BuilderConstants.InspectorLocalStyleResetClassName);
                    styleField.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName);
                }
                else if (!string.IsNullOrEmpty(styleField.bindingPath))
                {
                    styleField.AddToClassList(BuilderConstants.InspectorLocalStyleResetClassName);
                }
            }

            if (styleProperty != null || isRowOverride)
            {
                styleRow.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName);
            }
            else
            {
                styleRow.RemoveFromClassList(BuilderConstants.InspectorLocalStyleOverrideClassName);
                foreach (var styleField in styleFields)
                {
                    styleField.RemoveFromClassList(BuilderConstants.InspectorLocalStyleOverrideClassName);
                    styleField.RemoveFromClassList(BuilderConstants.InspectorLocalStyleResetClassName);
                }
            }
        }