internal static YogaValue ToYogaValue(this StyleLength styleValue) { if (styleValue.keyword == StyleKeyword.Auto) { return(YogaValue.Auto()); } // For max-width and max-height if (styleValue.keyword == StyleKeyword.None) { return(float.NaN); } var length = styleValue.value; switch (length.unit) { case LengthUnit.Pixel: return(YogaValue.Point(length.value)); case LengthUnit.Percent: return(YogaValue.Percent(length.value)); default: Debug.LogAssertion($"Unexpected unit '{length.unit}'"); return(float.NaN); } }
private static YogaValue ToYogaValue(JValue value) { if (value == null || value.Type == JTokenType.Null || value.Type == JTokenType.Undefined) { return(YogaValue.Undefined()); } if (value.Type == JTokenType.String) { var s = value.Value <string>(); if (s == "auto") { return(YogaValue.Auto()); } if (s.EndsWith("%")) { return(YogaValue.Percent(float.Parse(s.Substring(0, s.Length - 1)))); } throw new InvalidOperationException( Invariant($"Unknown value: '{s}'")); } return(YogaValue.Point(value.Value <float>())); }
internal static YogaValue ToYogaValue(this Length length) { if (length.IsAuto()) { return(YogaValue.Auto()); } // For max-width and max-height if (length.IsNone()) { return(float.NaN); } switch (length.unit) { case LengthUnit.Pixel: return(YogaValue.Point(length.value)); case LengthUnit.Percent: return(YogaValue.Percent(length.value)); default: Debug.LogAssertion($"Unexpected unit '{length.unit}'"); return(float.NaN); } }
public static YogaValue?NormalizeYogaValue(object value) { if (value == null) { return(YogaValue.Undefined()); } else if (value is YogaValue c) { return(c); } else if (value is double d) { return(YogaValue.Point((float)d)); } else if (value is int i) { return(YogaValue.Point(i)); } else if (value is float v) { return(YogaValue.Point(v)); } else if (value is string s) { if (s == "auto") { return(YogaValue.Auto()); } else if (s.EndsWith("%")) { return(YogaValue.Percent(float.Parse(s.Replace("%", "")))); } else { return(YogaValue.Point(float.Parse(s))); } } else { return(value as YogaValue?); } }
internal static YogaValue ToYogaValue(this StyleLength styleValue) { if (styleValue.keyword == StyleKeyword.Auto) { return(YogaValue.Auto()); } // For max-width and max-height if (styleValue.keyword == StyleKeyword.None) { return(float.NaN); } if (styleValue.specificity != UndefinedSpecificity) { return(styleValue.value.value); } return(float.NaN); }
public static YogaValue StyleLengthToYogaValue(StyleLength value) { if (value.keyword == StyleKeyword.Auto) { return(YogaValue.Auto()); } if (value.keyword == StyleKeyword.Null || value.keyword == StyleKeyword.None || value.keyword == StyleKeyword.Initial) { return(YogaValue.Undefined()); } if (value.value.unit == LengthUnit.Percent) { return(YogaValue.Percent(value.value.value)); } if (value.value.unit == LengthUnit.Pixel) { return(YogaValue.Point(value.value.value)); } return(YogaValue.Undefined()); }
internal static YogaValue ToYogaValue(this StyleLength styleValue) { bool flag = styleValue.keyword == StyleKeyword.Auto; YogaValue result; if (flag) { result = YogaValue.Auto(); } else { bool flag2 = styleValue.keyword == StyleKeyword.None; if (flag2) { result = float.NaN; } else { Length value = styleValue.value; LengthUnit unit = value.unit; LengthUnit lengthUnit = unit; if (lengthUnit != LengthUnit.Pixel) { if (lengthUnit != LengthUnit.Percent) { Debug.LogAssertion(string.Format("Unexpected unit '{0}'", value.unit)); result = float.NaN; } else { result = YogaValue.Percent(value.value); } } else { result = YogaValue.Point(value.value); } } } return(result); }
public object FromString(string value) { if (value == "auto") { return(YogaValue.Auto()); } else if (value.EndsWith("%")) { if (float.TryParse(value.Replace("%", ""), NumberStyles.Float, culture, out var parsedValue)) { return(YogaValue.Percent(parsedValue)); } return(SpecialNames.CantParse); } if (float.TryParse(PxRegex.Replace(value, ""), NumberStyles.Float, culture, out var parsedValue2)) { return(YogaValue.Point(parsedValue2)); } return(SpecialNames.CantParse); }
public void SyncWithLayout(YogaNode targetNode) { targetNode.Flex = float.NaN; float fb = FlexBasisToFloat().GetSpecifiedValueOrDefault(float.NaN); if (fb == -1f) { targetNode.FlexBasis = YogaValue.Auto(); } else { targetNode.FlexBasis = fb; } targetNode.FlexGrow = flexGrow.GetSpecifiedValueOrDefault(float.NaN); targetNode.FlexShrink = flexShrink.GetSpecifiedValueOrDefault(float.NaN); targetNode.Left = positionLeft.GetSpecifiedValueOrDefault(float.NaN); targetNode.Top = positionTop.GetSpecifiedValueOrDefault(float.NaN); targetNode.Right = positionRight.GetSpecifiedValueOrDefault(float.NaN); targetNode.Bottom = positionBottom.GetSpecifiedValueOrDefault(float.NaN); targetNode.MarginLeft = marginLeft.GetSpecifiedValueOrDefault(float.NaN); targetNode.MarginTop = marginTop.GetSpecifiedValueOrDefault(float.NaN); targetNode.MarginRight = marginRight.GetSpecifiedValueOrDefault(float.NaN); targetNode.MarginBottom = marginBottom.GetSpecifiedValueOrDefault(float.NaN); targetNode.PaddingLeft = paddingLeft.GetSpecifiedValueOrDefault(float.NaN); targetNode.PaddingTop = paddingTop.GetSpecifiedValueOrDefault(float.NaN); targetNode.PaddingRight = paddingRight.GetSpecifiedValueOrDefault(float.NaN); targetNode.PaddingBottom = paddingBottom.GetSpecifiedValueOrDefault(float.NaN); targetNode.BorderLeftWidth = borderLeftWidth.GetSpecifiedValueOrDefault(float.NaN); targetNode.BorderTopWidth = borderTopWidth.GetSpecifiedValueOrDefault(float.NaN); targetNode.BorderRightWidth = borderRightWidth.GetSpecifiedValueOrDefault(float.NaN); targetNode.BorderBottomWidth = borderBottomWidth.GetSpecifiedValueOrDefault(float.NaN); targetNode.Width = width.GetSpecifiedValueOrDefault(float.NaN); targetNode.Height = height.GetSpecifiedValueOrDefault(float.NaN); PositionType posType = (PositionType)positionType.value; switch (posType) { case PositionType.Absolute: case PositionType.Manual: targetNode.PositionType = YogaPositionType.Absolute; break; case PositionType.Relative: targetNode.PositionType = YogaPositionType.Relative; break; } targetNode.Overflow = (YogaOverflow)(overflow.value); targetNode.AlignSelf = (YogaAlign)(alignSelf.value); targetNode.MaxWidth = maxWidth.GetSpecifiedValueOrDefault(float.NaN); targetNode.MaxHeight = maxHeight.GetSpecifiedValueOrDefault(float.NaN); targetNode.MinWidth = minWidth.GetSpecifiedValueOrDefault(float.NaN); targetNode.MinHeight = minHeight.GetSpecifiedValueOrDefault(float.NaN); // Note: the following applies to VisualContainer only // but it won't cause any trouble and we avoid making this method virtual targetNode.FlexDirection = (YogaFlexDirection)flexDirection.value; targetNode.AlignContent = (YogaAlign)alignContent.GetSpecifiedValueOrDefault((int)DefaultAlignContent); targetNode.AlignItems = (YogaAlign)alignItems.GetSpecifiedValueOrDefault((int)DefaultAlignItems); targetNode.JustifyContent = (YogaJustify)justifyContent.value; targetNode.Wrap = (YogaWrap)flexWrap.value; }