Ejemplo n.º 1
0
        private static (string CellContent, string HorizontalBorder) StringifyTableCell(
            List <TableCellModel> allCells,
            TableCellModel cell,
            int rowIndex,
            int colIndex,
            int cellCharWidth)
        {
            var hasRowSpan = cell.RowSpan > 1;
            var shouldPrintRowSpanSpace = cell.RenderContentRowIndex != rowIndex && hasRowSpan;
            var contentToPrint          = shouldPrintRowSpanSpace ? string.Empty : cell.Content;

            var paddedCellContent = PadCellContent(contentToPrint, cellCharWidth, cell.HorizontalAlign);
            var cellString        = $"{paddedCellContent}|";

            var horBorderChar           = cell.RenderEndRowIndex > rowIndex ? ' ' : '-';
            var horizontalBorderContent = new string(horBorderChar, paddedCellContent.Length);

            var rowBelowIndex         = rowIndex + 1;
            var cellBelow             = allCells.FirstOrDefault(cm => TableCellPredicate(cm, rowBelowIndex, colIndex));
            var flatVerticalDelimiter = cellBelow == null || cellBelow.RowSpan > 0 && cellBelow.RenderEndColumnIndex > colIndex;

            var verticalDelimiterChar = flatVerticalDelimiter ? '-' : '|';

            horizontalBorderContent = $"{horizontalBorderContent}{verticalDelimiterChar}";

            return(CellContent : cellString, HorizontalBorder : horizontalBorderContent);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initialize a table details view model with the selected cell and a window manager.
 /// </summary>
 public TableDetailsViewModel(TableCellModel theSelectedCell, IWindowManager theWindowManager)
 {
     _selectedCell             = theSelectedCell;
     _windowManager            = theWindowManager;
     DisplayName               = "Details";
     Column                    = "Name";
     Row                       = "1";
     BackgroundColorExpression = string.Empty;
     TextExpression            = string.Empty;
 }
Ejemplo n.º 3
0
        private static int CalculateCellCharWidth(int[] columnCharWidths, int colIndex, TableCellModel cell)
        {
            if (cell.ColSpan > 1)
            {
                var allColumnCharWidths = columnCharWidths
                                          .Skip(cell.RenderStartColumnIndex)
                                          .Take(cell.ColSpan).ToList();

                return(allColumnCharWidths.Select((v, i) => i < allColumnCharWidths.Count - 1 ? v + 1 : v).Sum());
            }

            return(columnCharWidths[colIndex]);
        }
Ejemplo n.º 4
0
 // find cell by "coordinates" col*row in table model
 private static bool TableCellPredicate(TableCellModel cellModel, int rowIndex, int colunmIndex) =>
 cellModel.RenderStartColumnIndex <= colunmIndex &&
 cellModel.RenderEndColumnIndex >= colunmIndex &&
 cellModel.RenderStartRowIndex <= rowIndex &&
 cellModel.RenderEndRowIndex >= rowIndex;