public VisualElementStylesData(bool isShared) { this.isShared = isShared; // Initialize non trivial properties left = StyleSheetCache.GetInitialValue(StylePropertyID.PositionLeft).ToStyleLength(); top = StyleSheetCache.GetInitialValue(StylePropertyID.PositionTop).ToStyleLength(); right = StyleSheetCache.GetInitialValue(StylePropertyID.PositionRight).ToStyleLength(); bottom = StyleSheetCache.GetInitialValue(StylePropertyID.PositionBottom).ToStyleLength(); width = StyleSheetCache.GetInitialValue(StylePropertyID.Width).ToStyleLength(); height = StyleSheetCache.GetInitialValue(StylePropertyID.Height).ToStyleLength(); minWidth = StyleSheetCache.GetInitialValue(StylePropertyID.MinWidth).ToStyleLength(); minHeight = StyleSheetCache.GetInitialValue(StylePropertyID.MinHeight).ToStyleLength(); maxWidth = StyleSheetCache.GetInitialValue(StylePropertyID.MaxWidth).ToStyleLength(); maxHeight = StyleSheetCache.GetInitialValue(StylePropertyID.MaxHeight).ToStyleLength(); alignSelf = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignSelf).number; alignItems = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignItems).number; alignContent = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignContent).number; flexGrow = StyleSheetCache.GetInitialValue(StylePropertyID.FlexGrow).ToStyleFloat(); flexShrink = StyleSheetCache.GetInitialValue(StylePropertyID.FlexShrink).ToStyleFloat(); flexBasis = StyleSheetCache.GetInitialValue(StylePropertyID.FlexBasis).ToStyleLength(); color = StyleSheetCache.GetInitialValue(StylePropertyID.Color).color; borderLeftColor = StyleSheetCache.GetInitialValue(StylePropertyID.BorderLeftColor).color; borderTopColor = StyleSheetCache.GetInitialValue(StylePropertyID.BorderTopColor).color; borderRightColor = StyleSheetCache.GetInitialValue(StylePropertyID.BorderRightColor).color; borderBottomColor = StyleSheetCache.GetInitialValue(StylePropertyID.BorderBottomColor).color; opacity = StyleSheetCache.GetInitialValue(StylePropertyID.Opacity).number; unityBackgroundImageTintColor = StyleSheetCache.GetInitialValue(StylePropertyID.BackgroundImageTintColor).color; }
private void ApplyUnsetStyleValue(StylePropertyReader reader, InheritedStylesData inheritedStylesData) { if (inheritedStylesData == null) { ApplyInitialStyleValue(reader); } var specificity = reader.specificity; switch (reader.propertyID) { case StylePropertyID.Color: color = inheritedStylesData.color; color.specificity = specificity; break; case StylePropertyID.Font: unityFont = inheritedStylesData.font; unityFont.specificity = specificity; break; case StylePropertyID.FontSize: fontSize = inheritedStylesData.fontSize; fontSize.specificity = specificity; break; case StylePropertyID.FontStyleAndWeight: unityFontStyleAndWeight = inheritedStylesData.unityFontStyle; unityFontStyleAndWeight.specificity = specificity; break; case StylePropertyID.UnityTextAlign: unityTextAlign = inheritedStylesData.unityTextAlign; unityTextAlign.specificity = specificity; break; case StylePropertyID.Visibility: visibility = inheritedStylesData.visibility; visibility.specificity = specificity; break; case StylePropertyID.WhiteSpace: whiteSpace = inheritedStylesData.whiteSpace; whiteSpace.specificity = specificity; break; case StylePropertyID.Custom: RemoveCustomStyleProperty(reader.property.name); break; default: ApplyInitialStyleValue(reader.propertyID, specificity); break; } }
public void CopyFrom(InheritedStylesData other) { if (other != null) { color = other.color; font = other.font; fontSize = other.fontSize; visibility = other.visibility; whiteSpace = other.whiteSpace; unityFontStyle = other.unityFontStyle; unityTextAlign = other.unityTextAlign; } }
public bool TryGetValue(CustomStyleProperty <int> property, out int value) { CustomPropertyHandle propertyHandle; var tmp = new StyleInt(); if (TryGetValue(property.name, StyleValueType.Float, out propertyHandle)) { s_StyleSheetApplicator.ApplyInt(propertyHandle.data, propertyHandle.handles, propertyHandle.specificity, ref tmp); value = tmp.value; return(true); } value = 0; return(false); }
public static void ApplyDisplay(IStylePropertyReader reader, ref StyleInt property) { if (reader.IsKeyword(0, StyleValueKeyword.None)) { StyleInt none = new StyleInt((int)DisplayStyle.None) { specificity = reader.specificity }; property = none; return; } if (!reader.IsValueType(0, StyleValueType.Enum)) { Debug.LogError("Invalid value for display property " + reader.ReadAsString(0)); return; } property = reader.ReadStyleEnum <DisplayStyle>(0); }
public static void ApplyAlign(IStylePropertyReader reader, ref StyleInt property) { if (reader.IsKeyword(0, StyleValueKeyword.Auto)) { StyleInt auto = new StyleInt((int)Align.Auto) { specificity = reader.specificity }; property = auto; return; } if (!reader.IsValueType(0, StyleValueType.Enum)) { Debug.LogError("Invalid value for align property " + reader.ReadAsString(0)); return; } property = reader.ReadStyleEnum <Align>(0); }
public void ApplyDisplay(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleInt property) { if (handles[0].valueType == StyleValueType.Keyword && handles[0].valueIndex == (int)StyleValueKeyword.None) { StyleInt none = new StyleInt((int)DisplayStyle.None) { specificity = specificity }; property.Apply(none, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity); return; } if (handles[0].valueType != StyleValueType.Enum) { Debug.LogError("Invalid value for display property " + sheet.ReadAsString(handles[0])); return; } var value = sheet.ReadStyleEnum <DisplayStyle>(handles[0], specificity); property.Apply(value, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity); }
public void ApplyAlign(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleInt property) { if (handles[0].valueType == StyleValueType.Keyword && handles[0].valueIndex == (int)StyleValueKeyword.Auto) { StyleInt auto = new StyleInt((int)Align.Auto) { specificity = specificity }; property.Apply(auto, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity); return; } if (handles[0].valueType != StyleValueType.Enum) { Debug.LogError("Invalid value for align property " + sheet.ReadAsString(handles[0])); return; } var value = sheet.ReadStyleEnum <Align>(handles[0], specificity); property.Apply(value, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity); }
internal void ApplyStyleProperty(IStylePropertyReader reader) { switch (reader.propertyID) { case StylePropertyID.AlignContent: StyleSheetApplicator.ApplyAlign(reader, ref alignContent); break; case StylePropertyID.AlignItems: StyleSheetApplicator.ApplyAlign(reader, ref alignItems); break; case StylePropertyID.AlignSelf: StyleSheetApplicator.ApplyAlign(reader, ref alignSelf); break; case StylePropertyID.BackgroundImage: backgroundImage = reader.ReadStyleBackground(0); break; case StylePropertyID.FlexBasis: flexBasis = reader.ReadStyleLength(0); break; case StylePropertyID.FlexGrow: flexGrow = reader.ReadStyleFloat(0); break; case StylePropertyID.FlexShrink: flexShrink = reader.ReadStyleFloat(0); break; case StylePropertyID.Font: unityFont = reader.ReadStyleFont(0); break; case StylePropertyID.FontSize: fontSize = reader.ReadStyleLength(0); break; case StylePropertyID.FontStyleAndWeight: unityFontStyleAndWeight = reader.ReadStyleEnum <FontStyle>(0); break; case StylePropertyID.FlexDirection: flexDirection = reader.ReadStyleEnum <FlexDirection>(0); break; case StylePropertyID.FlexWrap: flexWrap = reader.ReadStyleEnum <Wrap>(0); break; case StylePropertyID.Height: height = reader.ReadStyleLength(0); break; case StylePropertyID.JustifyContent: justifyContent = reader.ReadStyleEnum <Justify>(0); break; case StylePropertyID.MarginLeft: marginLeft = reader.ReadStyleLength(0); break; case StylePropertyID.MarginTop: marginTop = reader.ReadStyleLength(0); break; case StylePropertyID.MarginRight: marginRight = reader.ReadStyleLength(0); break; case StylePropertyID.MarginBottom: marginBottom = reader.ReadStyleLength(0); break; case StylePropertyID.MaxHeight: maxHeight = reader.ReadStyleLength(0); break; case StylePropertyID.MaxWidth: maxWidth = reader.ReadStyleLength(0); break; case StylePropertyID.MinHeight: minHeight = reader.ReadStyleLength(0); break; case StylePropertyID.MinWidth: minWidth = reader.ReadStyleLength(0); break; case StylePropertyID.Overflow: overflow = reader.ReadStyleEnum <OverflowInternal>(0); break; case StylePropertyID.OverflowClipBox: unityOverflowClipBox = reader.ReadStyleEnum <OverflowClipBox>(0); break; case StylePropertyID.PaddingLeft: paddingLeft = reader.ReadStyleLength(0); break; case StylePropertyID.PaddingTop: paddingTop = reader.ReadStyleLength(0); break; case StylePropertyID.PaddingRight: paddingRight = reader.ReadStyleLength(0); break; case StylePropertyID.PaddingBottom: paddingBottom = reader.ReadStyleLength(0); break; case StylePropertyID.Position: position = reader.ReadStyleEnum <Position>(0); break; case StylePropertyID.PositionTop: top = reader.ReadStyleLength(0); break; case StylePropertyID.PositionBottom: bottom = reader.ReadStyleLength(0); break; case StylePropertyID.PositionLeft: left = reader.ReadStyleLength(0); break; case StylePropertyID.PositionRight: right = reader.ReadStyleLength(0); break; case StylePropertyID.UnityTextAlign: unityTextAlign = reader.ReadStyleEnum <TextAnchor>(0); break; case StylePropertyID.Color: color = reader.ReadStyleColor(0); break; case StylePropertyID.Width: width = reader.ReadStyleLength(0); break; case StylePropertyID.WhiteSpace: whiteSpace = reader.ReadStyleEnum <WhiteSpace>(0); break; case StylePropertyID.BackgroundColor: backgroundColor = reader.ReadStyleColor(0); break; case StylePropertyID.BackgroundScaleMode: unityBackgroundScaleMode = reader.ReadStyleEnum <ScaleMode>(0); break; case StylePropertyID.BackgroundImageTintColor: unityBackgroundImageTintColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderLeftColor: borderLeftColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderTopColor: borderTopColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderRightColor: borderRightColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderBottomColor: borderBottomColor = reader.ReadStyleColor(0); break; case StylePropertyID.BorderLeftWidth: borderLeftWidth = reader.ReadStyleFloat(0); break; case StylePropertyID.BorderTopWidth: borderTopWidth = reader.ReadStyleFloat(0); break; case StylePropertyID.BorderRightWidth: borderRightWidth = reader.ReadStyleFloat(0); break; case StylePropertyID.BorderBottomWidth: borderBottomWidth = reader.ReadStyleFloat(0); break; case StylePropertyID.BorderTopLeftRadius: borderTopLeftRadius = reader.ReadStyleLength(0); break; case StylePropertyID.BorderTopRightRadius: borderTopRightRadius = reader.ReadStyleLength(0); break; case StylePropertyID.BorderBottomRightRadius: borderBottomRightRadius = reader.ReadStyleLength(0); break; case StylePropertyID.BorderBottomLeftRadius: borderBottomLeftRadius = reader.ReadStyleLength(0); break; case StylePropertyID.Cursor: cursor = reader.ReadStyleCursor(0); break; case StylePropertyID.SliceLeft: unitySliceLeft = reader.ReadStyleInt(0); break; case StylePropertyID.SliceTop: unitySliceTop = reader.ReadStyleInt(0); break; case StylePropertyID.SliceRight: unitySliceRight = reader.ReadStyleInt(0); break; case StylePropertyID.SliceBottom: unitySliceBottom = reader.ReadStyleInt(0); break; case StylePropertyID.Opacity: opacity = reader.ReadStyleFloat(0); break; case StylePropertyID.Visibility: visibility = reader.ReadStyleEnum <Visibility>(0); break; case StylePropertyID.Display: StyleSheetApplicator.ApplyDisplay(reader, ref display); break; default: throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", reader.propertyID)); } }
public void ApplyEnum <T>(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleInt property) { var value = sheet.ReadStyleEnum <T>(handles[0], specificity); property.Apply(value, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity); }
public void ApplyDisplay(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleInt property) { if (currentStyleValue.keyword == StyleKeyword.None) { property.Apply(new StyleInt((int)DisplayStyle.None) { specificity = specificity }, StylePropertyApplyMode.Copy); } else { ApplyInt(sheet, handles, specificity, ref property); } }
public void ApplyInt(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleInt property) { property.Apply(new StyleInt((int)currentStyleValue.number, currentStyleValue.keyword) { specificity = specificity }, StylePropertyApplyMode.Copy); }
private void DrawProperties() { EditorGUILayout.LabelField(Styles.elementStylesContent, Styles.KInspectorTitle); m_SelectedElement.name = EditorGUILayout.TextField("Name", m_SelectedElement.name); EditorGUILayout.LabelField("Debug Id", m_SelectedElement.controlid.ToString()); var textElement = m_SelectedElement as ITextElement; if (textElement != null) { textElement.text = EditorGUILayout.TextField("Text", textElement.text); } bool cacheContents = EditorGUILayout.Toggle("Cache Contents", m_SelectedElement.cacheAsBitmap); m_SelectedElement.cacheAsBitmap = cacheContents; if (m_SelectedElement.cacheAsBitmap && m_SelectedElement.computedStyle.overflow.value == Overflow.Visible) { EditorGUILayout.HelpBox("Bitmap caching will be ignored for this element because it's not clipped", MessageType.Warning); } m_SelectedElement.pickingMode = (PickingMode)EditorGUILayout.EnumPopup("Picking Mode", m_SelectedElement.pickingMode); if (m_SelectedElement.pseudoStates != 0) { EditorGUILayout.LabelField("Pseudo States", m_SelectedElement.pseudoStates.ToString()); } else { EditorGUILayout.LabelField("Pseudo States", "None"); } EditorGUILayout.LabelField("Focusable", m_SelectedElement.focusable.ToString()); EditorGUILayout.LabelField("Layout", m_SelectedElement.layout.ToString()); EditorGUILayout.LabelField("World Bound", m_SelectedElement.worldBound.ToString()); EditorGUILayout.LabelField("World Clip", m_SelectedElement.worldClip.ToString()); EditorGUILayout.LabelField("Bounding Box", m_SelectedElement.boundingBox.ToString()); if (m_ClassList == null) { InitClassList(); } m_ClassList.DoLayoutList(); GUILayout.BeginHorizontal(EditorStyles.toolbar); m_DetailFilter = EditorGUILayout.ToolbarSearchField(m_DetailFilter); m_ShowAll = GUILayout.Toggle(m_ShowAll, Styles.showAllContent, EditorStyles.toolbarButton); m_Sort = GUILayout.Toggle(m_Sort, Styles.sortContent, EditorStyles.toolbarButton); GUILayout.EndHorizontal(); var customProperties = m_SelectedElement.specifiedStyle.m_CustomProperties; if (customProperties != null && customProperties.Any()) { foreach (KeyValuePair <string, CustomPropertyHandle> customProperty in customProperties) { foreach (StyleValueHandle handle in customProperty.Value.handles) { EditorGUILayout.LabelField(customProperty.Key, customProperty.Value.data.ReadAsString(handle)); } } } foreach (PropertyInfo field in m_Sort ? k_SortedFieldInfos : k_FieldInfos) { if (!string.IsNullOrEmpty(m_DetailFilter) && field.Name.IndexOf(m_DetailFilter, StringComparison.InvariantCultureIgnoreCase) == -1) { continue; } object val = field.GetValue(m_SelectedElement.computedStyle, null); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); int specificity; if (val is StyleFloat) { StyleFloat style = (StyleFloat)val; specificity = style.specificity; if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity) { style.specificity = Int32.MaxValue; style.value = EditorGUILayout.FloatField(field.Name, ((StyleFloat)val).value); val = style; } } else if (val is StyleInt) { StyleInt style = (StyleInt)val; specificity = style.specificity; if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity) { style.specificity = Int32.MaxValue; style.value = EditorGUILayout.IntField(field.Name, ((StyleInt)val).value); val = style; } } else if (val is StyleLength) { StyleLength style = (StyleLength)val; specificity = style.specificity; if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity) { style.specificity = Int32.MaxValue; style.value = EditorGUILayout.FloatField(field.Name, ((StyleLength)val).value.value); val = style; } } else if (val is StyleColor) { StyleColor style = (StyleColor)val; specificity = style.specificity; if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity) { style.specificity = Int32.MaxValue; style.value = EditorGUILayout.ColorField(field.Name, ((StyleColor)val).value); val = style; } } else if (val is StyleFont) { specificity = HandleReferenceProperty <Font>(field, ref val); } else if (val is StyleBackground) { StyleBackground style = (StyleBackground)val; specificity = style.specificity; if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity) { style.specificity = Int32.MaxValue; Texture2D t = EditorGUILayout.ObjectField(field.Name, style.value.texture, typeof(Texture2D), false) as Texture2D; style.value = new Background(t); val = style; } } else if (val is StyleCursor) { StyleCursor style = (StyleCursor)val; specificity = style.specificity; if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity) { if (style.value.texture != null) { style.specificity = Int32.MaxValue; var texture = EditorGUILayout.ObjectField(field.Name + "'s texture2D", style.value.texture, typeof(Texture2D), false) as Texture2D; EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUIUtility.wideMode = true; var hotspot = EditorGUILayout.Vector2Field(field.Name + "'s hotspot", style.value.hotspot); style.value = new Cursor() { texture = texture, hotspot = hotspot }; val = style; } else { int mouseId = style.value.defaultCursorId; Enum newEnumValue = EditorGUILayout.EnumPopup(field.Name, (MouseCursor)mouseId); int toCompare = Convert.ToInt32(newEnumValue); if (!Equals(mouseId, toCompare)) { style.specificity = Int32.MaxValue; style.value = new Cursor() { defaultCursorId = toCompare }; val = style; } } } } else { Type type = val.GetType(); if (type.IsGenericType && type.GetGenericArguments()[0].IsEnum) { specificity = (int)type.GetProperty("specificity", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(val, null); if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity) { var propInfo = type.GetProperty("value"); Enum enumValue = propInfo.GetValue(val, null) as Enum; Enum newEnumValue = EditorGUILayout.EnumPopup(field.Name, enumValue); if (!Equals(enumValue, newEnumValue)) { propInfo.SetValue(val, newEnumValue, null); } } } else { EditorGUILayout.LabelField(field.Name, val == null ? "null" : val.ToString()); specificity = StyleValueExtensions.UndefinedSpecificity; } } if (EditorGUI.EndChangeCheck()) { string propertyName = field.Name; var inlineStyle = typeof(IStyle).GetProperty(propertyName); inlineStyle.SetValue(m_SelectedElement.style, val, null); } if (m_ShowAll || specificity != StyleValueExtensions.UndefinedSpecificity) { string specificityString = ""; switch (specificity) { case StyleValueExtensions.UnitySpecificity: specificityString = "unity stylesheet"; break; case StyleValueExtensions.InlineSpecificity: specificityString = "inline"; break; case StyleValueExtensions.UndefinedSpecificity: break; default: specificityString = specificity.ToString(); break; } GUILayout.Label(specificityString, GUILayout.MinWidth(200), GUILayout.ExpandWidth(false)); } EditorGUILayout.EndHorizontal(); } }