Exemple #1
0
        public new void Add(Control control)
        {
            var isNameControl = Count % 2 == 0;
            var lastControl   = Children.LastOrDefault();

            base.Add(control);
            var cell = table.Add(control, isNameControl ?
                                 TableConstraint.Alignment(HorizontalAlignment.Right) :
                                 TableConstraint.Alignment(HorizontalAlignment.Left));

            if (isNameControl)
            {
                cell.Style.WhiteSpace = "nowrap";
            }
            else
            {
                control.Label = lastControl;
            }
        }
Exemple #2
0
 public TablePanel(params TableWidth[] columnWidths)
 {
     this.columnWidths = columnWidths;
     DefaultConstraint = new TableConstraint();
 }
Exemple #3
0
 public TablePanel(params TableWidth[] columnWidths)
 {
     this.columnWidths = columnWidths;
     DefaultConstraint = new TableConstraint();
 }
Exemple #4
0
        public Element Add(Control cell, TableConstraint constraint)
        {
            AddChild(cell);

            var nextEmptyCell = GetNextEmptyCell();

            constraint = constraint ?? DefaultConstraint;
            if (nextEmptyCell.X + constraint.ColumnSpan > columnWidths.Length)
            {
                throw new InvalidOperationException($"Added a cell at position ({nextEmptyCell.X},{nextEmptyCell.Y}), but the column ({constraint.ColumnSpan}) exceeds the available remaining space in the row ({columnWidths.Length - nextEmptyCell.X}).");
            }

            var jsCell = Browser.Document.CreateElement("td");

            if (constraint.ColumnSpan != 1)
            {
                jsCell.SetAttribute("colspan", constraint.ColumnSpan.ToString());
            }
            if (constraint.RowSpan != 1)
            {
                jsCell.SetAttribute("rowspan", constraint.RowSpan.ToString());
            }
            var jsCellDiv = Browser.Document.CreateElement("div");

            jsCell.AppendChild(jsCellDiv);
            switch (constraint.HorizontalAlignment)
            {
            case HorizontalAlignment.Left:
                jsCell.SetAttribute("align", "left");
                break;

            case HorizontalAlignment.Center:
                jsCell.SetAttribute("align", "center");
                break;

            case HorizontalAlignment.Right:
                jsCell.SetAttribute("align", "right");
                break;

            case HorizontalAlignment.Fill:
                jsCellDiv.Style.Width = "100%";
                cell.Node.Style.Width = "100%";
                break;
            }
            switch (constraint.VerticalAlignment)
            {
            case VerticalAlignment.Top:
                jsCell.Style.VerticalAlign = "top";
                break;

            case VerticalAlignment.Middle:
                jsCell.Style.VerticalAlign = "middle";
                break;

            case VerticalAlignment.Bottom:
                jsCell.Style.VerticalAlign = "bottom";
                break;

            case VerticalAlignment.Fill:
                cell.Node.Style.Height = "100%";
                jsCellDiv.Style.Height = "100%";
                break;
            }
            jsCellDiv.AppendChild(cell.Node);

            for (var row = nextEmptyCell.Y; row < nextEmptyCell.Y + constraint.RowSpan; row++)
            {
                for (var col = nextEmptyCell.X; col < nextEmptyCell.X + constraint.ColumnSpan; col++)
                {
                    while (cells.Count <= row)
                    {
                        cells.Add(new Control[columnWidths.Length]);
                        var newRow = Browser.Document.CreateElement("tr");
                        table.AppendChild(newRow);
                        rows.Add(newRow);
                    }
                    if (cells[row][col] != null)
                    {
                        throw new InvalidOperationException("Illegal layout: cannot add a view at row " + row + ", column " + col + " as another view is already present: " + cells[row][col]);
                    }
                    cells[row][col] = cell;
                }
            }

            var isFirstRowInTable = nextEmptyCell.Y == 0;
            var isLastCellInRow   = nextEmptyCell.X + constraint.ColumnSpan == columnWidths.Length;

            if (!isLastCellInRow && horizontalCellSpacing != 0)
            {
                jsCell.Style.PaddingRight = horizontalCellSpacing + "px";
            }
            if (!isFirstRowInTable)
            {
                jsCell.Style.PaddingTop = verticalCellSpacing + "px";
            }

            var jsRow = rows[nextEmptyCell.Y];

            jsRow.AppendChild(jsCell);

            return(jsCellDiv);
        }
