private static IConsole[] _SplitRows(IConsole c, params Split[] splits) { int height = c.WindowHeight; int splitHeight = splits.Sum(s => s.Size); if (splitHeight + 1 > height) { throw new ArgumentOutOfRangeException($"Console window is not tall enought to support that many rows. Console height:{height}, Sum of split rows:{splitHeight}"); } bool hasWildcard = splits.Any(s => s.Size == 0); int wildCardHeight = height - splitHeight; if (wildCardHeight > 0 && !hasWildcard) { throw new ArgumentOutOfRangeException("The sum of your splits must equal the height of the window if you do not have any wildcard splits."); } var rows = new IConsole[splits.Length]; int row = 0; for (int i = 0; i < splits.Length; i++) { var split = splits[i]; var size = (split.Size == 0) ? wildCardHeight : split.Size; var foregroundColor = split.Foreground ?? c.ForegroundColor; var backgroundColor = split.Background ?? c.BackgroundColor; rows[i] = LayoutExtensions._RowSlice(c, split.Title, row, size, split.Thickness != null, split.Thickness, foregroundColor, backgroundColor); row += size; } return(rows); }
public static IConsole[] SplitColumns(this IConsole c, params Split[] splits) { int width = c.WindowWidth; int splitWidth = splits.Sum(s => s.Size); if (splitWidth + 1 > width) { throw new ArgumentOutOfRangeException($"Console window is not wide enought to support that many columns. Console width:{width}, Sum of split columns:{splitWidth}"); } bool hasWildcard = splits.Any(s => s.Size == 0); int wildCardWidth = width - splitWidth; if (wildCardWidth > 0 && !hasWildcard) { throw new ArgumentOutOfRangeException("The sum of your splits must equal the width of the window if you do not have any wildcard splits."); } var rows = new IConsole[splits.Length]; int row = 0; for (int i = 0; i < splits.Length; i++) { var split = splits[i]; var size = (split.Size == 0) ? wildCardWidth : split.Size; var foregroundColor = split.Foreground ?? c.ForegroundColor; var backgroundColor = split.Background ?? c.BackgroundColor; rows[i] = LayoutExtensions._ColumnSlice(c, split.Title, row, size, split.Thickness != null, split.Thickness, foregroundColor, backgroundColor); row += size; } return(rows); }
internal static (IConsole top, IConsole bottom) _SplitTopBottom(IConsole c, string topTitle, string bottomTitle, LineThickNess thickness, BorderCollapse border, ConsoleColor foreground, ConsoleColor background) { if (border == None) { var top = LayoutExtensions._TopBot(c, topTitle, false, false, thickness, foreground); var bottom = LayoutExtensions._TopBot(c, bottomTitle, true, false, thickness, foreground); return(top, bottom); } if (border == Separate) { var top = LayoutExtensions._TopBot(c, topTitle, false, true, thickness, foreground); var bottom = LayoutExtensions._TopBot(c, bottomTitle, true, true, thickness, foreground); return(top, bottom); } lock (Window._staticLocker) { int h = c.WindowHeight; int width = c.WindowWidth; int topHeight = (h - 3) / 2; int bottomHeight = h - topHeight - 3; char leftChar = thickness == LineThickNess.Double ? '╠' : '├'; char rightChar = thickness == LineThickNess.Double ? '╣' : '┤'; c.DoCommand(c, () => { new Draw(c) .Box(0, 0, width - 1, topHeight + 1, topTitle, thickness); new Draw(c) .Box(0, topHeight + 1, width - 1, bottomHeight + topHeight + 2, bottomTitle, thickness); // print the edges c.PrintAt(0, topHeight + 1, leftChar); c.PrintAt(width, topHeight + 1, rightChar); }); var topWin = Window._CreateFloatingWindow(1, 1, width - 2, topHeight, foreground, background, true, c, null); var bottomWin = Window._CreateFloatingWindow(1, topHeight + 2, width - 2, bottomHeight, foreground, background, true, c, null); return(topWin, bottomWin); } }
internal static (IConsole left, IConsole right) _SplitLeftRight(IConsole c, string leftTitle, string rightTitle, LineThickNess thickness, BorderCollapse border, ConsoleColor foreground, ConsoleColor background) { if (border == None) { var left = LayoutExtensions._LeftRight(c, leftTitle, false, false, thickness, foreground); var right = LayoutExtensions._LeftRight(c, rightTitle, true, false, thickness, foreground); return(left, right); } if (border == Separate) { var left = LayoutExtensions._LeftRight(c, leftTitle, false, true, thickness, foreground); var right = LayoutExtensions._LeftRight(c, rightTitle, true, true, thickness, foreground); return(left, right); } lock (Window._staticLocker) { int h = c.WindowHeight; int w = c.WindowWidth - 3; int leftWidth = w / 2; int rightWidth = (w - leftWidth); c.DoCommand(c, () => { //todo need unit test for merging two boxes :D for now, lets print them twice so we get true overlap to start with new Draw(c) .Box(0, 0, leftWidth + 1, h - 1, leftTitle, thickness); new Draw(c) .Box(leftWidth + 1, 0, rightWidth + leftWidth + 2, h - 1, rightTitle, thickness); // print the corners c.PrintAt(leftWidth + 1, 0, '┬'); c.PrintAt(leftWidth + 1, h - 1, '┴'); }); var leftWin = Window._CreateFloatingWindow(1, 1, leftWidth, h - 2, foreground, background, true, c, null); var rightWin = Window._CreateFloatingWindow(leftWidth + 2, 1, rightWidth, h - 2, foreground, background, true, c, null); return(leftWin, rightWin); } }
// TOPS public static IConsole SplitTop(this Window c) { return(LayoutExtensions._TopBot(c, null, false, false, null, c.ForegroundColor)); }
public static IConsole SplitTop(this Window c, string title, LineThickNess thickness, ConsoleColor foreground) { return(LayoutExtensions._TopBot(c, title, false, true, thickness, foreground)); }
public static IConsole SplitTop(this Window c, string title) { return(LayoutExtensions._TopBot(c, title, false, true, LineThickNess.Single, c.ForegroundColor)); }
public static IConsole SplitLeft(this Window c, string title, LineThickNess thickness) { return(LayoutExtensions._LeftRight(c, title, false, true, thickness, c.ForegroundColor)); }
public static IConsole SplitLeft(this Window c) { return(LayoutExtensions._LeftRight(c, null, false, false, null, c.ForegroundColor)); }
public static IConsole SplitLeft(this Window c, string title, ConsoleColor foreground) { return(LayoutExtensions._LeftRight(c, title, false, true, LineThickNess.Single, foreground)); }
public static IConsole SplitBottom(this Window c, string title, LineThickNess thickness) { return(LayoutExtensions._TopBot(c, title, true, true, thickness, c.ForegroundColor)); }
public static IConsole SplitBottom(this Window c, string title, ConsoleColor foreground) { return(LayoutExtensions._TopBot(c, title, true, true, LineThickNess.Single, foreground)); }
public static IConsole SplitBottom(this Window c, ConsoleColor foreground) { return(LayoutExtensions._TopBot(c, null, true, false, null, foreground)); }
public static IConsole SplitRight(this Window c, ConsoleColor foreground) { return(LayoutExtensions._LeftRight(c, null, true, false, null, foreground)); }