public void ApplyCursor(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleCursor property) { float hotspotX; float hotspotY; int cursorId; Texture2D texture; CompileCursor(sheet, handles, out hotspotX, out hotspotY, out cursorId, out texture); var cursor = new Cursor() { texture = texture, hotspot = new Vector2(hotspotX, hotspotY), defaultCursorId = cursorId }; var styleCursor = new StyleCursor(cursor) { specificity = specificity }; property.Apply(styleCursor, StylePropertyApplyMode.CopyIfEqualOrGreaterSpecificity); }
public void Set(StyleCursor cursor, int spec) { propertyID = StylePropertyID.Cursor; m_CurrentCursor = cursor; specificity = spec; }
public void RefreshPropertyValue(object val, int specificity) { if (val is StyleFloat) { var style = (StyleFloat)val; FloatField field = GetOrCreateField <FloatField, float>(); if (!IsFocused(field)) { field.SetValueWithoutNotify(style.value); } } else if (val is StyleInt) { var style = (StyleInt)val; IntegerField field = GetOrCreateField <IntegerField, int>(); if (!IsFocused(field)) { field.SetValueWithoutNotify(style.value); } } else if (val is StyleLength) { var style = (StyleLength)val; StyleLengthField field = GetOrCreateField <StyleLengthField, StyleLength>(); if (!IsFocused(field)) { field.SetValueWithoutNotify(style); } } else if (val is StyleColor) { var style = (StyleColor)val; ColorField field = GetOrCreateField <ColorField, Color>(); if (!IsFocused(field)) { field.SetValueWithoutNotify(style.value); } } else if (val is StyleFont) { var style = (StyleFont)val; ObjectField field = GetOrCreateObjectField <Font>(); if (!IsFocused(field)) { field.SetValueWithoutNotify(style.value); } } else if (val is StyleBackground) { var background = ((StyleBackground)val).value; ObjectField field; if (background.vectorImage != null) { field = GetOrCreateObjectField <VectorImage>(); } else { field = GetOrCreateObjectField <Texture2D>(); } if (!IsFocused(field)) { field.SetValueWithoutNotify(background.vectorImage != null ? (UnityEngine.Object)background.vectorImage : (UnityEngine.Object)background.texture); } } else if (val is StyleCursor) { // Recreate the cursor fields every time since StyleCursor // can be made of different fields (based on the value) Clear(); StyleCursor style = (StyleCursor)val; if (style.value.texture != null) { var uiTextureField = new ObjectField(m_PropertyName) { value = style.value.texture }; uiTextureField.RegisterValueChangedCallback(e => { StyleCursor styleCursor = (StyleCursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id); var currentCursor = styleCursor.value; currentCursor.texture = e.newValue as Texture2D; SetPropertyValue(new StyleCursor(currentCursor)); }); Add(uiTextureField); var uiHotspotField = new Vector2Field("hotspot") { value = style.value.hotspot }; uiHotspotField.RegisterValueChangedCallback(e => { StyleCursor styleCursor = (StyleCursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id); var currentCursor = styleCursor.value; currentCursor.hotspot = e.newValue; SetPropertyValue(new StyleCursor(currentCursor)); }); Add(uiHotspotField); } else { int mouseId = style.value.defaultCursorId; var uiField = new EnumField(m_PropertyName, (MouseCursor)mouseId); uiField.RegisterValueChangedCallback(e => { int cursorId = Convert.ToInt32(e.newValue); var cursor = new Cursor() { defaultCursorId = cursorId }; SetPropertyValue(new StyleCursor(cursor)); }); Add(uiField); } Add(m_SpecificityLabel); SetSpecificity(specificity); } else { // StyleEnum<T> var type = val.GetType(); var propInfo = type.GetProperty("value"); Enum enumValue = propInfo.GetValue(val, null) as Enum; EnumField field = GetOrCreateEnumField(enumValue); if (!IsFocused(field)) { field.SetValueWithoutNotify(enumValue); } } SetSpecificity(specificity); }
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)); } }
internal void ApplyStyleCursor(StyleCursor styleCursor, int specificity) { s_StyleValuePropertyReader.Set(styleCursor, specificity); cursor = s_StyleValuePropertyReader.ReadStyleCursor(0); }
public void ApplyCursor(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleCursor property) { property.Apply(new StyleCursor(currentCursor.value, currentCursor.keyword) { specificity = specificity }, StylePropertyApplyMode.Copy); }
internal void ApplyStyleCursor(StyleCursor styleCursor, int specificity) { s_StyleValueApplicator.currentCursor = styleCursor; s_StyleValueApplicator.ApplyCursor(null, null, specificity, ref cursor); }
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(); } }