Пример #1
0
        public Table(
            Key key = null,
            List <TableRow> children = null,
            Dictionary <int, TableColumnWidth> columnWidths = null,
            TableColumnWidth defaultColumnWidth             = null,
            TableBorder border = null,
            TableCellVerticalAlignment defaultVerticalAlignment = TableCellVerticalAlignment.top,
            TextBaseline?textBaseline = null
            ) : base(key: key)
        {
            children                      = children ?? new List <TableRow>();
            defaultColumnWidth            = defaultColumnWidth ?? new FlexColumnWidth(1.0f);
            this.children                 = children;
            this.columnWidths             = columnWidths;
            this.defaultColumnWidth       = defaultColumnWidth;
            this.border                   = border;
            this.defaultVerticalAlignment = defaultVerticalAlignment;
            this.textBaseline             = textBaseline;
            D.assert(() => {
                if (children.Any((TableRow row) => {
                    return(row.children.Any((Widget cell) => { return cell == null; }));
                }))
                {
                    throw new UIWidgetsError(
                        "One of the children of one of the rows of the table was null.\n" +
                        "The children of a TableRow must not be null."
                        );
                }

                return(true);
            });
            D.assert(() => {
                if (children.Any((TableRow row1) => {
                    return(row1.key != null &&
                           children.Any((TableRow row2) => { return row1 != row2 && row1.key == row2.key; }));
                }))
                {
                    throw new UIWidgetsError(
                        "Two or more TableRow children of this Table had the same key.\n" +
                        "All the keyed TableRow children of a Table must have different Keys."
                        );
                }

                return(true);
            });
            D.assert(() => {
                if (children.isNotEmpty())
                {
                    int cellCount = this.children.First().children.Count;
                    if (children.Any((TableRow row) => { return(row.children.Count != cellCount); }))
                    {
                        throw new UIWidgetsError(
                            "Table contains irregular row lengths.\n" +
                            "Every TableRow in a Table must have the same number of children, so that every cell is filled. " +
                            "Otherwise, the table will contain holes."
                            );
                    }
                }

                return(true);
            });
            _rowDecorations = null;
            if (children.Any((TableRow row) => { return(row.decoration != null); }))
            {
                _rowDecorations = new List <Decoration>();
                foreach (TableRow row in children)
                {
                    _rowDecorations.Add(row.decoration);
                }
            }

            D.assert(() => {
                List <Widget> flatChildren = new List <Widget>();
                foreach (TableRow row in children)
                {
                    flatChildren.AddRange(row.children);
                }

                if (WidgetsD.debugChildrenHaveDuplicateKeys(this, flatChildren))
                {
                    throw new UIWidgetsError(
                        "Two or more cells in this Table contain widgets with the same key.\n" +
                        "Every widget child of every TableRow in a Table must have different keys. The cells of a Table are " +
                        "flattened out for processing, so separate cells cannot have duplicate keys even if they are in " +
                        "different rows."
                        );
                }

                return(true);
            });
        }
Пример #2
0
        public MarkdownStyleSheet(
            TextStyle a,
            TextStyle p,
            TextStyle code,
            TextStyle h1,
            TextStyle h2,
            TextStyle h3,
            TextStyle h4,
            TextStyle h5,
            TextStyle h6,
            TextStyle em,
            TextStyle strong,
            TextStyle del,
            TextStyle blockquote,
            TextStyle img,
            TextStyle checkbox,
            float blockSpacing,
            float listIndent,
            TextStyle listBullet,
            TextStyle tableHead,
            TextStyle tableBody,
            TextAlign tableHeadAlign,
            TableBorder tableBorder,
            TableColumnWidth tableColumnWidth,
            EdgeInsets tableCellsPadding,
            Decoration tableCellsDecoration,
            EdgeInsets blockquotePadding,
            Decoration blockquoteDecoration,
            EdgeInsets codeblockPadding,
            Decoration codeblockDecoration,
            Decoration horizontalRuleDecoration,
            float textScaleFactor = 1.0f
            )
        {
            this.a                        = a;
            this.p                        = p;
            this.code                     = code;
            this.h1                       = h1;
            this.h2                       = h2;
            this.h3                       = h3;
            this.h4                       = h4;
            this.h5                       = h5;
            this.h6                       = h6;
            this.em                       = em;
            this.strong                   = strong;
            this.del                      = del;
            this.blockquote               = blockquote;
            this.img                      = img;
            this.checkbox                 = checkbox;
            this.blockSpacing             = blockSpacing;
            this.listIndent               = listIndent;
            this.listBullet               = listBullet;
            this.tableHead                = tableHead;
            this.tableBody                = tableBody;
            this.tableHeadAlign           = tableHeadAlign;
            this.tableBorder              = tableBorder;
            this.tableColumnWidth         = tableColumnWidth;
            this.tableCellsPadding        = tableCellsPadding;
            this.tableCellsDecoration     = tableCellsDecoration;
            this.blockquotePadding        = blockquotePadding;
            this.blockquoteDecoration     = blockquoteDecoration;
            this.codeblockPadding         = codeblockPadding;
            this.codeblockDecoration      = codeblockDecoration;
            this.horizontalRuleDecoration = horizontalRuleDecoration;
            this.textScaleFactor          = textScaleFactor;

            this._styles = new Dictionary <string, TextStyle>()
            {
                { "a", a },
                { "p", p },
                { "li", p },
                { "code", code },
                { "pre", p },
                { "h1", h1 },
                { "h2", h2 },
                { "h3", h3 },
                { "h4", h4 },
                { "h5", h5 },
                { "h6", h6 },
                { "em", em },
                { "strong", strong },
                { "del", del },
                { "blockquote", blockquote },
                { "img", img },
                { "table", p },
                { "th", tableHead },
                { "tr", tableHead },
                { "td", tableHead },
            };
        }