void RefreshAttributeField(BindableElement fieldElement) { var styleRow = fieldElement.GetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName) as VisualElement; var attribute = fieldElement.GetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName) as UxmlAttributeDescription; var veType = currentVisualElement.GetType(); var csPropertyName = GetRemapAttributeNameToCSProperty(attribute.name); var fieldInfo = veType.GetProperty(csPropertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase); object veValueAbstract = null; if (fieldInfo == null) { veValueAbstract = GetCustomValueAbstract(attribute.name); } else { veValueAbstract = fieldInfo.GetValue(currentVisualElement, null); } if (veValueAbstract == null) { if (currentVisualElement is EnumField defaultEnumField && attribute.name == "value") { if (defaultEnumField.type == null) { fieldElement.SetEnabled(false); } else { ((EnumField)fieldElement).PopulateDataFromType(defaultEnumField.type); fieldElement.SetEnabled(true); } } return; } var attributeType = attribute.GetType(); var vea = currentVisualElement.GetVisualElementAsset(); if (attribute is UxmlStringAttributeDescription && attribute.name == "value" && currentVisualElement is EnumField enumField && fieldElement is EnumField inputEnumField) { var hasValue = enumField.value != null; if (hasValue) { inputEnumField.Init(enumField.value, enumField.includeObsoleteValues); } else { inputEnumField.SetValueWithoutNotify(null); } inputEnumField.SetEnabled(hasValue); }
static public VariableEditingHandler GetVarHandler(BindableElement field) { if (field == null) { return(null); } return(field?.GetProperty(BuilderConstants.ElementLinkedVariableHandlerVEPropertyName) as VariableEditingHandler); }
void PostAttributeValueChange(BindableElement field, string value) { // Undo/Redo Undo.RegisterCompleteObjectUndo(m_Inspector.visualTreeAsset, BuilderConstants.ChangeAttributeValueUndoMessage); // Set value in asset. var vea = currentVisualElement.GetVisualElementAsset(); vea.SetAttributeValue(field.bindingPath, value); // Mark field as overridden. var styleRow = field.GetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName) as BuilderStyleRow; styleRow.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); var styleFields = styleRow.Query <BindableElement>().ToList(); foreach (var styleField in styleFields) { styleField.RemoveFromClassList(BuilderConstants.InspectorLocalStyleResetClassName); if (field.bindingPath == styleField.bindingPath) { styleField.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); } else if (!string.IsNullOrEmpty(styleField.bindingPath) && field.bindingPath != styleField.bindingPath && !styleField.ClassListContains(BuilderConstants.InspectorLocalStyleOverrideClassName)) { styleField.AddToClassList(BuilderConstants.InspectorLocalStyleResetClassName); } } // Call Init(); CallInitOnElement(); // Notify of changes. m_Selection.NotifyOfHierarchyChange(m_Inspector); }
void RefreshAttributeField(BindableElement fieldElement) { var styleRow = fieldElement.GetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName) as VisualElement; var attribute = fieldElement.GetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName) as UxmlAttributeDescription; var veType = currentVisualElement.GetType(); var csPropertyName = GetRemapAttributeNameToCSProperty(attribute.name); var fieldInfo = veType.GetProperty(csPropertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase); object veValueAbstract = null; if (fieldInfo == null) { veValueAbstract = GetCustomValueAbstract(attribute.name); } else { veValueAbstract = fieldInfo.GetValue(currentVisualElement); } if (veValueAbstract == null) { return; } var attributeType = attribute.GetType(); var vea = currentVisualElement.GetVisualElementAsset(); if (attribute is UxmlStringAttributeDescription && fieldElement is TextField) { (fieldElement as TextField).SetValueWithoutNotify(GetAttributeStringValue(veValueAbstract)); } else if (attribute is UxmlFloatAttributeDescription && fieldElement is FloatField) { (fieldElement as FloatField).SetValueWithoutNotify((float)veValueAbstract); } else if (attribute is UxmlDoubleAttributeDescription && fieldElement is DoubleField) { (fieldElement as DoubleField).SetValueWithoutNotify((double)veValueAbstract); } else if (attribute is UxmlIntAttributeDescription && fieldElement is IntegerField) { if (veValueAbstract is int) { (fieldElement as IntegerField).SetValueWithoutNotify((int)veValueAbstract); } else if (veValueAbstract is float) { (fieldElement as IntegerField).SetValueWithoutNotify(Convert.ToInt32(veValueAbstract)); } } else if (attribute is UxmlLongAttributeDescription && fieldElement is LongField) { (fieldElement as LongField).SetValueWithoutNotify((long)veValueAbstract); } else if (attribute is UxmlBoolAttributeDescription && fieldElement is Toggle) { (fieldElement as Toggle).SetValueWithoutNotify((bool)veValueAbstract); } else if (attribute is UxmlColorAttributeDescription && fieldElement is ColorField) { (fieldElement as ColorField).SetValueWithoutNotify((Color)veValueAbstract); } else if (attributeType.IsGenericType && !attributeType.GetGenericArguments()[0].IsEnum && attributeType.GetGenericArguments()[0] is Type && fieldElement is TextField textField && veValueAbstract is Type veTypeValue) { var fullTypeName = veTypeValue.AssemblyQualifiedName; var fullTypeNameSplit = fullTypeName.Split(','); textField.SetValueWithoutNotify($"{fullTypeNameSplit[0]},{fullTypeNameSplit[1]}"); }
void ResetAttributeFieldToDefault(BindableElement fieldElement) { var styleRow = fieldElement.GetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName) as VisualElement; var attribute = fieldElement.GetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName) as UxmlAttributeDescription; var attributeType = attribute.GetType(); var vea = currentVisualElement.GetVisualElementAsset(); if (attribute is UxmlStringAttributeDescription && fieldElement is TextField) { var a = attribute as UxmlStringAttributeDescription; var f = fieldElement as TextField; f.SetValueWithoutNotify(a.defaultValue); } else if (attribute is UxmlFloatAttributeDescription && fieldElement is FloatField) { var a = attribute as UxmlFloatAttributeDescription; var f = fieldElement as FloatField; f.SetValueWithoutNotify(a.defaultValue); } else if (attribute is UxmlDoubleAttributeDescription && fieldElement is DoubleField) { var a = attribute as UxmlDoubleAttributeDescription; var f = fieldElement as DoubleField; f.SetValueWithoutNotify(a.defaultValue); } else if (attribute is UxmlIntAttributeDescription && fieldElement is IntegerField) { var a = attribute as UxmlIntAttributeDescription; var f = fieldElement as IntegerField; f.SetValueWithoutNotify(a.defaultValue); } else if (attribute is UxmlLongAttributeDescription && fieldElement is LongField) { var a = attribute as UxmlLongAttributeDescription; var f = fieldElement as LongField; f.SetValueWithoutNotify(a.defaultValue); } else if (attribute is UxmlBoolAttributeDescription && fieldElement is Toggle) { var a = attribute as UxmlBoolAttributeDescription; var f = fieldElement as Toggle; f.SetValueWithoutNotify(a.defaultValue); } else if (attribute is UxmlColorAttributeDescription && fieldElement is ColorField) { var a = attribute as UxmlColorAttributeDescription; var f = fieldElement as ColorField; f.SetValueWithoutNotify(a.defaultValue); } else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum && fieldElement is EnumField) { var propInfo = attributeType.GetProperty("defaultValue"); var enumValue = propInfo.GetValue(attribute, null) as Enum; var uiField = fieldElement as EnumField; uiField.SetValueWithoutNotify(enumValue); } else if (fieldElement is TextField) { (fieldElement as TextField).SetValueWithoutNotify(string.Empty); } // Clear override. styleRow.RemoveFromClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); var styleFields = styleRow.Query <BindableElement>().ToList(); foreach (var styleField in styleFields) { styleField.RemoveFromClassList(BuilderConstants.InspectorLocalStyleResetClassName); styleField.RemoveFromClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); } }
void RefreshAttributeField(BindableElement fieldElement) { var styleRow = fieldElement.GetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName) as VisualElement; var attribute = fieldElement.GetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName) as UxmlAttributeDescription; var veType = currentVisualElement.GetType(); var camel = BuilderNameUtilities.ConvertDashToCamel(attribute.name); var fieldInfo = veType.GetProperty(camel, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase); object veValueAbstract = null; if (fieldInfo == null) { veValueAbstract = GetCustomValueAbstract(attribute.name); } else { veValueAbstract = fieldInfo.GetValue(currentVisualElement); } if (veValueAbstract == null) { return; } var attributeType = attribute.GetType(); var vea = currentVisualElement.GetVisualElementAsset(); if (attribute is UxmlStringAttributeDescription && fieldElement is TextField) { string value; if (veValueAbstract is Enum) { value = (veValueAbstract as Enum).ToString(); } else { value = (string)veValueAbstract; } (fieldElement as TextField).SetValueWithoutNotify(value); } else if (attribute is UxmlFloatAttributeDescription && fieldElement is FloatField) { (fieldElement as FloatField).SetValueWithoutNotify((float)veValueAbstract); } else if (attribute is UxmlDoubleAttributeDescription && fieldElement is DoubleField) { (fieldElement as DoubleField).SetValueWithoutNotify((double)veValueAbstract); } else if (attribute is UxmlIntAttributeDescription && fieldElement is IntegerField) { (fieldElement as IntegerField).SetValueWithoutNotify((int)veValueAbstract); } else if (attribute is UxmlLongAttributeDescription && fieldElement is LongField) { (fieldElement as LongField).SetValueWithoutNotify((long)veValueAbstract); } else if (attribute is UxmlBoolAttributeDescription && fieldElement is Toggle) { (fieldElement as Toggle).SetValueWithoutNotify((bool)veValueAbstract); } else if (attribute is UxmlColorAttributeDescription && fieldElement is ColorField) { (fieldElement as ColorField).SetValueWithoutNotify((Color)veValueAbstract); } else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum && fieldElement is EnumField) { var propInfo = attributeType.GetProperty("defaultValue"); var enumValue = propInfo.GetValue(attribute, null) as Enum; // Create and initialize the EnumField. var uiField = fieldElement as EnumField; // Set the value from the UXML attribute. var enumAttributeValueStr = vea?.GetAttributeValue(attribute.name); if (!string.IsNullOrEmpty(enumAttributeValueStr)) { var parsedValue = Enum.Parse(enumValue.GetType(), enumAttributeValueStr, true) as Enum; uiField.SetValueWithoutNotify(parsedValue); } } else if (fieldElement is TextField) { (fieldElement as TextField).SetValueWithoutNotify(veValueAbstract.ToString()); } // Determine if overridden. styleRow.RemoveFromClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); if (vea != null && attribute.name == "picking-mode") { var veaAttributeValue = vea.GetAttributeValue(attribute.name); if (veaAttributeValue != null && veaAttributeValue.ToLower() != attribute.defaultValueAsString.ToLower()) { styleRow.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); } } else if (attribute.name == "name") { if (!string.IsNullOrEmpty(currentVisualElement.name)) { styleRow.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); } } else if (vea != null && vea.HasAttribute(attribute.name)) { styleRow.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); } }