Ejemplo n.º 1
0
        public void EvaluateFor(ForBlock block, int level = 0)
        {
            int start = (int)((CssUnitValue)EvalulateExpression(block.Start)).Value;
            int end   = (int)((CssUnitValue)EvalulateExpression(block.End)).Value;

            if (end < start)
            {
                throw new Exception("end must be after the start");
            }

            if (end - start > 10000)
            {
                throw new Exception("Must be less than 10,000");
            }

            scope = scope.GetChildScope();

            int a = 0;

            for (int i = start; i <= end; i++)
            {
                if (a > 0)
                {
                    writer.WriteLine();
                }

                scope[block.Variable.Symbol] = CssUnitValue.Number(i);

                WriteBlockBody(block, level);

                a++;
            }

            scope = scope.Parent !;
        }
Ejemplo n.º 2
0
 public Thickness(CssUnitValue top, CssUnitValue left, CssUnitValue bottom, CssUnitValue right)
 {
     Top    = top;
     Left   = left;
     Bottom = bottom;
     Right  = right;
 }
Ejemplo n.º 3
0
        // 60px
        // 6.5em

        private static bool TryParseNumberOrMeasurement(string text, out CssValue?value)
        {
            int unitIndex = -1;

            char point;

            for (int i = 0; i < text.Length; i++)
            {
                point = text[i];

                if (point == ' ' || point == ',')
                {
                    value = null;
                    return(false);
                }

                if (char.IsNumber(point) || point == '.')
                {
                }
                else if (unitIndex == -1)
                {
                    unitIndex = i;
                }
            }

            if (unitIndex > 0)
            {
                value = new CssUnitValue(double.Parse(text.Substring(0, unitIndex), CultureInfo.InvariantCulture), text.Substring(unitIndex));
            }
            else
            {
                value = CssValue.Number(double.Parse(text, CultureInfo.InvariantCulture));
            }

            return(true);
        }
Ejemplo n.º 4
0
        public static Thickness Parse(string value)
        {
            var top    = CssUnitValue.Zero;
            var left   = CssUnitValue.Zero;
            var bottom = CssUnitValue.Zero;
            var right  = CssUnitValue.Zero;

            value = value.Trim();

            string[] parts = value.Split(Seperators.Space);

            for (int i = 0; i < parts.Length; i++)
            {
                var part = CssUnitValue.Parse(parts[i].AsSpan());

                if (parts.Length == 1)
                {
                    top    = part;
                    left   = part;
                    bottom = part;
                    right  = part;
                }
                else if (parts.Length == 2)
                {
                    // padding: 10px 20px;
                    // 10px = top & bottom
                    // 20px = left & right

                    switch (i)
                    {
                    case 0: top = part; bottom = part; break;

                    case 1: left = part; right = part; break;
                    }
                }
                else if (parts.Length == 3)
                {
                    // padding: 10px 3% 20px;
                    // 10px = top
                    // 3%   = left & right
                    // 20px = bottom

                    switch (i)
                    {
                    case 0: top = part; break;

                    case 1: left = part; right = part; break;

                    case 3: bottom = part; break;
                    }
                }
                else
                {
                    switch (i)
                    {
                    case 0: top = part; break;

                    case 1: left = part; break;

                    case 2: bottom = part; break;

                    case 3: right = part; break;
                    }
                }
            }

            return(new Thickness(top, left, bottom, right));
        }