public void ApplyLayoutStyles() { Element.style.flexDirection = StylingHelpers.GetStyleEnumCustom <FlexDirection>(Style, LayoutProperties.FlexDirection); Element.style.flexWrap = StylingHelpers.GetStyleEnumCustom <Wrap>(Style, LayoutProperties.Wrap); Element.style.flexGrow = StylingHelpers.GetStyleFloat(Style, LayoutProperties.FlexGrow); Element.style.flexShrink = StylingHelpers.GetStyleFloat(Style, LayoutProperties.FlexShrink); Element.style.width = StylingHelpers.GetStyleLength(Style, LayoutProperties.Width); Element.style.height = StylingHelpers.GetStyleLength(Style, LayoutProperties.Height); Element.style.flexBasis = StylingHelpers.GetStyleLength(Style, LayoutProperties.FlexBasis); Element.style.minWidth = StylingHelpers.GetStyleLength(Style, LayoutProperties.MinWidth); Element.style.minHeight = StylingHelpers.GetStyleLength(Style, LayoutProperties.MinHeight); Element.style.maxWidth = StylingHelpers.GetStyleLength(Style, LayoutProperties.MaxWidth); Element.style.maxHeight = StylingHelpers.GetStyleLength(Style, LayoutProperties.MaxHeight); Element.style.paddingBottom = StylingHelpers.GetStyleLengthDouble(Style, LayoutProperties.PaddingBottom, LayoutProperties.Padding); Element.style.paddingTop = StylingHelpers.GetStyleLengthDouble(Style, LayoutProperties.PaddingTop, LayoutProperties.Padding); Element.style.paddingLeft = StylingHelpers.GetStyleLengthDouble(Style, LayoutProperties.PaddingLeft, LayoutProperties.Padding); Element.style.paddingRight = StylingHelpers.GetStyleLengthDouble(Style, LayoutProperties.PaddingRight, LayoutProperties.Padding); Element.style.marginBottom = StylingHelpers.GetStyleLengthDouble(Style, LayoutProperties.MarginBottom, LayoutProperties.Margin); Element.style.marginTop = StylingHelpers.GetStyleLengthDouble(Style, LayoutProperties.MarginTop, LayoutProperties.Margin); Element.style.marginLeft = StylingHelpers.GetStyleLengthDouble(Style, LayoutProperties.MarginLeft, LayoutProperties.Margin); Element.style.marginRight = StylingHelpers.GetStyleLengthDouble(Style, LayoutProperties.MarginRight, LayoutProperties.Margin); Element.style.left = StylingHelpers.GetStyleLength(Style, LayoutProperties.Left); Element.style.right = StylingHelpers.GetStyleLength(Style, LayoutProperties.Right); Element.style.top = StylingHelpers.GetStyleLength(Style, LayoutProperties.Top); Element.style.bottom = StylingHelpers.GetStyleLength(Style, LayoutProperties.Bottom); Element.style.borderLeftWidth = StylingHelpers.GetStyleFloatDouble(Style, LayoutProperties.BorderLeftWidth, LayoutProperties.BorderWidth); Element.style.borderRightWidth = StylingHelpers.GetStyleFloatDouble(Style, LayoutProperties.BorderRightWidth, LayoutProperties.BorderWidth); Element.style.borderTopWidth = StylingHelpers.GetStyleFloatDouble(Style, LayoutProperties.BorderTopWidth, LayoutProperties.BorderWidth); Element.style.borderBottomWidth = StylingHelpers.GetStyleFloatDouble(Style, LayoutProperties.BorderBottomWidth, LayoutProperties.BorderWidth); Element.style.display = StylingHelpers.GetStyleEnumCustom <DisplayStyle>(Style, LayoutProperties.Display); Element.style.position = StylingHelpers.GetStyleEnumCustom <Position>(Style, LayoutProperties.PositionType); Element.style.overflow = StylingHelpers.GetStyleEnumCustom <Overflow>(Style, LayoutProperties.Overflow); Element.style.alignContent = StylingHelpers.GetStyleEnumCustom <Align>(Style, LayoutProperties.AlignContent); Element.style.alignItems = StylingHelpers.GetStyleEnumCustom <Align>(Style, LayoutProperties.AlignItems); Element.style.alignSelf = StylingHelpers.GetStyleEnumCustom <Align>(Style, LayoutProperties.AlignSelf); Element.style.justifyContent = StylingHelpers.GetStyleEnumCustom <Justify>(Style, LayoutProperties.JustifyContent); }
public virtual void ApplyStyles() { Element.style.backgroundColor = StylingHelpers.GetStyleColor(Style, StyleProperties.backgroundColor); Element.style.color = StylingHelpers.GetStyleColor(Style, StyleProperties.color); Element.style.textOverflow = StylingHelpers.GetStyleEnumCustom <TextOverflow>(Style, StyleProperties.textOverflow); Element.style.visibility = StylingHelpers.GetStyleBoolToEnum(Style, StyleProperties.visibility, Visibility.Visible, Visibility.Hidden); Element.style.opacity = StylingHelpers.GetStyleFloat(Style, StyleProperties.opacity); Element.style.whiteSpace = StylingHelpers.GetStyleBoolToEnum(Style, StyleProperties.textWrap, WhiteSpace.Normal, WhiteSpace.NoWrap); if (Style.HasValue(StyleProperties.fontSize)) { Element.style.fontSize = Style.fontSizeActual; } else { Element.style.fontSize = StyleKeyword.Null; } Element.style.borderBottomLeftRadius = StylingHelpers.GetStyleBorderRadius(Style, StyleProperties.borderBottomLeftRadius); Element.style.borderBottomRightRadius = StylingHelpers.GetStyleBorderRadius(Style, StyleProperties.borderBottomRightRadius); Element.style.borderTopLeftRadius = StylingHelpers.GetStyleBorderRadius(Style, StyleProperties.borderTopLeftRadius); Element.style.borderTopRightRadius = StylingHelpers.GetStyleBorderRadius(Style, StyleProperties.borderTopRightRadius); Element.style.borderBottomColor = StylingHelpers.GetStyleBorderColor(Style, StyleProperties.borderBottomColor); Element.style.borderTopColor = StylingHelpers.GetStyleBorderColor(Style, StyleProperties.borderTopColor); Element.style.borderLeftColor = StylingHelpers.GetStyleBorderColor(Style, StyleProperties.borderLeftColor); Element.style.borderRightColor = StylingHelpers.GetStyleBorderColor(Style, StyleProperties.borderRightColor); if (Style.HasValue(StyleProperties.backgroundImage)) { Style.backgroundImage?.Get(Context, tx => Element.style.backgroundImage = tx); } else { Element.style.backgroundImage = StyleKeyword.Null; } if (Style.HasValue(StyleProperties.fontStyle) || Style.HasValue(StyleProperties.fontWeight)) { Element.style.unityFontStyleAndWeight = StylingHelpers.ConvertFontStyle(Style.fontStyle, Style.fontWeight); } else { Element.style.unityFontStyleAndWeight = StyleKeyword.Null; } if (Style.HasValue(StyleProperties.backgroundImage) && Style.HasValue(StyleProperties.backgroundColor)) { Element.style.unityBackgroundImageTintColor = Style.backgroundColor; } else { Element.style.unityBackgroundImageTintColor = StyleKeyword.Null; } if (Style.HasValue(StyleProperties.textAlign)) { if (StylingHelpers.TextAlignMap.TryGetValue(Style.textAlign, out var value)) { Element.style.unityTextAlign = value; } else { Element.style.unityTextAlign = TextAnchor.MiddleCenter; } } else { Element.style.unityTextAlign = StyleKeyword.Null; } if (Style.HasValue(StyleProperties.fontFamily)) { if (Style.fontFamily != null) { Style.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 (Style.HasValue(StyleProperties.cursor)) { var cursor = EditorResourcesHelper.UtilityCursorClassPrefix + Style.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 (Style.HasValue(StyleProperties.scale)) { Element.transform.scale = new Vector3(Style.scale.x, Style.scale.y, 1); } else { Element.transform.scale = Vector3.one; } if (Style.HasValue(StyleProperties.rotate)) { Element.transform.rotation = Quaternion.Euler(0, 0, Style.rotate); } else { Element.transform.rotation = Quaternion.identity; } if (Style.HasValue(StyleProperties.translate)) { Element.transform.position = Style.translate.AsVector(); } else { Element.transform.position = Vector3.zero; } //Element.transform.position += (Vector3)(Element.layout.size / 2); }