diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs
index 292f1a23f..7b06a1cad 100644
--- a/Terminal.Gui/Core.cs
+++ b/Terminal.Gui/Core.cs
@@ -444,13 +444,14 @@ namespace Terminal.Gui {
/// Draws a frame in the current view, clipped by the boundary of this view
///
/// Rectangular region for the frame to be drawn.
+ /// The padding to add to the drawn frame.
/// If set to true it fill will the contents.
- public void DrawFrame (Rect rect, bool fill = false)
+ public void DrawFrame (Rect rect, int padding = 0, bool fill = false)
{
var scrRect = RectToScreen (rect);
var savedClip = Driver.Clip;
Driver.Clip = ScreenClip (RectToScreen (Bounds));
- Driver.DrawFrame (scrRect, fill);
+ Driver.DrawFrame (scrRect, padding, fill);
Driver.Clip = savedClip;
}
@@ -933,10 +934,25 @@ namespace Terminal.Gui {
///
/// Frame.
/// Title.
- public Window (Rect frame, string title = null) : base (frame)
+ public Window (Rect frame, string title = null) : this (frame, title, padding: 0)
+ {
+ }
+
+ int padding;
+ ///
+ /// Initializes a new instance of the with
+ /// the specified frame for its location, with the specified border
+ /// an optional title.
+ ///
+ /// Frame.
+ /// Number of characters to use for padding of the drawn frame.
+ /// Title.
+ public Window (Rect frame, string title = null, int padding = 0) : base (frame)
{
this.Title = title;
- var cFrame = new Rect (1, 1, frame.Width - 2, frame.Height - 2);
+ int wb = 2 * (1 + padding);
+ this.padding = padding;
+ var cFrame = new Rect (1 + padding, 1 + padding, frame.Width - wb, frame.Height - wb);
contentView = new ContentView (cFrame);
base.Add (contentView);
}
@@ -952,7 +968,7 @@ namespace Terminal.Gui {
void DrawFrame ()
{
- DrawFrame (new Rect (0, 0, Frame.Width, Frame.Height), true);
+ DrawFrame (new Rect (0, 0, Frame.Width, Frame.Height), padding, fill: true);
}
///
@@ -973,7 +989,7 @@ namespace Terminal.Gui {
Driver.SetAttribute (ColorScheme.Normal);
var width = Frame.Width;
if (Title != null && width > 4) {
- Move (1, 0);
+ Move (1+padding, padding);
Driver.AddCh (' ');
var str = Title.Length > width ? Title.Substring (0, width - 4) : Title;
Driver.AddStr (str);
@@ -1397,7 +1413,7 @@ namespace Terminal.Gui {
// Need to look into why this does not work properly.
static void DrawBounds (View v)
{
- v.DrawFrame (v.Frame, false);
+ v.DrawFrame (v.Frame, padding: 0, fill: false);
if (v.Subviews != null && v.Subviews.Count > 0)
foreach (var sub in v.Subviews)
DrawBounds (sub);
diff --git a/Terminal.Gui/Driver.cs b/Terminal.Gui/Driver.cs
index 53ec4e3c4..53e959f67 100644
--- a/Terminal.Gui/Driver.cs
+++ b/Terminal.Gui/Driver.cs
@@ -222,7 +222,7 @@ namespace Terminal.Gui {
/// Background color identifier.
public abstract void SetColors (short foregroundColorId, short backgroundColorId);
- public abstract void DrawFrame (Rect region, bool fill);
+ public abstract void DrawFrame (Rect region, int padding, bool fill);
///
/// Draws a special characters in the screen
///
@@ -275,7 +275,7 @@ namespace Terminal.Gui {
}
}
- static bool sync;
+ static bool sync = true;
public override void AddCh (int rune)
{
if (Clip.Contains (ccol, crow)) {
@@ -444,32 +444,59 @@ namespace Terminal.Gui {
}
- public override void DrawFrame (Rect region, bool fill)
+ public override void DrawFrame (Rect region, int padding, bool fill)
{
int width = region.Width;
int height = region.Height;
int b;
+ int fwidth = width - padding * 2;
+ int fheight = height - 1 - padding;
Move (region.X, region.Y);
+ if (padding > 0) {
+ for (int l = 0; l < padding; l++)
+ for (b = 0; b < width; b++)
+ AddCh (' ');
+ }
+ Move (region.X, region.Y + padding);
+ for (int c = 0; c < padding; c++)
+ AddCh (' ');
AddCh (Curses.ACS_ULCORNER);
- for (b = 0; b < width - 2; b++)
+ for (b = 0; b < fwidth - 2; b++)
AddCh (Curses.ACS_HLINE);
AddCh (Curses.ACS_URCORNER);
- for (b = 1; b < height - 1; b++) {
+ for (int c = 0; c < padding; c++)
+ AddCh (' ');
+
+ for (b = 1+padding; b < fheight; b++) {
Move (region.X, region.Y + b);
+ for (int c = 0; c < padding; c++)
+ AddCh (' ');
AddCh (Curses.ACS_VLINE);
- if (fill) {
- for (int x = 1; x < width - 1; x++)
+ if (fill) {
+ for (int x = 1; x < fwidth - 1; x++)
AddCh (' ');
} else
- Move (region.X + width - 1, region.Y + b);
+ Move (region.X + fwidth - 1, region.Y + b);
AddCh (Curses.ACS_VLINE);
+ for (int c = 0; c < padding; c++)
+ AddCh (' ');
}
- Move (region.X, region.Y + height - 1);
+ Move (region.X, region.Y + fheight);
+ for (int c = 0; c < padding; c++)
+ AddCh (' ');
AddCh (Curses.ACS_LLCORNER);
- for (b = 0; b < width - 2; b++)
+ for (b = 0; b < fwidth - 2; b++)
AddCh (Curses.ACS_HLINE);
AddCh (Curses.ACS_LRCORNER);
+ for (int c = 0; c < padding; c++)
+ AddCh (' ');
+ if (padding > 0) {
+ Move (region.X, region.Y + height - padding);
+ for (int l = 0; l < padding; l++)
+ for (b = 0; b < width; b++)
+ AddCh (' ');
+ }
}
Curses.Event oldMouseEvents, reportableMouseEvents;
@@ -625,4 +652,182 @@ namespace Terminal.Gui {
return true;
}
}
+
+ internal class NetDriver : ConsoleDriver {
+ public override int Cols => Console.WindowWidth;
+ public override int Rows => Console.WindowHeight;
+
+ int [,,] contents;
+ bool [] dirtyLine;
+
+ static int MakeColor (int fg, int bg)
+ {
+ return (fg << 16) | bg;
+ }
+
+ void UpdateOffscreen ()
+ {
+ int cols = Cols;
+ int rows = Rows;
+
+ contents = new int [cols, rows, 3];
+ for (int r = 0; r < rows; r++) {
+ for (int c = 0; c < cols; c++) {
+ contents [r, c, 0] = ' ';
+ contents [r, c, 1] = MakeColor (7, 0);
+ contents [r, c, 2] = 0;
+ }
+ }
+ dirtyLine = new bool [rows];
+ for (int row = 0; row < rows; row++)
+ dirtyLine [row] = true;
+ }
+
+ public NetDriver ()
+ {
+ UpdateOffscreen ();
+ }
+
+ // Current row, and current col, tracked by Move/AddCh only
+ int ccol, crow;
+ public override void Move (int col, int row)
+ {
+ ccol = col;
+ crow = row;
+ }
+
+ public override void AddCh (int rune)
+ {
+ if (Clip.Contains (ccol, crow)) {
+ contents [crow, ccol, 0] = rune;
+ contents [crow, ccol, 2] = 1;
+ }
+ ccol++;
+ if (ccol == Cols) {
+ ccol = 0;
+ if (crow + 1 < Rows)
+ crow++;
+ }
+ }
+
+ public override void AddSpecial (SpecialChar ch)
+ {
+ AddCh ('*');
+ }
+
+ public override void AddStr (string str)
+ {
+ foreach (var rune in str)
+ AddCh ((int)rune);
+ }
+
+ public override void DrawFrame(Rect region, int padding, bool fill)
+ {
+ int width = region.Width;
+ int height = region.Height;
+ int b;
+
+ Move (region.X, region.Y);
+ AddCh ('+');
+ for (b = 0; b < width - 2; b++)
+ AddCh ('-');
+ AddCh ('+');
+ for (b = 1; b < height - 1; b++) {
+ Move (region.X, region.Y + b);
+ AddCh ('|');
+ if (fill) {
+ for (int x = 1; x < width - 1; x++)
+ AddCh (' ');
+ } else
+ Move (region.X + width - 1, region.Y + b);
+ AddCh ('|');
+ }
+ Move (region.X, region.Y + height - 1);
+ AddCh ('+');
+ for (b = 0; b < width - 2; b++)
+ AddCh ('-');
+ AddCh ('+');
+ }
+
+ public override void End()
+ {
+
+ }
+
+ public override void Init(Action terminalResized)
+ {
+
+ }
+
+ public override void RedrawTop()
+ {
+ int rows = Rows;
+ int cols = Cols;
+
+ Console.CursorTop = 0;
+ Console.CursorLeft = 0;
+ for (int row = 0; row < rows; row++) {
+ dirtyLine [row] = false;
+ for (int col = 0; col < cols; col++) {
+ contents [row, col, 2] = 0;
+ Console.Write ((char)contents [row, col, 0]);
+ }
+ }
+ }
+
+ public override void Refresh()
+ {
+ int rows = Rows;
+ int cols = Cols;
+
+ for (int row = 0; row < rows; row++) {
+ if (!dirtyLine [row])
+ continue;
+ dirtyLine [row] = false;
+ for (int col = 0; col < cols; col++) {
+ if (contents [row, col, 2] != 1)
+ continue;
+
+ Console.CursorTop = row;
+ Console.CursorLeft = col;
+ for (; col < cols && contents [row, col, 2] == 1; col++) {
+ Console.Write ((char)contents [row, col, 0]);
+ contents [row, col, 2] = 0;
+ }
+ }
+ }
+ }
+
+ public override void StartReportingMouseMoves()
+ {
+ }
+
+ public override void StopReportingMouseMoves()
+ {
+ }
+
+ public override void Suspend()
+ {
+ }
+
+ public override void SetAttribute(Attribute c)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void PrepareToRun(MainLoop mainLoop, Action target, Action mouse)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void SetColors(ConsoleColor foreground, ConsoleColor background)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void SetColors(short foregroundColorId, short backgroundColorId)
+ {
+ throw new NotImplementedException();
+ }
+ }
}
diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs
index 35d04283c..a4eaa576f 100644
--- a/Terminal.Gui/Views/Dialog.cs
+++ b/Terminal.Gui/Views/Dialog.cs
@@ -15,6 +15,7 @@ namespace Terminal.Gui {
///
public class Dialog : Window {
List