Exemple #5
0
        public Element Add(Control cell, TableConstraint constraint)
        {
            AddChild(cell);

            var nextEmptyCell = GetNextEmptyCell();
            constraint = constraint ?? DefaultConstraint;
            if (nextEmptyCell.X + constraint.ColumnSpan > columnWidths.Length)
                throw new InvalidOperationException($"Added a cell at position ({nextEmptyCell.X},{nextEmptyCell.Y}), but the column ({constraint.ColumnSpan}) exceeds the available remaining space in the row ({columnWidths.Length - nextEmptyCell.X}).");

            var jsCell = Browser.Document.CreateElement("td");
            if (constraint.ColumnSpan != 1)
                jsCell.SetAttribute("colspan", constraint.ColumnSpan.ToString());                        
            if (constraint.RowSpan != 1)
                jsCell.SetAttribute("rowspan", constraint.RowSpan.ToString());
            var jsCellDiv = Browser.Document.CreateElement("div");
            jsCell.AppendChild(jsCellDiv);
            switch (constraint.HorizontalAlignment)
            {
                case HorizontalAlignment.Left:
                    jsCell.SetAttribute("align", "left");
                    break;
                case HorizontalAlignment.Center:
                    jsCell.SetAttribute("align", "center");
                    break;
                case HorizontalAlignment.Right:
                    jsCell.SetAttribute("align", "right");
                    break;
                case HorizontalAlignment.Fill:
                    jsCellDiv.Style.Width = "100%";
                    cell.Node.Style.Width = "100%";
                    break;
            }
            switch (constraint.VerticalAlignment)
            {
                case VerticalAlignment.Top:
                    jsCell.Style.VerticalAlign = "top";
                    break;
                case VerticalAlignment.Middle:
                    jsCell.Style.VerticalAlign = "middle";
                    break;
                case VerticalAlignment.Bottom:
                    jsCell.Style.VerticalAlign = "bottom";
                    break;
                case VerticalAlignment.Fill:
                    cell.Node.Style.Height = "100%"; 
                    jsCellDiv.Style.Height = "100%";
                    break;
            }
            jsCellDiv.AppendChild(cell.Node);
                        
            for (var row = nextEmptyCell.Y; row < nextEmptyCell.Y + constraint.RowSpan; row++)
            {
                for (var col = nextEmptyCell.X; col < nextEmptyCell.X + constraint.ColumnSpan; col++)
                {
                    while (cells.Count <= row)
                    {
                        cells.Add(new Control[columnWidths.Length]);
                        var newRow = Browser.Document.CreateElement("tr");
                        table.AppendChild(newRow);
                        rows.Add(newRow);
                    }
                    if (cells[row][col] != null)
                        throw new InvalidOperationException("Illegal layout: cannot add a view at row " + row + ", column " + col + " as another view is already present: " + cells[row][col]);
                    cells[row][col] = cell;
                }
            }

            var isFirstRowInTable = nextEmptyCell.Y == 0;
            var isLastCellInRow = nextEmptyCell.X + constraint.ColumnSpan == columnWidths.Length;
            if (!isLastCellInRow && horizontalCellSpacing != 0)
                jsCell.Style.PaddingRight = horizontalCellSpacing + "px";
            if (!isFirstRowInTable)
                jsCell.Style.PaddingTop = verticalCellSpacing + "px";

            var jsRow = rows[nextEmptyCell.Y];
            jsRow.AppendChild(jsCell);

            return jsCellDiv;
        }