public StyleField(VisualElement selectedElement, StyleFieldPropertyInfo propInfo) { AddToClassList("unity-style-field"); m_SelectedElement = selectedElement; m_PropertyInfo = propInfo.computedPropertyInfo; m_PropertyName = propInfo.name; m_SpecificityLabel = new Label(); m_SpecificityLabel.AddToClassList("unity-style-field__specifity-label"); RefreshPropertyValue(propInfo.value, propInfo.specificity); }
private void RefreshFields() { if (m_SelectedElement == null) { return; } m_CustomPropertyFieldsContainer.Clear(); var customProperties = m_SelectedElement.specifiedStyle.m_CustomProperties; if (customProperties != null && customProperties.Any()) { foreach (KeyValuePair <string, CustomPropertyHandle> customProperty in customProperties) { var styleName = customProperty.Key; foreach (StyleValueHandle handle in customProperty.Value.handles) { TextField textField = new TextField(styleName) { isReadOnly = true }; textField.AddToClassList("unity-style-field"); textField.value = customProperty.Value.data.ReadAsString(handle).ToLower(); m_CustomPropertyFieldsContainer.Add(textField); } } } foreach (PropertyInfo propertyInfo in m_Sort ? k_SortedFieldInfos : k_FieldInfos) { var styleName = GetUSSPropertyNameFromComputedStyleName(propertyInfo.Name); if (!string.IsNullOrEmpty(m_SearchFilter) && styleName.IndexOf(m_SearchFilter, StringComparison.InvariantCultureIgnoreCase) == -1) { continue; } object val = propertyInfo.GetValue(selectedElement.computedStyle, null); Type type = val.GetType(); int specificity = (int)type.GetProperty("specificity", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(val, null); StyleField sf = null; m_NameToFieldDictionary.TryGetValue(styleName, out sf); if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity) { if (sf != null) { sf.RefreshPropertyValue(val, specificity); } else { var sfPropInfo = new StyleFieldPropertyInfo() { name = styleName, value = val, specificity = specificity, computedPropertyInfo = propertyInfo }; sf = new StyleField(m_SelectedElement, sfPropInfo); m_FieldsContainer.Add(sf); m_NameToFieldDictionary[styleName] = sf; } } else if (sf != null) { // Style property is not applied anymore, remove the field m_NameToFieldDictionary.Remove(styleName); m_FieldsContainer.Remove(sf); } } }