public static object GetInlineStyleValue(IStyle style, StylePropertyId id) { switch (id) { case StylePropertyId.AlignContent: return(style.alignContent); case StylePropertyId.AlignItems: return(style.alignItems); case StylePropertyId.AlignSelf: return(style.alignSelf); case StylePropertyId.BackgroundColor: return(style.backgroundColor); case StylePropertyId.BackgroundImage: return(style.backgroundImage); case StylePropertyId.BorderBottomColor: return(style.borderBottomColor); case StylePropertyId.BorderBottomLeftRadius: return(style.borderBottomLeftRadius); case StylePropertyId.BorderBottomRightRadius: return(style.borderBottomRightRadius); case StylePropertyId.BorderBottomWidth: return(style.borderBottomWidth); case StylePropertyId.BorderLeftColor: return(style.borderLeftColor); case StylePropertyId.BorderLeftWidth: return(style.borderLeftWidth); case StylePropertyId.BorderRightColor: return(style.borderRightColor); case StylePropertyId.BorderRightWidth: return(style.borderRightWidth); case StylePropertyId.BorderTopColor: return(style.borderTopColor); case StylePropertyId.BorderTopLeftRadius: return(style.borderTopLeftRadius); case StylePropertyId.BorderTopRightRadius: return(style.borderTopRightRadius); case StylePropertyId.BorderTopWidth: return(style.borderTopWidth); case StylePropertyId.Bottom: return(style.bottom); case StylePropertyId.Color: return(style.color); case StylePropertyId.Cursor: return(style.cursor); case StylePropertyId.Display: return(style.display); case StylePropertyId.FlexBasis: return(style.flexBasis); case StylePropertyId.FlexDirection: return(style.flexDirection); case StylePropertyId.FlexGrow: return(style.flexGrow); case StylePropertyId.FlexShrink: return(style.flexShrink); case StylePropertyId.FlexWrap: return(style.flexWrap); case StylePropertyId.FontSize: return(style.fontSize); case StylePropertyId.Height: return(style.height); case StylePropertyId.JustifyContent: return(style.justifyContent); case StylePropertyId.Left: return(style.left); case StylePropertyId.MarginBottom: return(style.marginBottom); case StylePropertyId.MarginLeft: return(style.marginLeft); case StylePropertyId.MarginRight: return(style.marginRight); case StylePropertyId.MarginTop: return(style.marginTop); case StylePropertyId.MaxHeight: return(style.maxHeight); case StylePropertyId.MaxWidth: return(style.maxWidth); case StylePropertyId.MinHeight: return(style.minHeight); case StylePropertyId.MinWidth: return(style.minWidth); case StylePropertyId.Opacity: return(style.opacity); case StylePropertyId.Overflow: return(style.overflow); case StylePropertyId.PaddingBottom: return(style.paddingBottom); case StylePropertyId.PaddingLeft: return(style.paddingLeft); case StylePropertyId.PaddingRight: return(style.paddingRight); case StylePropertyId.PaddingTop: return(style.paddingTop); case StylePropertyId.Position: return(style.position); case StylePropertyId.Right: return(style.right); case StylePropertyId.TextOverflow: return(style.textOverflow); case StylePropertyId.Top: return(style.top); case StylePropertyId.UnityBackgroundImageTintColor: return(style.unityBackgroundImageTintColor); case StylePropertyId.UnityBackgroundScaleMode: return(style.unityBackgroundScaleMode); case StylePropertyId.UnityFont: return(style.unityFont); case StylePropertyId.UnityFontStyleAndWeight: return(style.unityFontStyleAndWeight); case StylePropertyId.UnityOverflowClipBox: return(style.unityOverflowClipBox); case StylePropertyId.UnitySliceBottom: return(style.unitySliceBottom); case StylePropertyId.UnitySliceLeft: return(style.unitySliceLeft); case StylePropertyId.UnitySliceRight: return(style.unitySliceRight); case StylePropertyId.UnitySliceTop: return(style.unitySliceTop); case StylePropertyId.UnityTextAlign: return(style.unityTextAlign); case StylePropertyId.UnityTextOverflowPosition: return(style.unityTextOverflowPosition); case StylePropertyId.Visibility: return(style.visibility); case StylePropertyId.WhiteSpace: return(style.whiteSpace); case StylePropertyId.Width: return(style.width); default: { Debug.LogAssertion($"Cannot get inline style value for property id {id}"); return(null); } } }
public static void SetInlineStyleValue(IStyle style, StylePropertyId id, object value) { switch (id) { case StylePropertyId.AlignContent: style.alignContent = (StyleEnum <Align>)value; break; case StylePropertyId.AlignItems: style.alignItems = (StyleEnum <Align>)value; break; case StylePropertyId.AlignSelf: style.alignSelf = (StyleEnum <Align>)value; break; case StylePropertyId.BackgroundColor: style.backgroundColor = (StyleColor)value; break; case StylePropertyId.BackgroundImage: style.backgroundImage = (StyleBackground)value; break; case StylePropertyId.BorderBottomColor: style.borderBottomColor = (StyleColor)value; break; case StylePropertyId.BorderBottomLeftRadius: style.borderBottomLeftRadius = (StyleLength)value; break; case StylePropertyId.BorderBottomRightRadius: style.borderBottomRightRadius = (StyleLength)value; break; case StylePropertyId.BorderBottomWidth: style.borderBottomWidth = (StyleFloat)value; break; case StylePropertyId.BorderLeftColor: style.borderLeftColor = (StyleColor)value; break; case StylePropertyId.BorderLeftWidth: style.borderLeftWidth = (StyleFloat)value; break; case StylePropertyId.BorderRightColor: style.borderRightColor = (StyleColor)value; break; case StylePropertyId.BorderRightWidth: style.borderRightWidth = (StyleFloat)value; break; case StylePropertyId.BorderTopColor: style.borderTopColor = (StyleColor)value; break; case StylePropertyId.BorderTopLeftRadius: style.borderTopLeftRadius = (StyleLength)value; break; case StylePropertyId.BorderTopRightRadius: style.borderTopRightRadius = (StyleLength)value; break; case StylePropertyId.BorderTopWidth: style.borderTopWidth = (StyleFloat)value; break; case StylePropertyId.Bottom: style.bottom = (StyleLength)value; break; case StylePropertyId.Color: style.color = (StyleColor)value; break; case StylePropertyId.Cursor: style.cursor = (StyleCursor)value; break; case StylePropertyId.Display: style.display = (StyleEnum <DisplayStyle>)value; break; case StylePropertyId.FlexBasis: style.flexBasis = (StyleLength)value; break; case StylePropertyId.FlexDirection: style.flexDirection = (StyleEnum <FlexDirection>)value; break; case StylePropertyId.FlexGrow: style.flexGrow = (StyleFloat)value; break; case StylePropertyId.FlexShrink: style.flexShrink = (StyleFloat)value; break; case StylePropertyId.FlexWrap: style.flexWrap = (StyleEnum <Wrap>)value; break; case StylePropertyId.FontSize: style.fontSize = (StyleLength)value; break; case StylePropertyId.Height: style.height = (StyleLength)value; break; case StylePropertyId.JustifyContent: style.justifyContent = (StyleEnum <Justify>)value; break; case StylePropertyId.Left: style.left = (StyleLength)value; break; case StylePropertyId.MarginBottom: style.marginBottom = (StyleLength)value; break; case StylePropertyId.MarginLeft: style.marginLeft = (StyleLength)value; break; case StylePropertyId.MarginRight: style.marginRight = (StyleLength)value; break; case StylePropertyId.MarginTop: style.marginTop = (StyleLength)value; break; case StylePropertyId.MaxHeight: style.maxHeight = (StyleLength)value; break; case StylePropertyId.MaxWidth: style.maxWidth = (StyleLength)value; break; case StylePropertyId.MinHeight: style.minHeight = (StyleLength)value; break; case StylePropertyId.MinWidth: style.minWidth = (StyleLength)value; break; case StylePropertyId.Opacity: style.opacity = (StyleFloat)value; break; case StylePropertyId.Overflow: style.overflow = (StyleEnum <Overflow>)value; break; case StylePropertyId.PaddingBottom: style.paddingBottom = (StyleLength)value; break; case StylePropertyId.PaddingLeft: style.paddingLeft = (StyleLength)value; break; case StylePropertyId.PaddingRight: style.paddingRight = (StyleLength)value; break; case StylePropertyId.PaddingTop: style.paddingTop = (StyleLength)value; break; case StylePropertyId.Position: style.position = (StyleEnum <Position>)value; break; case StylePropertyId.Right: style.right = (StyleLength)value; break; case StylePropertyId.TextOverflow: style.textOverflow = (StyleEnum <TextOverflow>)value; break; case StylePropertyId.Top: style.top = (StyleLength)value; break; case StylePropertyId.UnityBackgroundImageTintColor: style.unityBackgroundImageTintColor = (StyleColor)value; break; case StylePropertyId.UnityBackgroundScaleMode: style.unityBackgroundScaleMode = (StyleEnum <ScaleMode>)value; break; case StylePropertyId.UnityFont: style.unityFont = (StyleFont)value; break; case StylePropertyId.UnityFontStyleAndWeight: style.unityFontStyleAndWeight = (StyleEnum <FontStyle>)value; break; case StylePropertyId.UnityOverflowClipBox: style.unityOverflowClipBox = (StyleEnum <OverflowClipBox>)value; break; case StylePropertyId.UnitySliceBottom: style.unitySliceBottom = (StyleInt)value; break; case StylePropertyId.UnitySliceLeft: style.unitySliceLeft = (StyleInt)value; break; case StylePropertyId.UnitySliceRight: style.unitySliceRight = (StyleInt)value; break; case StylePropertyId.UnitySliceTop: style.unitySliceTop = (StyleInt)value; break; case StylePropertyId.UnityTextAlign: style.unityTextAlign = (StyleEnum <TextAnchor>)value; break; case StylePropertyId.UnityTextOverflowPosition: style.unityTextOverflowPosition = (StyleEnum <TextOverflowPosition>)value; break; case StylePropertyId.Visibility: style.visibility = (StyleEnum <Visibility>)value; break; case StylePropertyId.WhiteSpace: style.whiteSpace = (StyleEnum <WhiteSpace>)value; break; case StylePropertyId.Width: style.width = (StyleLength)value; break; default: Debug.LogAssertion($"Cannot set inline style value for property id {id}"); break; } }
private void DrawComputedStyle() { // style name, style value, source UIStyleSet style = selectedElement.style; bool isSet = (selectedElement.flags & UIElementFlags.DebugLayout) != 0; if (EditorGUILayout.ToggleLeft("Debug Layout", isSet)) { selectedElement.flags |= UIElementFlags.DebugLayout; } else { selectedElement.flags &= ~UIElementFlags.DebugLayout; } GUILayout.BeginHorizontal(); DrawStyleStateButton("Hover", StyleState.Hover); DrawStyleStateButton("Focus", StyleState.Focused); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); DrawStyleStateButton("Active", StyleState.Active); GUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); showAllComputedStyles = EditorGUILayout.ToggleLeft("Show All", showAllComputedStyles); showComputedSources = EditorGUILayout.ToggleLeft("Show Sources", showComputedSources); EditorGUILayout.EndHorizontal(); GUILayout.Space(4); searchString = searchField.OnGUI(searchString); GUILayout.Space(4); List <ValueTuple <string, StyleProperty> > properties = ListPool <ValueTuple <string, StyleProperty> > .Get(); string lowerSearch = searchString.ToLower(); for (int i = 0; i < StyleUtil.StylePropertyIdList.Length; i++) { StylePropertyId propertyId = StyleUtil.StylePropertyIdList[i]; if (showAllComputedStyles || style.IsDefined(propertyId)) { if (!string.IsNullOrEmpty(searchString)) { string propertyName = StyleUtil.GetPropertyName(propertyId).ToLower(); if (!propertyName.Contains(lowerSearch)) { continue; } } string source = selectedElement.style.GetPropertySource(propertyId); StyleProperty property = selectedElement.style.GetComputedStyleProperty(propertyId); if (!property.hasValue) { property = DefaultStyleValues_Generated.GetPropertyValue(propertyId); } properties.Add(ValueTuple.Create(source, property)); } } if (properties.Count == 0) { return; } if (showComputedSources) { properties.Sort( (a, b) => { if (a.Item1 == b.Item1) { return(0); } bool aInstance = a.Item1.Contains("Instance"); bool bInstance = b.Item1.Contains("Instance"); if (aInstance && bInstance) { return(string.Compare(a.Item1, b.Item1, StringComparison.Ordinal)); } if (aInstance) { return(-1); } if (bInstance) { return(1); } bool aDefault = a.Item1.Contains("Default"); bool bDefault = b.Item1.Contains("Default"); if (aDefault && bDefault) { return(string.Compare(a.Item1, b.Item1, StringComparison.Ordinal)); } if (aDefault) { return(1); } if (bDefault) { return(-1); } return(string.Compare(a.Item1, b.Item1, StringComparison.Ordinal)); }); GUILayout.Space(10); string currentSource = properties[0].Item1; EditorGUILayout.LabelField(currentSource); int start = 0; for (int i = 0; i < properties.Count; i++) { if (currentSource != properties[i].Item1) { properties.Sort(start, i - start, s_StyleCompare); for (int j = start; j < i; j++) { DrawStyleProperty(properties[j].Item2, false); } start = i; currentSource = properties[i].Item1; GUILayout.Space(10); EditorGUILayout.LabelField(currentSource); } } properties.Sort(start, properties.Count - start, s_StyleCompare); for (int j = start; j < properties.Count; j++) { DrawStyleProperty(properties[j].Item2, false); } } else { properties.Sort(0, properties.Count - 1, s_StyleCompare); for (int i = 0; i < properties.Count; i++) { DrawStyleProperty(properties[i].Item2, false); } } }