public override void ApplyStyles() { base.ApplyStyles(); if (ComputedStyle.HasValue(StyleProperties.color)) { Element.tintColor = ComputedStyle.color; } else { Element.tintColor = Color.white; } }
public virtual void ApplyStyles() { Element.style.backgroundColor = StylingHelpers.GetStyleColor(ComputedStyle, StyleProperties.backgroundColor); Element.style.color = StylingHelpers.GetStyleColor(ComputedStyle, StyleProperties.color); Element.style.textOverflow = StylingHelpers.GetStyleEnumCustom <TextOverflow>(ComputedStyle, StyleProperties.textOverflow); Element.style.visibility = StylingHelpers.GetStyleBoolToEnum(ComputedStyle, StyleProperties.visibility, Visibility.Visible, Visibility.Hidden); Element.style.opacity = StylingHelpers.GetStyleFloat(ComputedStyle, StyleProperties.opacity); Element.style.whiteSpace = StylingHelpers.GetStyleBoolToEnum(ComputedStyle, StyleProperties.textWrap, WhiteSpace.Normal, WhiteSpace.NoWrap); if (ComputedStyle.HasValue(StyleProperties.fontSize)) { Element.style.fontSize = ComputedStyle.fontSizeActual; } else { Element.style.fontSize = StyleKeyword.Null; } Element.style.borderBottomLeftRadius = StylingHelpers.GetStyleBorderRadius(ComputedStyle, StyleProperties.borderBottomLeftRadius); Element.style.borderBottomRightRadius = StylingHelpers.GetStyleBorderRadius(ComputedStyle, StyleProperties.borderBottomRightRadius); Element.style.borderTopLeftRadius = StylingHelpers.GetStyleBorderRadius(ComputedStyle, StyleProperties.borderTopLeftRadius); Element.style.borderTopRightRadius = StylingHelpers.GetStyleBorderRadius(ComputedStyle, StyleProperties.borderTopRightRadius); Element.style.borderBottomColor = StylingHelpers.GetStyleBorderColor(ComputedStyle, StyleProperties.borderBottomColor); Element.style.borderTopColor = StylingHelpers.GetStyleBorderColor(ComputedStyle, StyleProperties.borderTopColor); Element.style.borderLeftColor = StylingHelpers.GetStyleBorderColor(ComputedStyle, StyleProperties.borderLeftColor); Element.style.borderRightColor = StylingHelpers.GetStyleBorderColor(ComputedStyle, StyleProperties.borderRightColor); if (ComputedStyle.HasValue(StyleProperties.backgroundImage)) { ComputedStyle.backgroundImage?.Get(Context, tx => Element.style.backgroundImage = tx); } else { Element.style.backgroundImage = StyleKeyword.Null; } if (ComputedStyle.HasValue(StyleProperties.fontStyle) || ComputedStyle.HasValue(StyleProperties.fontWeight)) { Element.style.unityFontStyleAndWeight = StylingHelpers.ConvertFontStyle(ComputedStyle.fontStyle, ComputedStyle.fontWeight); } else { Element.style.unityFontStyleAndWeight = StyleKeyword.Null; } if (ComputedStyle.HasValue(StyleProperties.backgroundImage) && ComputedStyle.HasValue(StyleProperties.backgroundColor)) { Element.style.unityBackgroundImageTintColor = ComputedStyle.backgroundColor; } else { Element.style.unityBackgroundImageTintColor = StyleKeyword.Null; } if (ComputedStyle.HasValue(StyleProperties.textAlign)) { if (StylingHelpers.TextAlignMap.TryGetValue(ComputedStyle.textAlign, out var value)) { Element.style.unityTextAlign = value; } else { Element.style.unityTextAlign = TextAnchor.MiddleCenter; } } else { Element.style.unityTextAlign = StyleKeyword.Null; } if (ComputedStyle.HasValue(StyleProperties.fontFamily)) { if (ComputedStyle.fontFamily != null) { ComputedStyle.fontFamily?.Get(Context, x => { if (x?.sourceFontFile) { Element.style.unityFont = x?.sourceFontFile; } else { Element.style.unityFont = EditorResourcesHelper.DefaultFont; } }); } } else { Element.style.unityFont = StyleKeyword.Null; } if (ComputedStyle.HasValue(StyleProperties.cursor)) { var cursor = EditorResourcesHelper.UtilityCursorClassPrefix + ComputedStyle.cursor; if (currentCursor != cursor) { if (currentCursor != null) { Element.RemoveFromClassList(currentCursor); currentCursor = null; } if (cursor != null) { currentCursor = cursor; Element.AddToClassList(currentCursor); } } } else if (currentCursor != null) { Element.RemoveFromClassList(currentCursor); currentCursor = null; } // Transforms //Element.transform.position -= (Vector3)(Element.layout.size / 2); if (ComputedStyle.HasValue(StyleProperties.scale)) { Element.transform.scale = new Vector3(ComputedStyle.scale.x, ComputedStyle.scale.y, 1); } else { Element.transform.scale = Vector3.one; } if (ComputedStyle.HasValue(StyleProperties.rotate)) { Element.transform.rotation = Quaternion.Euler(ComputedStyle.rotate); } else { Element.transform.rotation = Quaternion.identity; } if (ComputedStyle.HasValue(StyleProperties.translate)) { Element.transform.position = ComputedStyle.translate.AsVector(); } else { Element.transform.position = Vector3.zero; } //Element.transform.position += (Vector3)(Element.layout.size / 2); }