Skip to content

Commit

Permalink
add conditionals for old unity versions
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtGokhan committed Nov 11, 2023
1 parent 74abcf3 commit e73a927
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
2 changes: 2 additions & 0 deletions Runtime/Frameworks/UIToolkit/Components/UIToolkitComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ protected override void ApplyStylesSelf()
TargetElement.style.borderLeftColor = StylingHelpers.GetStyleBorderColor(computed, StyleProperties.borderLeftColor);
TargetElement.style.borderRightColor = StylingHelpers.GetStyleBorderColor(computed, StyleProperties.borderRightColor);

#if UNITY_2022_3_OR_NEWER
TargetElement.style.backgroundPositionX = StylingHelpers.GetStyleBackgroundPosition(computed, StyleProperties.backgroundPositionX);
TargetElement.style.backgroundPositionY = StylingHelpers.GetStyleBackgroundPosition(computed, StyleProperties.backgroundPositionY);
TargetElement.style.backgroundSize = StylingHelpers.GetStyleBackgroundSize(computed, StyleProperties.backgroundSize);
TargetElement.style.backgroundRepeat = StylingHelpers.GetStyleBackgroundRepeat(computed, StyleProperties.backgroundRepeatX, StyleProperties.backgroundRepeatY);
#endif

TargetElement.style.letterSpacing = StylingHelpers.GetStyleFloat(computed, StyleProperties.letterSpacing).value;
TargetElement.style.wordSpacing = StylingHelpers.GetStyleFloat(computed, StyleProperties.wordSpacing).value;
Expand Down
76 changes: 39 additions & 37 deletions Runtime/Frameworks/UIToolkit/General/StylingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,44 @@ public static StyleLength GetStyleLength(NodeStyle style, StyleProperty<YogaValu
else return StyleKeyword.Null;
}

public static StyleLength GetStyleLengthDouble(NodeStyle style, StyleProperty<YogaValue> prop, StyleProperty<YogaValue> prop2)
{
if (style.HasValue(prop)) return YogaValueToStyleLength(style.GetStyleValue<YogaValue>(prop));
if (style.HasValue(prop2)) return YogaValueToStyleLength(style.GetStyleValue<YogaValue>(prop2));
else return StyleKeyword.Null;
}

public static StyleEnum<T> GetStyleEnum<T>(NodeStyle style, StyleProperty<T> prop) where T : struct, IConvertible
{
if (style.HasValue(prop)) return style.GetStyleValue<T>(prop);
else return StyleKeyword.Null;
}

public static StyleEnum<T> GetStyleEnumCustom<T>(NodeStyle style, IStyleProperty prop) where T : struct, IConvertible
{
if (style.HasValue(prop)) return style.GetStyleValue<T>(prop);
else return StyleKeyword.Null;
}

public static StyleEnum<T> GetStyleBoolToEnum<T>(NodeStyle style, StyleProperty<bool> prop, T trueValue, T falseValue) where T : struct, IConvertible
{
if (style.HasValue(prop)) return style.GetStyleValue<bool>(prop) ? trueValue : falseValue;
else return StyleKeyword.Null;
}

public static StyleLength GetStyleBorderRadius(NodeStyle style, StyleProperty<YogaValue2> prop)
{
if (style.HasValue(prop)) return YogaValueToStyleLength(style.GetStyleValue<YogaValue2>(prop).X);
else return StyleKeyword.Null;
}

public static StyleColor GetStyleBorderColor(NodeStyle style, StyleProperty<Color> prop)
{
if (style.HasValue(prop)) return style.GetStyleValue<Color>(prop);
else return StyleKeyword.Null;
}

#if UNITY_2022_3_OR_NEWER
public static StyleBackgroundPosition GetStyleBackgroundPosition(NodeStyle style, ValueListStyleProperty<YogaValue> prop)
{
if (style.HasValue(prop))
Expand Down Expand Up @@ -164,42 +202,6 @@ Repeat convertRepeat(Types.BackgroundRepeat val)

return new UnityEngine.UIElements.BackgroundRepeat(convertRepeat(valX), convertRepeat(valY));
}

public static StyleLength GetStyleLengthDouble(NodeStyle style, StyleProperty<YogaValue> prop, StyleProperty<YogaValue> prop2)
{
if (style.HasValue(prop)) return YogaValueToStyleLength(style.GetStyleValue<YogaValue>(prop));
if (style.HasValue(prop2)) return YogaValueToStyleLength(style.GetStyleValue<YogaValue>(prop2));
else return StyleKeyword.Null;
}

public static StyleEnum<T> GetStyleEnum<T>(NodeStyle style, StyleProperty<T> prop) where T : struct, IConvertible
{
if (style.HasValue(prop)) return style.GetStyleValue<T>(prop);
else return StyleKeyword.Null;
}

public static StyleEnum<T> GetStyleEnumCustom<T>(NodeStyle style, IStyleProperty prop) where T : struct, IConvertible
{
if (style.HasValue(prop)) return style.GetStyleValue<T>(prop);
else return StyleKeyword.Null;
}

public static StyleEnum<T> GetStyleBoolToEnum<T>(NodeStyle style, StyleProperty<bool> prop, T trueValue, T falseValue) where T : struct, IConvertible
{
if (style.HasValue(prop)) return style.GetStyleValue<bool>(prop) ? trueValue : falseValue;
else return StyleKeyword.Null;
}

public static StyleLength GetStyleBorderRadius(NodeStyle style, StyleProperty<YogaValue2> prop)
{
if (style.HasValue(prop)) return YogaValueToStyleLength(style.GetStyleValue<YogaValue2>(prop).X);
else return StyleKeyword.Null;
}

public static StyleColor GetStyleBorderColor(NodeStyle style, StyleProperty<Color> prop)
{
if (style.HasValue(prop)) return style.GetStyleValue<Color>(prop);
else return StyleKeyword.Null;
}
#endif
}
}

0 comments on commit e73a927

Please sign in to comment.