public void BindStyleField(BuilderStyleRow styleRow, FoldoutColorField foldoutElement) { var colorFields = foldoutElement.Query <ColorField>().ToList(); foreach (var field in colorFields) { field.SetProperty(BuilderConstants.FoldoutFieldPropertyName, foldoutElement); field.RegisterValueChangedCallback((evt) => { var row = field.GetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName) as BuilderStyleRow; if (row != null && !string.IsNullOrEmpty(row.bindingPath)) { foldoutElement.UpdateFromChildField(row.bindingPath, field.value); } foldoutElement.header.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); }); BuilderStyleRow.ReAssignTooltipToChild(field); } foldoutElement.header.SetProperty(BuilderConstants.FoldoutFieldPropertyName, foldoutElement); foldoutElement.headerInputField.RegisterValueChangedCallback(FoldoutColorFieldOnValueChange); foldoutElement.headerInputField.AddManipulator( new ContextualMenuManipulator((e) => { e.target = foldoutElement.header; BuildStyleFieldContextualMenu(e); })); foldoutElement.header.AddManipulator( new ContextualMenuManipulator(BuildStyleFieldContextualMenu)); }
void RefreshStyleFoldoutColorField(FoldoutColorField foldoutElement) { var isDirty = false; foreach (var path in foldoutElement.bindingPathArray) { var cSharpStyleName = ConvertUssStyleNameToCSharpStyleName(path); var styleProperty = GetStyleProperty(currentRule, cSharpStyleName); var field = FindStylePropertyInfo(path); if (field == null) { continue; } var val = field.GetValue(currentVisualElement.computedStyle, null); if (val is StyleColor) { var style = (StyleColor)val; var value = style.value; // We keep falling into the alpha==0 trap. This patches the issue a little. if (value.a < 0.1f) { value.a = 255.0f; } if (styleProperty != null) { isDirty = true; value = styleSheet.GetColor(styleProperty.values[0]); } foldoutElement.UpdateFromChildField(path, value); } } if (isDirty) { foldoutElement.header.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); } else { foldoutElement.header.RemoveFromClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); } }