示例#1
0
        public Value(YamlElement node, ElementFactory fac, DataMap def = null)
            : base(node, fac, def)
        {
            string str = "";

            switch (node.Type)
            {
            case YamlElement.Types.Scalar:
                str = node.Val();
                break;

            case YamlElement.Types.Map:
                str = node.Key("value", "").Str();
                if (node.Has("substring"))
                {
                    int pos;
                    var subs = node.Key("substring");
                    if (subs.Type == YamlElement.Types.Map)
                    {
                        if (subs.Has("length") && int.TryParse(subs.Get("length"), out pos))
                        {
                            data.length = pos;
                        }
                        if (subs.Has("start") && int.TryParse(subs.Get("start"), out pos))
                        {
                            data.start = pos;
                        }
                    }
                    else if (subs.Type == YamlElement.Types.Sequence)
                    {
                        var arr = subs.List().Select(i => i.Str()).ToList();
                        if (arr.Count > 1 && int.TryParse(arr[1], out pos))
                        {
                            data.length = pos;
                        }
                        if (arr.Count > 0 && int.TryParse(arr[0], out pos))
                        {
                            data.start = pos;
                        }
                    }
                    else if (subs.Type == YamlElement.Types.Scalar)
                    {
                        var arr = subs.Val().Split(',');
                        if (arr.Length > 1 && int.TryParse(arr[1], out pos))
                        {
                            data.length = pos;
                        }
                        if (arr.Length > 0 && int.TryParse(arr[0], out pos))
                        {
                            data.start = pos;
                        }
                    }
                }
                break;
            }
            data.value = str.Replace("[ [ ", "[[").Replace(" ] ]", "]]");
        }
示例#2
0
        public Box(YamlElement node, ElementFactory fac, DataMap def = null)
            : base(node, fac, def ?? (fac.style.ContainsKey("box") ? fac.style["box"] : null))
        {
            switch (node.Type)
            {
            case YamlElement.Types.Sequence:
                nodes = node.List().Select(i => fac.Detect(i)).ToList();
                break;

            case YamlElement.Types.Map:
                if (node.Has("elements"))
                {
                    var elem = node.Key("elements");
                    if (elem.Type == YamlElement.Types.Sequence)
                    {
                        var cfac = new ElementFactory(fac);
                        foreach (var pair in node.Keys())
                        {
                            if (pair.Value.Type != YamlElement.Types.Map)
                            {
                                continue;
                            }
                            DataMap dat = null;
                            if (!cfac.style.ContainsKey(pair.Key))
                            {
                                cfac.style[pair.Key] = dat = new DataMap();
                            }
                            else
                            {
                                cfac.style[pair.Key] = dat = cfac.style[pair.Key].Copy();
                            }
                            dat.Join(pair.Value.ToData());
                        }
                        nodes = elem.List().Select(i => cfac.Detect(i)).ToList();
                    }
                }
                if (node.Has("contentalign"))
                {
                    var    align = node.Key("contentalign");
                    string x = null, y = null;
                    if (align.Type == YamlElement.Types.Map)
                    {
                        x = align.Get("h", null);
                        y = align.Get("v", null);
                    }
                    else if (align.Type == YamlElement.Types.Sequence)
                    {
                        var arr = align.List().Select(i => i.ToString()).ToList();
                        if (arr.Count == 1)
                        {
                            x = y = arr[0];
                        }
                        else if (arr.Count > 1)
                        {
                            x = arr[0]; y = arr[1];
                        }
                    }
                    else if (align.Type == YamlElement.Types.Scalar)
                    {
                        var arr = align.Val().Split(',');
                        if (arr.Length == 1)
                        {
                            x = y = arr[0];
                        }
                        else if (arr.Length > 1)
                        {
                            x = arr[0]; y = arr[1];
                        }
                    }

                    Alignment align_en;
                    if (Enum.TryParse(x, true, out align_en))
                    {
                        contentX = align_en;
                    }
                    if (Enum.TryParse(y, true, out align_en))
                    {
                        contentY = align_en;
                    }
                }
                break;
            }
        }
示例#3
0
        public Base(YamlElement node, ElementFactory fac, DataMap def = null)
        {
            if (def != null)
            {
                Configure(def, fac);
            }
            if (node.Type != YamlElement.Types.Map)
            {
                return;
            }

            Configure(node.ToData(), fac);

            // position
            if (node.Has("pos"))
            {
                var pos = node.Key("pos");
                if (pos.Type == YamlElement.Types.Map)
                {
                    rect.Up    = fac.unit.Detect(pos.Get("top", null));
                    rect.Down  = fac.unit.Detect(pos.Get("bottom", null));
                    rect.Left  = fac.unit.Detect(pos.Get("left", null));
                    rect.Right = fac.unit.Detect(pos.Get("right", null));
                }
                else if (pos.Type == YamlElement.Types.Sequence)
                {
                    var arr = pos.List().Select(i => (Unit)fac.unit.Detect(i.Val(null)));
                    rect = new Dimension(arr.ToArray());
                }
                else if (pos.Type == YamlElement.Types.Scalar)
                {
                    var arr = pos.Val().Split(',').Select(i => fac.unit.Detect(i));
                    rect = new Dimension(arr.ToArray());
                }
            }

            // size
            if (node.Has("size"))
            {
                var size = node.Key("size");
                if (size.Type == YamlElement.Types.Map)
                {
                    rect.Width  = fac.unit.Detect(size.Get("width", null));
                    rect.Height = fac.unit.Detect(size.Get("height", null));
                }
                else if (size.Type == YamlElement.Types.Sequence)
                {
                    var arr = size.List().Select(i => fac.unit.Detect(i.Val(null)));
                    rect.Size = new Vector(arr.ToArray());
                }
                else if (size.Type == YamlElement.Types.Scalar)
                {
                    var arr = size.Val().Split(',').Select(i => fac.unit.Detect(i));
                    rect.Size = new Vector(arr.ToArray());
                }
            }

            // align
            if (node.Has("align"))
            {
                var    align = node.Key("align");
                string x = null, y = null;
                if (align.Type == YamlElement.Types.Map)
                {
                    x = align.Get("h", null);
                    y = align.Get("v", null);
                }
                else if (align.Type == YamlElement.Types.Sequence)
                {
                    var arr = align.List().Select(i => i.ToString()).ToList();
                    if (arr.Count == 1)
                    {
                        x = y = arr[0];
                    }
                    else if (arr.Count > 1)
                    {
                        x = arr[0]; y = arr[1];
                    }
                }
                else if (align.Type == YamlElement.Types.Scalar)
                {
                    var arr = align.Val().Split(',');
                    if (arr.Length == 1)
                    {
                        x = y = arr[0];
                    }
                    else if (arr.Length > 1)
                    {
                        x = arr[0]; y = arr[1];
                    }
                }

                Alignment align_en;
                if (Enum.TryParse(x, true, out align_en))
                {
                    alignX = align_en;
                }
                if (Enum.TryParse(y, true, out align_en))
                {
                    alignY = align_en;
                }
            }
        }