Browse Source

Merge branch 'v2_develop' into v2_draw-over-a-modal-view_2478

BDisp 2 years ago
parent
commit
89bb0282b2

+ 46 - 6
Terminal.Gui/Core/Frame.cs

@@ -85,8 +85,8 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// <summary>
 		/// Redraws the Frames that comprise the <see cref="Frame"/>.
 		/// Redraws the Frames that comprise the <see cref="Frame"/>.
 		/// </summary>
 		/// </summary>
-		/// <param name="clipRect"></param>
-		public override void Redraw (Rect clipRect)
+		/// <param name="bounds"></param>
+		public override void Redraw (Rect bounds)
 		{
 		{
 			if (Thickness == Thickness.Empty) return;
 			if (Thickness == Thickness.Empty) return;
 
 
@@ -114,7 +114,13 @@ namespace Terminal.Gui {
 
 
 			if (Id == "BorderFrame" && BorderStyle != BorderStyle.None) {
 			if (Id == "BorderFrame" && BorderStyle != BorderStyle.None) {
 				var lc = new LineCanvas ();
 				var lc = new LineCanvas ();
-				if (Thickness.Top > 0 && Frame.Width > 1 && Frame.Height > 1) {
+				
+				var drawTop = Thickness.Top > 0 && Frame.Width > 1 && Frame.Height > 1;
+				var drawLeft = Thickness.Left > 0 && (Frame.Height > 1 || Thickness.Top == 0);
+				var drawBottom = Thickness.Bottom > 0 && Frame.Width > 1;
+				var drawRight = Thickness.Right > 0 && (Frame.Height > 1 || Thickness.Top == 0);
+
+				if (drawTop) {
 					// ╔╡Title╞═════╗
 					// ╔╡Title╞═════╗
 					// ╔╡╞═════╗
 					// ╔╡╞═════╗
 					if (Frame.Width < 4 || ustring.IsNullOrEmpty (Parent?.Title)) {
 					if (Frame.Width < 4 || ustring.IsNullOrEmpty (Parent?.Title)) {
@@ -133,19 +139,53 @@ namespace Terminal.Gui {
 						lc.AddLine (new Point (screenBounds.X + 1 + (titleWidth + 1), screenBounds.Location.Y), Frame.Width - (titleWidth + 3), Orientation.Horizontal, BorderStyle);
 						lc.AddLine (new Point (screenBounds.X + 1 + (titleWidth + 1), screenBounds.Location.Y), Frame.Width - (titleWidth + 3), Orientation.Horizontal, BorderStyle);
 					}
 					}
 				}
 				}
-				if (Thickness.Left > 0 && (Frame.Height > 1 || Thickness.Top == 0)) {
+				if (drawLeft) {
 					lc.AddLine (screenBounds.Location, Frame.Height - 1, Orientation.Vertical, BorderStyle);
 					lc.AddLine (screenBounds.Location, Frame.Height - 1, Orientation.Vertical, BorderStyle);
 				}
 				}
-				if (Thickness.Bottom > 0 && Frame.Width > 1) {
+				if (drawBottom) {
 					lc.AddLine (new Point (screenBounds.X, screenBounds.Y + screenBounds.Height - 1), screenBounds.Width - 1, Orientation.Horizontal, BorderStyle);
 					lc.AddLine (new Point (screenBounds.X, screenBounds.Y + screenBounds.Height - 1), screenBounds.Width - 1, Orientation.Horizontal, BorderStyle);
 				}
 				}
-				if (Thickness.Right > 0 && (Frame.Height > 1 || Thickness.Top == 0)) {
+				if (drawRight) {
 					lc.AddLine (new Point (screenBounds.X + screenBounds.Width - 1, screenBounds.Y), screenBounds.Height - 1, Orientation.Vertical, BorderStyle);
 					lc.AddLine (new Point (screenBounds.X + screenBounds.Width - 1, screenBounds.Y), screenBounds.Height - 1, Orientation.Vertical, BorderStyle);
 				}
 				}
 				foreach (var p in lc.GenerateImage (screenBounds)) {
 				foreach (var p in lc.GenerateImage (screenBounds)) {
 					Driver.Move (p.Key.X, p.Key.Y);
 					Driver.Move (p.Key.X, p.Key.Y);
 					Driver.AddRune (p.Value);
 					Driver.AddRune (p.Value);
 				}
 				}
+
+				// TODO: This should be moved to LineCanvas as a new BorderStyle.Ruler
+				if ((ConsoleDriver.Diagnostics & ConsoleDriver.DiagnosticFlags.FrameRuler) == ConsoleDriver.DiagnosticFlags.FrameRuler) {
+					// Top
+					var hruler = new Ruler () { Length = screenBounds.Width, Orientation = Orientation.Horizontal };
+					if (drawTop) {
+						hruler.Draw (new Point (screenBounds.X, screenBounds.Y));
+					}
+
+					// Redraw title 
+					if (drawTop && Id == "BorderFrame" && !ustring.IsNullOrEmpty (Parent?.Title)) {
+						var prevAttr = Driver.GetAttribute ();
+						Driver.SetAttribute (Parent.HasFocus ? Parent.GetHotNormalColor () : Parent.GetNormalColor ());
+						Driver.DrawWindowTitle (screenBounds, Parent?.Title, 0, 0, 0, 0);
+						Driver.SetAttribute (prevAttr);
+					}
+
+					//Left
+					var vruler = new Ruler () { Length = screenBounds.Height - 2, Orientation = Orientation.Vertical };
+					if (drawLeft) {
+						vruler.Draw (new Point (screenBounds.X, screenBounds.Y + 1), 1);
+					}
+
+					// Bottom
+					if (drawBottom) {
+						hruler.Draw (new Point (screenBounds.X, screenBounds.Y + screenBounds.Height - 1));
+					}
+
+					// Right
+					if (drawRight) {
+						vruler.Draw (new Point (screenBounds.X + screenBounds.Width - 1, screenBounds.Y + 1), 1);
+					}
+
+				}
 			}
 			}
 
 
 
 

+ 16 - 37
Terminal.Gui/Core/Thickness.cs

@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using System.Text.Json.Serialization;
 using System.Text.Json.Serialization;
 using Terminal.Gui.Configuration;
 using Terminal.Gui.Configuration;
+using Terminal.Gui.Graphs;
 
 
 namespace Terminal.Gui {
 namespace Terminal.Gui {
 	/// <summary>
 	/// <summary>
@@ -159,16 +160,6 @@ namespace Terminal.Gui {
 				}
 				}
 			}
 			}
 
 
-			ustring hrule = ustring.Empty;
-			ustring vrule = ustring.Empty;
-			if ((ConsoleDriver.Diagnostics & ConsoleDriver.DiagnosticFlags.FrameRuler) == ConsoleDriver.DiagnosticFlags.FrameRuler) {
-
-				string h = "0123456789";
-				hrule = h.Repeat ((int)Math.Ceiling ((double)(rect.Width) / (double)h.Length)) [0..(rect.Width)];
-				string v = "0123456789";
-				vrule = v.Repeat ((int)Math.Ceiling ((double)(rect.Height * 2) / (double)v.Length)) [0..(rect.Height * 2)];
-			};
-
 			// Draw the Top side
 			// Draw the Top side
 			if (Top > 0) {
 			if (Top > 0) {
 				Application.Driver.FillRect (new Rect (rect.X, rect.Y, rect.Width, Math.Min (rect.Height, Top)), topChar);
 				Application.Driver.FillRect (new Rect (rect.X, rect.Y, rect.Width, Math.Min (rect.Height, Top)), topChar);
@@ -192,20 +183,25 @@ namespace Terminal.Gui {
 			// TODO: This should be moved to LineCanvas as a new BorderStyle.Ruler
 			// TODO: This should be moved to LineCanvas as a new BorderStyle.Ruler
 			if ((ConsoleDriver.Diagnostics & ConsoleDriver.DiagnosticFlags.FrameRuler) == ConsoleDriver.DiagnosticFlags.FrameRuler) {
 			if ((ConsoleDriver.Diagnostics & ConsoleDriver.DiagnosticFlags.FrameRuler) == ConsoleDriver.DiagnosticFlags.FrameRuler) {
 				// Top
 				// Top
-				Application.Driver.Move (rect.X, rect.Y);
-				Application.Driver.AddStr (hrule);
+				var hruler = new Ruler () { Length = rect.Width, Orientation = Orientation.Horizontal };
+				if (Top > 0) {
+					hruler.Draw (new Point (rect.X, rect.Y));
+				}
+
 				//Left
 				//Left
-				for (var r = rect.Y; r < rect.Y + rect.Height; r++) {
-					Application.Driver.Move (rect.X, r);
-					Application.Driver.AddRune (vrule [r - rect.Y]);
+				var vruler = new Ruler () { Length = rect.Height - 2, Orientation = Orientation.Vertical };
+				if (Left > 0) {
+					vruler.Draw (new Point (rect.X, rect.Y + 1), 1);
 				}
 				}
+
 				// Bottom
 				// Bottom
-				Application.Driver.Move (rect.X, rect.Y + rect.Height - Bottom + 1);
-				Application.Driver.AddStr (hrule);
+				if (Bottom > 0) {
+					hruler.Draw (new Point (rect.X, rect.Y + rect.Height - 1));
+				}
+
 				// Right
 				// Right
-				for (var r = rect.Y + 1; r < rect.Y + rect.Height; r++) {
-					Application.Driver.Move (rect.X + rect.Width - Right + 1, r);
-					Application.Driver.AddRune (vrule [r - rect.Y]);
+				if (Right > 0) {
+					vruler.Draw (new Point (rect.X + rect.Width - 1, rect.Y + 1), 1);
 				}
 				}
 			}
 			}
 
 
@@ -281,21 +277,4 @@ namespace Terminal.Gui {
 			return !(left == right);
 			return !(left == right);
 		}
 		}
 	}
 	}
-
-	internal static class StringExtensions {
-		public static string Repeat (this string instr, int n)
-		{
-			if (n <= 0) {
-				return null;
-			}
-
-			if (string.IsNullOrEmpty (instr) || n == 1) {
-				return instr;
-			}
-
-			return new StringBuilder (instr.Length * n)
-				.Insert (0, instr, n)
-				.ToString ();
-		}
-	}
 }
 }

+ 1 - 1
Terminal.Gui/Core/View.cs

@@ -857,7 +857,7 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// <summary>
 		/// Gets or sets the <see cref="Terminal.Gui.TextFormatter"/> which can be handled differently by any derived class.
 		/// Gets or sets the <see cref="Terminal.Gui.TextFormatter"/> which can be handled differently by any derived class.
 		/// </summary>
 		/// </summary>
-		public TextFormatter? TextFormatter { get; set; }
+		public TextFormatter TextFormatter { get; set; }
 
 
 		/// <summary>
 		/// <summary>
 		/// Returns the container for this view, or null if this view has not been added to a container.
 		/// Returns the container for this view, or null if this view has not been added to a container.

+ 86 - 0
Terminal.Gui/Drawing/Ruler.cs

@@ -0,0 +1,86 @@
+using NStack;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Text;
+using System.Text.Json.Serialization;
+using Terminal.Gui.Configuration;
+using Terminal.Gui.Graphs;
+
+namespace Terminal.Gui {
+	/// <summary>
+	/// Draws a ruler on the screen.
+	/// </summary>
+	/// <remarks>
+	/// <para>
+	/// </para>
+	/// </remarks>
+	public class Ruler {
+
+		/// <summary>
+		/// Gets or sets whether the ruler is drawn horizontally or vertically. The default is horizontally.
+		/// </summary>
+		public Orientation Orientation { get; set; }
+
+		/// <summary>
+		/// Gets or sets the lenght of the ruler. The default is 0.
+		/// </summary>
+		public int Length { get; set; }
+
+		/// <summary>
+		/// Gets or sets the foreground and backgrond color to use.
+		/// </summary>
+		public Attribute Attribute { get; set; }
+
+		string _hTemplate { get; set; } = "|123456789";
+		string _vTemplate { get; set; } = "-123456789";
+
+
+		/// <summary>
+		/// Draws the <see cref="Ruler"/>. 
+		/// </summary>
+		/// <param name="location">The location to start drawing the ruler, in screen-relative coordinates.</param>
+		/// <param name="start">The start value of the ruler.</param>
+		public void Draw (Point location, int start = 0)
+		{
+			if (start < 0) {
+				throw new ArgumentException ("start must be greater than or equal to 0");
+			}
+
+			if (Length < 1) {
+				return;
+			}
+
+			if (Orientation == Orientation.Horizontal) {
+				var hrule = _hTemplate.Repeat ((int)Math.Ceiling ((double)Length + 2 / (double)_hTemplate.Length)) [start..(Length + start)];
+				// Top
+				Application.Driver.Move (location.X, location.Y);
+				Application.Driver.AddStr (hrule);
+
+			} else {
+				var vrule = _vTemplate.Repeat ((int)Math.Ceiling ((double)(Length + 2) / (double)_vTemplate.Length)) [start..(Length + start)];
+				for (var r = location.Y; r < location.Y + Length; r++) {
+					Application.Driver.Move (location.X, r);
+					Application.Driver.AddRune (vrule [r - location.Y]);
+				}
+			}
+		}
+	}
+
+	internal static class StringExtensions {
+		public static string Repeat (this string instr, int n)
+		{
+			if (n <= 0) {
+				return null;
+			}
+
+			if (string.IsNullOrEmpty (instr) || n == 1) {
+				return instr;
+			}
+
+			return new StringBuilder (instr.Length * n)
+				.Insert (0, instr, n)
+				.ToString ();
+		}
+	}
+}

+ 2 - 2
UICatalog/Scenarios/Scrolling.cs

@@ -128,7 +128,7 @@ namespace UICatalog.Scenarios {
 			};
 			};
 			label.Text = $"{scrollView}\nContentSize: {scrollView.ContentSize}\nContentOffset: {scrollView.ContentOffset}";
 			label.Text = $"{scrollView}\nContentSize: {scrollView.ContentSize}\nContentOffset: {scrollView.ContentOffset}";
 
 
-			const string rule = "0123456789";
+			//const string rule = "0123456789";
 
 
 			var horizontalRuler = new Label () {
 			var horizontalRuler = new Label () {
 				X = 0,
 				X = 0,
@@ -140,7 +140,7 @@ namespace UICatalog.Scenarios {
 			};
 			};
 			scrollView.Add (horizontalRuler);
 			scrollView.Add (horizontalRuler);
 
 
-			const string vrule = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
+			//const string vrule = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
 
 
 			var verticalRuler = new Label () {
 			var verticalRuler = new Label () {
 				X = 0,
 				X = 0,

+ 66 - 62
UICatalog/UICatalog.cs

@@ -13,6 +13,7 @@ using System.Threading;
 using Terminal.Gui.Configuration;
 using Terminal.Gui.Configuration;
 using static Terminal.Gui.Configuration.ConfigurationManager;
 using static Terminal.Gui.Configuration.ConfigurationManager;
 using System.Text.Json.Serialization;
 using System.Text.Json.Serialization;
+using System.ComponentModel.DataAnnotations;
 
 
 #nullable enable
 #nullable enable
 
 
@@ -70,7 +71,6 @@ namespace UICatalog {
 
 
 			_scenarios = Scenario.GetScenarios ();
 			_scenarios = Scenario.GetScenarios ();
 			_categories = Scenario.GetAllCategories ();
 			_categories = Scenario.GetAllCategories ();
-			_nameColumnWidth = _scenarios.OrderByDescending (s => s.GetName ().Length).FirstOrDefault ().GetName ().Length;
 
 
 			if (args.Length > 0 && args.Contains ("-usc")) {
 			if (args.Length > 0 && args.Contains ("-usc")) {
 				_useSystemConsole = true;
 				_useSystemConsole = true;
@@ -83,7 +83,7 @@ namespace UICatalog {
 			// run it and exit when done.
 			// run it and exit when done.
 			if (args.Length > 0) {
 			if (args.Length > 0) {
 				var item = _scenarios.FindIndex (s => s.GetName ().Equals (args [0], StringComparison.OrdinalIgnoreCase));
 				var item = _scenarios.FindIndex (s => s.GetName ().Equals (args [0], StringComparison.OrdinalIgnoreCase));
-				_selectedScenario = (Scenario)Activator.CreateInstance (_scenarios [item].GetType ());
+				_selectedScenario = (Scenario)Activator.CreateInstance (_scenarios [item].GetType ())!;
 				Application.UseSystemConsole = _useSystemConsole;
 				Application.UseSystemConsole = _useSystemConsole;
 				Application.Init ();
 				Application.Init ();
 				_selectedScenario.Theme = _cachedTheme;
 				_selectedScenario.Theme = _cachedTheme;
@@ -115,7 +115,7 @@ namespace UICatalog {
 			Scenario scenario;
 			Scenario scenario;
 			while ((scenario = RunUICatalogTopLevel ()) != null) {
 			while ((scenario = RunUICatalogTopLevel ()) != null) {
 				VerifyObjectsWereDisposed ();
 				VerifyObjectsWereDisposed ();
-				ConfigurationManager.Themes.Theme = _cachedTheme;
+				ConfigurationManager.Themes!.Theme = _cachedTheme!;
 				ConfigurationManager.Apply ();
 				ConfigurationManager.Apply ();
 				scenario.Theme = _cachedTheme;
 				scenario.Theme = _cachedTheme;
 				scenario.TopLevelColorScheme = _topLevelColorScheme;
 				scenario.TopLevelColorScheme = _topLevelColorScheme;
@@ -151,7 +151,7 @@ namespace UICatalog {
 			// Setup a file system watcher for `./.tui/`
 			// Setup a file system watcher for `./.tui/`
 			_currentDirWatcher.NotifyFilter = NotifyFilters.LastWrite;
 			_currentDirWatcher.NotifyFilter = NotifyFilters.LastWrite;
 			var f = new FileInfo (Assembly.GetExecutingAssembly ().Location);
 			var f = new FileInfo (Assembly.GetExecutingAssembly ().Location);
-			var tuiDir = Path.Combine (f.Directory.FullName, ".tui");
+			var tuiDir = Path.Combine (f.Directory!.FullName, ".tui");
 
 
 			if (!Directory.Exists (tuiDir)) {
 			if (!Directory.Exists (tuiDir)) {
 				Directory.CreateDirectory (tuiDir);
 				Directory.CreateDirectory (tuiDir);
@@ -206,9 +206,9 @@ namespace UICatalog {
 			Application.Init ();
 			Application.Init ();
 
 
 			if (_cachedTheme is null) {
 			if (_cachedTheme is null) {
-				_cachedTheme = ConfigurationManager.Themes.Theme;
+				_cachedTheme = ConfigurationManager.Themes?.Theme;
 			} else {
 			} else {
-				ConfigurationManager.Themes.Theme = _cachedTheme;
+				ConfigurationManager.Themes!.Theme = _cachedTheme;
 				ConfigurationManager.Apply ();
 				ConfigurationManager.Apply ();
 			}
 			}
 
 
@@ -217,40 +217,40 @@ namespace UICatalog {
 			Application.Run<UICatalogTopLevel> ();
 			Application.Run<UICatalogTopLevel> ();
 			Application.Shutdown ();
 			Application.Shutdown ();
 
 
-			return _selectedScenario;
+			return _selectedScenario!;
 		}
 		}
 
 
-		static List<Scenario> _scenarios;
-		static List<string> _categories;
-		static int _nameColumnWidth;
+		static List<Scenario>? _scenarios;
+		static List<string>? _categories;
+
 		// When a scenario is run, the main app is killed. These items
 		// When a scenario is run, the main app is killed. These items
 		// are therefore cached so that when the scenario exits the
 		// are therefore cached so that when the scenario exits the
 		// main app UI can be restored to previous state
 		// main app UI can be restored to previous state
 		static int _cachedScenarioIndex = 0;
 		static int _cachedScenarioIndex = 0;
 		static int _cachedCategoryIndex = 0;
 		static int _cachedCategoryIndex = 0;
-		static string? _cachedTheme;
-		
-		static StringBuilder _aboutMessage;
+		static string? _cachedTheme = string.Empty;
+
+		static StringBuilder? _aboutMessage = null;
 
 
 		// If set, holds the scenario the user selected
 		// If set, holds the scenario the user selected
-		static Scenario _selectedScenario = null;
+		static Scenario? _selectedScenario = null;
 
 
 		static bool _useSystemConsole = false;
 		static bool _useSystemConsole = false;
 		static ConsoleDriver.DiagnosticFlags _diagnosticFlags;
 		static ConsoleDriver.DiagnosticFlags _diagnosticFlags;
 		//static bool _enableConsoleScrolling = false;
 		//static bool _enableConsoleScrolling = false;
 		static bool _isFirstRunning = true;
 		static bool _isFirstRunning = true;
-		static string _topLevelColorScheme;
-
-		static MenuItem [] _themeMenuItems;
-		static MenuBarItem _themeMenuBarItem;
+		static string _topLevelColorScheme = string.Empty;
 
 
+		static MenuItem []? _themeMenuItems;
+		static MenuBarItem? _themeMenuBarItem;
+		
 		/// <summary>
 		/// <summary>
 		/// This is the main UI Catalog app view. It is run fresh when the app loads (if a Scenario has not been passed on 
 		/// This is the main UI Catalog app view. It is run fresh when the app loads (if a Scenario has not been passed on 
 		/// the command line) and each time a Scenario ends.
 		/// the command line) and each time a Scenario ends.
 		/// </summary>
 		/// </summary>
 		public class UICatalogTopLevel : Toplevel {
 		public class UICatalogTopLevel : Toplevel {
-			public MenuItem miIsMouseDisabled;
-			public MenuItem miEnableConsoleScrolling;
+			public MenuItem? miIsMouseDisabled;
+			public MenuItem? miEnableConsoleScrolling;
 
 
 			public TileView ContentPane;
 			public TileView ContentPane;
 			public ListView CategoryListView;
 			public ListView CategoryListView;
@@ -276,7 +276,7 @@ namespace UICatalog {
 						new MenuItem ("_gui.cs API Overview", "", () => OpenUrl ("https://gui-cs.github.io/Terminal.Gui/articles/overview.html"), null, null, Key.F1),
 						new MenuItem ("_gui.cs API Overview", "", () => OpenUrl ("https://gui-cs.github.io/Terminal.Gui/articles/overview.html"), null, null, Key.F1),
 						new MenuItem ("gui.cs _README", "", () => OpenUrl ("https://github.com/gui-cs/Terminal.Gui"), null, null, Key.F2),
 						new MenuItem ("gui.cs _README", "", () => OpenUrl ("https://github.com/gui-cs/Terminal.Gui"), null, null, Key.F2),
 						new MenuItem ("_About...",
 						new MenuItem ("_About...",
-							"About UI Catalog", () =>  MessageBox.Query ("About UI Catalog", _aboutMessage.ToString(), 0, false, "_Ok"), null, null, Key.CtrlMask | Key.A),
+							"About UI Catalog", () =>  MessageBox.Query ("About UI Catalog", _aboutMessage!.ToString(), 0, false, "_Ok"), null, null, Key.CtrlMask | Key.A),
 					}),
 					}),
 				});
 				});
 
 
@@ -302,7 +302,7 @@ namespace UICatalog {
 					}),
 					}),
 					new StatusItem(Key.F10, "~F10~ Status Bar", () => {
 					new StatusItem(Key.F10, "~F10~ Status Bar", () => {
 						StatusBar.Visible = !StatusBar.Visible;
 						StatusBar.Visible = !StatusBar.Visible;
-						ContentPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
+						ContentPane!.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
 						LayoutSubviews();
 						LayoutSubviews();
 						SetSubViewNeedsDisplay();
 						SetSubViewNeedsDisplay();
 					}),
 					}),
@@ -332,7 +332,7 @@ namespace UICatalog {
 					CanFocus = true,
 					CanFocus = true,
 				};
 				};
 				CategoryListView.OpenSelectedItem += (s,a) => {
 				CategoryListView.OpenSelectedItem += (s,a) => {
-					ScenarioListView.SetFocus ();
+					ScenarioListView!.SetFocus ();
 				};
 				};
 				CategoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
 				CategoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
 
 
@@ -371,12 +371,12 @@ namespace UICatalog {
 				ConfigurationManager.Applied += ConfigAppliedHandler;
 				ConfigurationManager.Applied += ConfigAppliedHandler;
 			}
 			}
       
       
-			void LoadedHandler (object sender, EventArgs args)
+			void LoadedHandler (object? sender, EventArgs? args)
 			{
 			{
 				ConfigChanged ();
 				ConfigChanged ();
 
 
-				miIsMouseDisabled.Checked = Application.IsMouseDisabled;
-				miEnableConsoleScrolling.Checked = Application.EnableConsoleScrolling;
+				miIsMouseDisabled!.Checked = Application.IsMouseDisabled;
+				miEnableConsoleScrolling!.Checked = Application.EnableConsoleScrolling;
 				DriverName.Title = $"Driver: {Driver.GetType ().Name}";
 				DriverName.Title = $"Driver: {Driver.GetType ().Name}";
 				OS.Title = $"OS: {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem} {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion}";
 				OS.Title = $"OS: {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem} {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion}";
 
 
@@ -391,7 +391,7 @@ namespace UICatalog {
 				StatusBar.VisibleChanged += (s, e) => {
 				StatusBar.VisibleChanged += (s, e) => {
 					UICatalogApp.ShowStatusBar = StatusBar.Visible;
 					UICatalogApp.ShowStatusBar = StatusBar.Visible;
 
 
-					var height = (StatusBar.Visible ? 1 : 0);// + (MenuBar.Visible ? 1 : 0);
+					var height = (StatusBar.Visible ? 1 : 0);
 					ContentPane.Height = Dim.Fill (height);
 					ContentPane.Height = Dim.Fill (height);
 					LayoutSubviews ();
 					LayoutSubviews ();
 					SetSubViewNeedsDisplay ();
 					SetSubViewNeedsDisplay ();
@@ -400,13 +400,13 @@ namespace UICatalog {
 				Loaded -= LoadedHandler;
 				Loaded -= LoadedHandler;
 			}
 			}
 
 
-			private void UnloadedHandler (object sender, EventArgs args)
+			private void UnloadedHandler (object? sender, EventArgs? args)
 			{
 			{
 				ConfigurationManager.Applied -= ConfigAppliedHandler;
 				ConfigurationManager.Applied -= ConfigAppliedHandler;
 				Unloaded -= UnloadedHandler;
 				Unloaded -= UnloadedHandler;
 			}
 			}
       
       
-			void ConfigAppliedHandler (object sender, ConfigurationManagerEventArgs a)
+			void ConfigAppliedHandler (object? sender, ConfigurationManagerEventArgs? a)
 			{
 			{
 				ConfigChanged ();
 				ConfigChanged ();
 			}
 			}
@@ -415,14 +415,16 @@ namespace UICatalog {
 			/// Launches the selected scenario, setting the global _selectedScenario
 			/// Launches the selected scenario, setting the global _selectedScenario
 			/// </summary>
 			/// </summary>
 			/// <param name="e"></param>
 			/// <param name="e"></param>
-			void ScenarioListView_OpenSelectedItem (object sender, EventArgs e)
+			void ScenarioListView_OpenSelectedItem (object? sender, EventArgs? e)
 			{
 			{
 				if (_selectedScenario is null) {
 				if (_selectedScenario is null) {
 					// Save selected item state
 					// Save selected item state
 					_cachedCategoryIndex = CategoryListView.SelectedItem;
 					_cachedCategoryIndex = CategoryListView.SelectedItem;
 					_cachedScenarioIndex = ScenarioListView.SelectedItem;
 					_cachedScenarioIndex = ScenarioListView.SelectedItem;
 					// Create new instance of scenario (even though Scenarios contains instances)
 					// Create new instance of scenario (even though Scenarios contains instances)
-					_selectedScenario = (Scenario)Activator.CreateInstance (ScenarioListView.Source.ToList () [ScenarioListView.SelectedItem].GetType ());
+					var sourceList = ScenarioListView.Source.ToList ();
+
+					_selectedScenario = (Scenario)Activator.CreateInstance (ScenarioListView.Source.ToList () [ScenarioListView.SelectedItem]!.GetType ())!;
 
 
 					// Tell the main app to stop
 					// Tell the main app to stop
 					Application.RequestStop ();
 					Application.RequestStop ();
@@ -431,12 +433,13 @@ namespace UICatalog {
 
 
 			List<MenuItem []> CreateDiagnosticMenuItems ()
 			List<MenuItem []> CreateDiagnosticMenuItems ()
 			{
 			{
-				List<MenuItem []> menuItems = new List<MenuItem []> ();
-				menuItems.Add (CreateDiagnosticFlagsMenuItems ());
-				menuItems.Add (new MenuItem [] { null });
-				menuItems.Add (CreateEnableConsoleScrollingMenuItems ());
-				menuItems.Add (CreateDisabledEnabledMouseItems ());
-				menuItems.Add (CreateKeybindingsMenuItems ());
+				List<MenuItem []> menuItems = new List<MenuItem []> {
+					CreateDiagnosticFlagsMenuItems (),
+					new MenuItem [] { },
+					CreateEnableConsoleScrollingMenuItems (),
+					CreateDisabledEnabledMouseItems (),
+					CreateKeybindingsMenuItems ()
+				};
 				return menuItems;
 				return menuItems;
 			}
 			}
 
 
@@ -446,10 +449,10 @@ namespace UICatalog {
 				miIsMouseDisabled = new MenuItem {
 				miIsMouseDisabled = new MenuItem {
 					Title = "_Disable Mouse"
 					Title = "_Disable Mouse"
 				};
 				};
-				miIsMouseDisabled.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miIsMouseDisabled.Title.ToString ().Substring (1, 1) [0];
+				miIsMouseDisabled.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miIsMouseDisabled!.Title!.ToString ()!.Substring (1, 1) [0];
 				miIsMouseDisabled.CheckType |= MenuItemCheckStyle.Checked;
 				miIsMouseDisabled.CheckType |= MenuItemCheckStyle.Checked;
 				miIsMouseDisabled.Action += () => {
 				miIsMouseDisabled.Action += () => {
-					miIsMouseDisabled.Checked = Application.IsMouseDisabled = (bool)!miIsMouseDisabled.Checked;
+					miIsMouseDisabled.Checked = Application.IsMouseDisabled = (bool)!miIsMouseDisabled.Checked!;
 				};
 				};
 				menuItems.Add (miIsMouseDisabled);
 				menuItems.Add (miIsMouseDisabled);
 
 
@@ -468,7 +471,7 @@ namespace UICatalog {
 					Application.Run (dlg);
 					Application.Run (dlg);
 				};
 				};
 
 
-				menuItems.Add (null);
+				menuItems.Add (null!);
 				menuItems.Add (item);
 				menuItems.Add (item);
 
 
 				return menuItems.ToArray ();
 				return menuItems.ToArray ();
@@ -479,11 +482,11 @@ namespace UICatalog {
 				List<MenuItem> menuItems = new List<MenuItem> ();
 				List<MenuItem> menuItems = new List<MenuItem> ();
 				miEnableConsoleScrolling = new MenuItem ();
 				miEnableConsoleScrolling = new MenuItem ();
 				miEnableConsoleScrolling.Title = "_Enable Console Scrolling";
 				miEnableConsoleScrolling.Title = "_Enable Console Scrolling";
-				miEnableConsoleScrolling.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miEnableConsoleScrolling.Title.ToString ().Substring (1, 1) [0];
+				miEnableConsoleScrolling.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miEnableConsoleScrolling.Title.ToString ()!.Substring (1, 1) [0];
 				miEnableConsoleScrolling.CheckType |= MenuItemCheckStyle.Checked;
 				miEnableConsoleScrolling.CheckType |= MenuItemCheckStyle.Checked;
 				miEnableConsoleScrolling.Action += () => {
 				miEnableConsoleScrolling.Action += () => {
 					miEnableConsoleScrolling.Checked = !miEnableConsoleScrolling.Checked;
 					miEnableConsoleScrolling.Checked = !miEnableConsoleScrolling.Checked;
-					Application.EnableConsoleScrolling = (bool)miEnableConsoleScrolling.Checked;
+					Application.EnableConsoleScrolling = (bool)miEnableConsoleScrolling.Checked!;
 				};
 				};
 				menuItems.Add (miEnableConsoleScrolling);
 				menuItems.Add (miEnableConsoleScrolling);
 
 
@@ -554,10 +557,10 @@ namespace UICatalog {
 
 
 				Enum GetDiagnosticsEnumValue (ustring title)
 				Enum GetDiagnosticsEnumValue (ustring title)
 				{
 				{
-					return title.ToString () switch {
+					return title!.ToString () switch {
 						FRAME_RULER => ConsoleDriver.DiagnosticFlags.FrameRuler,
 						FRAME_RULER => ConsoleDriver.DiagnosticFlags.FrameRuler,
 						FRAME_PADDING => ConsoleDriver.DiagnosticFlags.FramePadding,
 						FRAME_PADDING => ConsoleDriver.DiagnosticFlags.FramePadding,
-						_ => null,
+						_ => null!,
 					};
 					};
 				}
 				}
 
 
@@ -585,10 +588,10 @@ namespace UICatalog {
 				}
 				}
 			}
 			}
 
 
-			public MenuItem [] CreateThemeMenuItems ()
+			public MenuItem []? CreateThemeMenuItems ()
 			{
 			{
 				List<MenuItem> menuItems = new List<MenuItem> ();
 				List<MenuItem> menuItems = new List<MenuItem> ();
-				foreach (var theme in ConfigurationManager.Themes) {
+				foreach (var theme in ConfigurationManager.Themes!) {
 					var item = new MenuItem {
 					var item = new MenuItem {
 						Title = theme.Key,
 						Title = theme.Key,
 						Shortcut = Key.AltMask + theme.Key [0]
 						Shortcut = Key.AltMask + theme.Key [0]
@@ -621,7 +624,7 @@ namespace UICatalog {
 					};
 					};
 					schemeMenuItems.Add (item);
 					schemeMenuItems.Add (item);
 				}
 				}
-				menuItems.Add (null);
+				menuItems.Add (null!);
 				var mbi = new MenuBarItem ("_Color Scheme for Application.Top", schemeMenuItems.ToArray ());
 				var mbi = new MenuBarItem ("_Color Scheme for Application.Top", schemeMenuItems.ToArray ());
 				menuItems.Add (mbi);
 				menuItems.Add (mbi);
 
 
@@ -635,18 +638,19 @@ namespace UICatalog {
 				}
 				}
 
 
 				_themeMenuItems = ((UICatalogTopLevel)Application.Top).CreateThemeMenuItems ();
 				_themeMenuItems = ((UICatalogTopLevel)Application.Top).CreateThemeMenuItems ();
-				_themeMenuBarItem.Children = _themeMenuItems;
+				_themeMenuBarItem!.Children = _themeMenuItems;
 
 
-				var checkedThemeMenu = _themeMenuItems.Where (m => (bool)m.Checked).FirstOrDefault ();
+				var checkedThemeMenu = _themeMenuItems?.Where (m => m?.Checked ?? false).FirstOrDefault ();
 				if (checkedThemeMenu != null) {
 				if (checkedThemeMenu != null) {
 					checkedThemeMenu.Checked = false;
 					checkedThemeMenu.Checked = false;
 				}
 				}
-				checkedThemeMenu = _themeMenuItems.Where (m => m != null && m.Title == ConfigurationManager.Themes.Theme).FirstOrDefault ();
+				checkedThemeMenu = _themeMenuItems?.Where (m => m != null && m.Title == ConfigurationManager.Themes?.Theme).FirstOrDefault ();
 				if (checkedThemeMenu != null) {
 				if (checkedThemeMenu != null) {
-					ConfigurationManager.Themes.Theme = checkedThemeMenu.Title.ToString ();
+					ConfigurationManager.Themes!.Theme = checkedThemeMenu.Title.ToString ()!;
 					checkedThemeMenu.Checked = true;
 					checkedThemeMenu.Checked = true;
 				}
 				}
-				var schemeMenuItems = ((MenuBarItem)_themeMenuItems.Where (i => i is MenuBarItem).FirstOrDefault ()).Children;
+
+				var schemeMenuItems = ((MenuBarItem)_themeMenuItems?.Where (i => i is MenuBarItem)!.FirstOrDefault ()!)!.Children;
 				foreach (var schemeMenuItem in schemeMenuItems) {
 				foreach (var schemeMenuItem in schemeMenuItems) {
 					schemeMenuItem.Checked = (string)schemeMenuItem.Data == _topLevelColorScheme;
 					schemeMenuItem.Checked = (string)schemeMenuItem.Data == _topLevelColorScheme;
 				}
 				}
@@ -659,8 +663,8 @@ namespace UICatalog {
 				StatusBar.Items [0].Shortcut = Application.QuitKey;
 				StatusBar.Items [0].Shortcut = Application.QuitKey;
 				StatusBar.Items [0].Title = $"~{Application.QuitKey} to quit";
 				StatusBar.Items [0].Title = $"~{Application.QuitKey} to quit";
 
 
-				miIsMouseDisabled.Checked = Application.IsMouseDisabled;
-				miEnableConsoleScrolling.Checked = Application.EnableConsoleScrolling;
+				miIsMouseDisabled!.Checked = Application.IsMouseDisabled;
+				miEnableConsoleScrolling!.Checked = Application.EnableConsoleScrolling;
 
 
 				var height = (UICatalogApp.ShowStatusBar ? 1 : 0);// + (MenuBar.Visible ? 1 : 0);
 				var height = (UICatalogApp.ShowStatusBar ? 1 : 0);// + (MenuBar.Visible ? 1 : 0);
 				ContentPane.Height = Dim.Fill (height);
 				ContentPane.Height = Dim.Fill (height);
@@ -670,9 +674,9 @@ namespace UICatalog {
 				Application.Top.SetNeedsDisplay ();
 				Application.Top.SetNeedsDisplay ();
 			}
 			}
 
 
-			void KeyDownHandler (object sender, KeyEventEventArgs a)
+			void KeyDownHandler (object? sender, KeyEventEventArgs? a)
 			{
 			{
-				if (a.KeyEvent.IsCapslock) {
+				if (a!.KeyEvent.IsCapslock) {
 					Capslock.Title = "Caps: On";
 					Capslock.Title = "Caps: On";
 					StatusBar.SetNeedsDisplay ();
 					StatusBar.SetNeedsDisplay ();
 				} else {
 				} else {
@@ -680,7 +684,7 @@ namespace UICatalog {
 					StatusBar.SetNeedsDisplay ();
 					StatusBar.SetNeedsDisplay ();
 				}
 				}
 
 
-				if (a.KeyEvent.IsNumlock) {
+				if (a!.KeyEvent.IsNumlock) {
 					Numlock.Title = "Num: On";
 					Numlock.Title = "Num: On";
 					StatusBar.SetNeedsDisplay ();
 					StatusBar.SetNeedsDisplay ();
 				} else {
 				} else {
@@ -688,7 +692,7 @@ namespace UICatalog {
 					StatusBar.SetNeedsDisplay ();
 					StatusBar.SetNeedsDisplay ();
 				}
 				}
 
 
-				if (a.KeyEvent.IsScrolllock) {
+				if (a!.KeyEvent.IsScrolllock) {
 					Scrolllock.Title = "Scroll: On";
 					Scrolllock.Title = "Scroll: On";
 					StatusBar.SetNeedsDisplay ();
 					StatusBar.SetNeedsDisplay ();
 				} else {
 				} else {
@@ -697,16 +701,16 @@ namespace UICatalog {
 				}
 				}
 			}
 			}
 
 
-			void CategoryListView_SelectedChanged (object sender, ListViewItemEventArgs e)
+			void CategoryListView_SelectedChanged (object? sender, ListViewItemEventArgs? e)
 			{
 			{
-				var item = _categories [e.Item];
+				var item = _categories! [e!.Item];
 				List<Scenario> newlist;
 				List<Scenario> newlist;
 				if (e.Item == 0) {
 				if (e.Item == 0) {
 					// First category is "All"
 					// First category is "All"
-					newlist = _scenarios;
+					newlist = _scenarios!;
 
 
 				} else {
 				} else {
-					newlist = _scenarios.Where (s => s.GetCategories ().Contains (item)).ToList ();
+					newlist = _scenarios!.Where (s => s.GetCategories ().Contains (item)).ToList ();
 				}
 				}
 				ScenarioListView.SetSource (newlist.ToList ());
 				ScenarioListView.SetSource (newlist.ToList ());
 			}
 			}

+ 13 - 0
UnitTests/Application/ApplicationTests.cs

@@ -461,6 +461,19 @@ namespace Terminal.Gui.ApplicationTests {
 		}
 		}
 		#endregion
 		#endregion
 
 
+		[Fact, AutoInitShutdown]
+		public void Begin_Sets_Application_Top_To_Console_Size()
+		{
+			Assert.Equal (new Rect (0, 0, 80, 25), Application.Top.Frame);
+
+			((FakeDriver)Application.Driver).SetBufferSize (5, 5);
+			Application.Begin (Application.Top);
+			// BUGBUG: v2 - 
+			Assert.Equal (new Rect (0, 0, 80, 25), Application.Top.Frame);
+			((FakeDriver)Application.Driver).SetBufferSize (5, 5);
+			Assert.Equal (new Rect (0, 0, 5, 5), Application.Top.Frame);
+		}
+
 		[Fact]
 		[Fact]
 		[AutoInitShutdown]
 		[AutoInitShutdown]
 		public void SetCurrentAsTop_Run_A_Not_Modal_Toplevel_Make_It_The_Current_Application_Top ()
 		public void SetCurrentAsTop_Run_A_Not_Modal_Toplevel_Make_It_The_Current_Application_Top ()

+ 131 - 0
UnitTests/Core/ThicknessTests.cs

@@ -485,6 +485,137 @@ namespace Terminal.Gui.CoreTests {
 
 
 		}
 		}
 
 
+		[Fact (), AutoInitShutdown]
+		public void DrawTests_Ruler ()
+		{
+			// Add a frame so we can see the ruler
+			var f = new FrameView () {
+				X = 0,
+				Y = 0,
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+			};
+
+
+			Application.Top.Add (f);
+			Application.Begin (Application.Top);
+			
+			((FakeDriver)Application.Driver).SetBufferSize (45, 20);
+			var t = new Thickness (0, 0, 0, 0);
+			var r = new Rect (2, 2, 40, 15);
+			Application.Refresh ();
+			ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FrameRuler;
+			t.Draw (r, "Test");
+			ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
+			TestHelpers.AssertDriverContentsAre (@"
+┌───────────────────────────────────────────┐
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+└───────────────────────────────────────────┘", output);
+
+
+			t = new Thickness (1, 1, 1, 1);
+			r = new Rect (1, 1, 40, 15);
+			Application.Refresh ();
+			ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FrameRuler;
+			t.Draw (r, "Test");
+			ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
+			TestHelpers.AssertDriverContentsAre (@"
+┌───────────────────────────────────────────┐
+│|123456789|123456789|123456789|123456789   │
+│1                                      1   │
+│2                                      2   │
+│3                                      3   │
+│4                                      4   │
+│5                                      5   │
+│6                                      6   │
+│7                                      7   │
+│8                                      8   │
+│9                                      9   │
+│-                                      -   │
+│1                                      1   │
+│2                                      2   │
+│3                                      3   │
+│|123456789|123456789|123456789|123456789   │
+│                                           │
+│                                           │
+│                                           │
+└───────────────────────────────────────────┘", output);
+
+			t = new Thickness (1, 2, 3, 4);
+			r = new Rect (2, 2, 40, 15);
+			Application.Refresh ();
+			ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FrameRuler;
+			t.Draw (r, "Test");
+			ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌───────────────────────────────────────────┐
+│                                           │
+│ |123456789|123456789|123456789|123456789  │
+│ 1                                      1  │
+│ 2                                      2  │
+│ 3                                      3  │
+│ 4                                      4  │
+│ 5                                      5  │
+│ 6                                      6  │
+│ 7                                      7  │
+│ 8                                      8  │
+│ 9                                      9  │
+│ -                                      -  │
+│ 1                                      1  │
+│ 2                                      2  │
+│ 3                                      3  │
+│ |123456789|123456789|123456789|123456789  │
+│                                           │
+│                                           │
+└───────────────────────────────────────────┘", output);
+
+
+			t = new Thickness (-1, 1, 1, 1);
+			r = new Rect (5, 5, 40, 15);
+			Application.Refresh ();
+			ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FrameRuler;
+			t.Draw (r, "Test");
+			ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌───────────────────────────────────────────┐
+│                                           │
+│                                           │
+│                                           │
+│                                           │
+│    |123456789|123456789|123456789|123456789
+│                                           1
+│                                           2
+│                                           3
+│                                           4
+│                                           5
+│                                           6
+│                                           7
+│                                           8
+│                                           9
+│                                           -
+│                                           1
+│                                           2
+│                                           3
+└────|123456789|123456789|123456789|123456789", output);
+
+		}
 		[Fact ()]
 		[Fact ()]
 		public void EqualsTest ()
 		public void EqualsTest ()
 		{
 		{

+ 368 - 0
UnitTests/Drawing/RulerTests.cs

@@ -0,0 +1,368 @@
+using Terminal.Gui;
+using NStack;
+using System;
+using System.Collections.Generic;
+using System.Xml.Linq;
+using Terminal.Gui.Graphs;
+using Xunit;
+using Xunit.Abstractions;
+//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
+
+// Alias Console to MockConsole so we don't accidentally use Console
+using Console = Terminal.Gui.FakeConsole;
+
+namespace Terminal.Gui.DrawingTests {
+	public class RulerTests {
+
+		readonly ITestOutputHelper output;
+
+		public RulerTests (ITestOutputHelper output)
+		{
+			this.output = output;
+		}
+
+		[Fact ()]
+		public void Constructor_Defaults ()
+		{
+			var r = new Ruler ();
+			Assert.Equal (0, r.Length);
+			Assert.Equal (Orientation.Horizontal, r.Orientation);
+			Assert.Equal (default, r.Attribute);
+		}
+
+
+		[Fact ()]
+		public void Orientation_set ()
+		{
+			var r = new Ruler ();
+			Assert.Equal (Orientation.Horizontal, r.Orientation);
+			r.Orientation = Orientation.Vertical;
+			Assert.Equal (Orientation.Vertical, r.Orientation);
+		}
+
+		[Fact ()]
+		public void Length_set ()
+		{
+			var r = new Ruler ();
+			Assert.Equal (0, r.Length);
+			r.Length = 42;
+			Assert.Equal (42, r.Length);
+		}
+
+		[Fact ()]
+		public void Attribute_set ()
+		{
+			var newAttribute = new Attribute (Color.Red, Color.Green);
+
+			var r = new Ruler ();
+			Assert.Equal (default, r.Attribute);
+			r.Attribute = newAttribute;
+			Assert.Equal (newAttribute, r.Attribute);
+		}
+
+		[Fact (), AutoInitShutdown]
+		public void Draw_Default ()
+		{
+			((FakeDriver)Application.Driver).SetBufferSize (25, 25);
+
+			var r = new Ruler ();
+			r.Draw (new Point (0, 0));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
+		}
+
+		[Fact (), AutoInitShutdown]
+		public void Draw_Horizontal ()
+		{
+			var len = 15;
+
+			// Add a frame so we can see the ruler
+			var f = new FrameView () {
+				X = 0,
+				Y = 0,
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+			};
+			Application.Top.Add (f);
+			Application.Begin (Application.Top);
+			((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
+			Assert.Equal (new Rect (0, 0, len + 5, 5), f.Frame);
+
+			var r = new Ruler ();
+			Assert.Equal (Orientation.Horizontal, r.Orientation);
+
+			r.Length = len;
+			r.Draw (new Point (0, 0));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+|123456789|1234────┐
+│                  │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			// Postive offset
+			Application.Refresh ();
+			r.Draw (new Point (1, 1));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│|123456789|1234   │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			// Negative offset
+			Application.Refresh ();
+			r.Draw (new Point (-1, 1));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+123456789|1234     │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			// Clip
+			Application.Refresh ();
+			r.Draw (new Point (10, 1));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│         |123456789
+│                  │
+│                  │
+└──────────────────┘", output);
+		}
+
+		[Fact (), AutoInitShutdown]
+		public void Draw_Horizontal_Start ()
+		{
+			var len = 15;
+
+			// Add a frame so we can see the ruler
+			var f = new FrameView () {
+				X = 0,
+				Y = 0,
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+			};
+			Application.Top.Add (f);
+			Application.Begin (Application.Top);
+			((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
+			Assert.Equal (new Rect (0, 0, len + 5, 5), f.Frame);
+
+			var r = new Ruler ();
+			Assert.Equal (Orientation.Horizontal, r.Orientation);
+
+			r.Length = len;
+			r.Draw (new Point (0, 0), 1);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+123456789|12345────┐
+│                  │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			Application.Refresh ();
+			r.Length = len;
+			r.Draw (new Point (1, 0), 1);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌123456789|12345───┐
+│                  │
+│                  │
+│                  │
+└──────────────────┘", output);
+		}
+
+		[Fact (), AutoInitShutdown]
+		public void Draw_Vertical ()
+		{
+			var len = 15;
+
+			// Add a frame so we can see the ruler
+			var f = new FrameView () {
+				X = 0,
+				Y = 0,
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+			};
+
+
+			Application.Top.Add (f);
+			Application.Begin (Application.Top);
+			((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
+			Assert.Equal (new Rect (0, 0, 5, len + 5), f.Frame);
+
+			var r = new Ruler ();
+			r.Orientation = Orientation.Vertical;
+			r.Length = len;
+			r.Draw (new Point (0, 0));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+-───┐
+1   │
+2   │
+3   │
+4   │
+5   │
+6   │
+7   │
+8   │
+9   │
+-   │
+1   │
+2   │
+3   │
+4   │
+│   │
+│   │
+│   │
+│   │
+└───┘", output);
+
+			// Postive offset
+			Application.Refresh ();
+			r.Draw (new Point (1, 1));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌───┐
+│-  │
+│1  │
+│2  │
+│3  │
+│4  │
+│5  │
+│6  │
+│7  │
+│8  │
+│9  │
+│-  │
+│1  │
+│2  │
+│3  │
+│4  │
+│   │
+│   │
+│   │
+└───┘", output);
+
+			// Negative offset
+			Application.Refresh ();
+			r.Draw (new Point (1, -1));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌1──┐
+│2  │
+│3  │
+│4  │
+│5  │
+│6  │
+│7  │
+│8  │
+│9  │
+│-  │
+│1  │
+│2  │
+│3  │
+│4  │
+│   │
+│   │
+│   │
+│   │
+│   │
+└───┘", output);
+
+			// Clip
+			Application.Refresh ();
+			r.Draw (new Point (1, 10));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌───┐
+│   │
+│   │
+│   │
+│   │
+│   │
+│   │
+│   │
+│   │
+│   │
+│-  │
+│1  │
+│2  │
+│3  │
+│4  │
+│5  │
+│6  │
+│7  │
+│8  │
+└9──┘", output);
+		}
+
+		[Fact (), AutoInitShutdown]
+		public void Draw_Vertical_Start ()
+		{
+			var len = 15;
+
+			// Add a frame so we can see the ruler
+			var f = new FrameView () {
+				X = 0,
+				Y = 0,
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+			};
+
+
+			Application.Top.Add (f);
+			Application.Begin (Application.Top);
+			((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
+			Assert.Equal (new Rect (0, 0, 5, len + 5), f.Frame);
+
+			var r = new Ruler ();
+			r.Orientation = Orientation.Vertical;
+			r.Length = len;
+			r.Draw (new Point (0, 0), 1);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+1───┐
+2   │
+3   │
+4   │
+5   │
+6   │
+7   │
+8   │
+9   │
+-   │
+1   │
+2   │
+3   │
+4   │
+5   │
+│   │
+│   │
+│   │
+│   │
+└───┘", output);
+
+			Application.Refresh ();
+			r.Length = len;
+			r.Draw (new Point (0, 1), 1);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌───┐
+1   │
+2   │
+3   │
+4   │
+5   │
+6   │
+7   │
+8   │
+9   │
+-   │
+1   │
+2   │
+3   │
+4   │
+5   │
+│   │
+│   │
+│   │
+└───┘", output);
+
+		}
+	}
+}
+
+

+ 3 - 4
UnitTests/TestHelpers.cs

@@ -28,8 +28,8 @@ public class AutoInitShutdownAttribute : Xunit.Sdk.BeforeAfterTestAttribute {
 	/// </summary>
 	/// </summary>
 	/// <param name="autoInit">If true, Application.Init will be called Before the test runs.</param>
 	/// <param name="autoInit">If true, Application.Init will be called Before the test runs.</param>
 	/// <param name="autoShutdown">If true, Application.Shutdown will be called After the test runs.</param>
 	/// <param name="autoShutdown">If true, Application.Shutdown will be called After the test runs.</param>
-	/// <param name="consoleDriverType">Determins which ConsoleDriver (FakeDriver, WindowsDriver, 
-	/// CursesDriver, NetDriver) will be used when Appliation.Init is called. If null FakeDriver will be used.
+	/// <param name="consoleDriverType">Determines which ConsoleDriver (FakeDriver, WindowsDriver, 
+	/// CursesDriver, NetDriver) will be used when Application.Init is called. If null FakeDriver will be used.
 	/// Only valid if <paramref name="autoInit"/> is true.</param>
 	/// Only valid if <paramref name="autoInit"/> is true.</param>
 	/// <param name="useFakeClipboard">If true, will force the use of <see cref="FakeDriver.FakeClipboard"/>. 
 	/// <param name="useFakeClipboard">If true, will force the use of <see cref="FakeDriver.FakeClipboard"/>. 
 	/// Only valid if <see cref="consoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.</param>
 	/// Only valid if <see cref="consoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.</param>
@@ -126,7 +126,7 @@ class TestHelpers {
 			actualLook = actualLook.Replace ("\r\n", "\n");
 			actualLook = actualLook.Replace ("\r\n", "\n");
 
 
 			// If test is about to fail show user what things looked like
 			// If test is about to fail show user what things looked like
-			if(!string.Equals(expectedLook,actualLook)) {
+			if (!string.Equals (expectedLook, actualLook)) {
 				output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
 				output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
 				output?.WriteLine ("But Was:" + Environment.NewLine + actualLook);
 				output?.WriteLine ("But Was:" + Environment.NewLine + actualLook);
 			}
 			}
@@ -282,4 +282,3 @@ class TestHelpers {
 		return $"{a.Foreground},{a.Background}";
 		return $"{a.Foreground},{a.Background}";
 	}
 	}
 }
 }
-

+ 0 - 1
UnitTests/TopLevels/ToplevelTests.cs

@@ -39,7 +39,6 @@ namespace Terminal.Gui.TopLevelTests {
 			Assert.Equal (new Rect (0, 0, Application.Driver.Cols, Application.Driver.Rows), top.Bounds);
 			Assert.Equal (new Rect (0, 0, Application.Driver.Cols, Application.Driver.Rows), top.Bounds);
 		}
 		}
 
 
-
 		[Fact]
 		[Fact]
 		[AutoInitShutdown]
 		[AutoInitShutdown]
 		public void Application_Top_EnsureVisibleBounds_To_Driver_Rows_And_Cols ()
 		public void Application_Top_EnsureVisibleBounds_To_Driver_Rows_And_Cols ()

+ 64 - 1
UnitTests/Views/FrameViewTests.cs

@@ -1,12 +1,21 @@
-using System;
+using Microsoft.VisualStudio.TestPlatform.Utilities;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using Xunit;
 using Xunit;
+using Xunit.Abstractions;
 
 
 namespace Terminal.Gui.ViewTests {
 namespace Terminal.Gui.ViewTests {
 	public class FrameViewTests {
 	public class FrameViewTests {
+		readonly ITestOutputHelper output;
+
+		public FrameViewTests (ITestOutputHelper output)
+		{
+			this.output = output;
+		}
+
 		[Fact]
 		[Fact]
 		public void Constuctors_Defaults ()
 		public void Constuctors_Defaults ()
 		{
 		{
@@ -28,5 +37,59 @@ namespace Terminal.Gui.ViewTests {
 			fv.EndInit ();
 			fv.EndInit ();
 			Assert.Equal (new Rect (1, 2, 10, 20), fv.Frame);
 			Assert.Equal (new Rect (1, 2, 10, 20), fv.Frame);
 		}
 		}
+
+		[Fact, AutoInitShutdown]
+		public void Draw_Defaults ()
+		{
+			((FakeDriver)Application.Driver).SetBufferSize (10, 10);
+			var fv = new FrameView ();
+			Assert.Equal (string.Empty, fv.Title);
+			Assert.Equal (string.Empty, fv.Text);
+			Assert.NotNull (fv.Border);
+			Application.Top.Add (fv);
+			Application.Begin (Application.Top);
+			Assert.Equal (new Rect (0, 0, 0, 0), fv.Frame);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
+
+			fv.Height = 5;
+			fv.Width = 5;
+			Assert.Equal (new Rect (0, 0, 5, 5), fv.Frame);
+			Application.Refresh ();
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌───┐
+│   │
+│   │
+│   │
+└───┘", output);
+
+
+			fv.X = 1;
+			fv.Y = 2;
+			Assert.Equal (new Rect (1, 2, 5, 5), fv.Frame);
+			Application.Refresh ();
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+ ┌───┐
+ │   │
+ │   │
+ │   │
+ └───┘", output);
+
+			fv.X = -1;
+			fv.Y = -2;
+			Assert.Equal (new Rect (-1, -2, 5, 5), fv.Frame);
+			Application.Refresh ();
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+   │
+   │
+───┘", output);
+
+			fv.X = 7;
+			fv.Y = 8;
+			Assert.Equal (new Rect (7, 8, 5, 5), fv.Frame);
+			Application.Refresh ();
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+       ┌──
+       │  ", output);
+		}
 	}
 	}
 }
 }

+ 19 - 9
UnitTests/Views/GraphViewTests.cs

@@ -12,7 +12,7 @@ using Xunit.Abstractions;
 using Rune = System.Rune;
 using Rune = System.Rune;
 
 
 namespace Terminal.Gui.ViewTests {
 namespace Terminal.Gui.ViewTests {
-#if false // BUGBUG: v2 see https://github.com/gui-cs/Terminal.Gui/issues/2463
+// BUGBUG: v2 see https://github.com/gui-cs/Terminal.Gui/issues/2463
 
 
 	#region Helper Classes
 	#region Helper Classes
 	class FakeHAxis : HorizontalAxis {
 	class FakeHAxis : HorizontalAxis {
@@ -86,6 +86,8 @@ namespace Terminal.Gui.ViewTests {
 			GraphViewTests.InitFakeDriver ();
 			GraphViewTests.InitFakeDriver ();
 
 
 			var gv = new GraphView ();
 			var gv = new GraphView ();
+			gv.BeginInit (); gv.EndInit ();
+
 			gv.ColorScheme = new ColorScheme ();
 			gv.ColorScheme = new ColorScheme ();
 			gv.MarginBottom = 1;
 			gv.MarginBottom = 1;
 			gv.MarginLeft = 1;
 			gv.MarginLeft = 1;
@@ -100,6 +102,8 @@ namespace Terminal.Gui.ViewTests {
 		public void ScreenToGraphSpace_DefaultCellSize ()
 		public void ScreenToGraphSpace_DefaultCellSize ()
 		{
 		{
 			var gv = new GraphView ();
 			var gv = new GraphView ();
+			gv.BeginInit (); gv.EndInit ();
+
 			gv.Bounds = new Rect (0, 0, 20, 10);
 			gv.Bounds = new Rect (0, 0, 20, 10);
 
 
 			// origin should be bottom left
 			// origin should be bottom left
@@ -119,7 +123,7 @@ namespace Terminal.Gui.ViewTests {
 		public void ScreenToGraphSpace_DefaultCellSize_WithMargin ()
 		public void ScreenToGraphSpace_DefaultCellSize_WithMargin ()
 		{
 		{
 			var gv = new GraphView ();
 			var gv = new GraphView ();
-			gv.LayoutSubviews ();
+			gv.BeginInit (); gv.EndInit ();
 
 
 			gv.Bounds = new Rect (0, 0, 20, 10);
 			gv.Bounds = new Rect (0, 0, 20, 10);
 
 
@@ -155,7 +159,7 @@ namespace Terminal.Gui.ViewTests {
 		public void ScreenToGraphSpace_CustomCellSize ()
 		public void ScreenToGraphSpace_CustomCellSize ()
 		{
 		{
 			var gv = new GraphView ();
 			var gv = new GraphView ();
-			gv.LayoutSubviews ();
+			gv.BeginInit (); gv.EndInit ();
 
 
 			gv.Bounds = new Rect (0, 0, 20, 10);
 			gv.Bounds = new Rect (0, 0, 20, 10);
 
 
@@ -186,7 +190,7 @@ namespace Terminal.Gui.ViewTests {
 		public void GraphSpaceToScreen_DefaultCellSize ()
 		public void GraphSpaceToScreen_DefaultCellSize ()
 		{
 		{
 			var gv = new GraphView ();
 			var gv = new GraphView ();
-			gv.LayoutSubviews ();
+			gv.BeginInit (); gv.EndInit ();
 
 
 			gv.Bounds = new Rect (0, 0, 20, 10);
 			gv.Bounds = new Rect (0, 0, 20, 10);
 
 
@@ -205,7 +209,7 @@ namespace Terminal.Gui.ViewTests {
 		public void GraphSpaceToScreen_DefaultCellSize_WithMargin ()
 		public void GraphSpaceToScreen_DefaultCellSize_WithMargin ()
 		{
 		{
 			var gv = new GraphView ();
 			var gv = new GraphView ();
-			gv.LayoutSubviews ();
+			gv.BeginInit (); gv.EndInit ();
 
 
 			gv.Bounds = new Rect (0, 0, 20, 10);
 			gv.Bounds = new Rect (0, 0, 20, 10);
 
 
@@ -234,7 +238,7 @@ namespace Terminal.Gui.ViewTests {
 		public void GraphSpaceToScreen_ScrollOffset ()
 		public void GraphSpaceToScreen_ScrollOffset ()
 		{
 		{
 			var gv = new GraphView ();
 			var gv = new GraphView ();
-			gv.LayoutSubviews ();
+			gv.BeginInit (); gv.EndInit ();
 
 
 			gv.Bounds = new Rect (0, 0, 20, 10);
 			gv.Bounds = new Rect (0, 0, 20, 10);
 
 
@@ -255,7 +259,7 @@ namespace Terminal.Gui.ViewTests {
 		public void GraphSpaceToScreen_CustomCellSize ()
 		public void GraphSpaceToScreen_CustomCellSize ()
 		{
 		{
 			var gv = new GraphView ();
 			var gv = new GraphView ();
-			gv.LayoutSubviews ();
+			gv.BeginInit (); gv.EndInit ();
 			
 			
 			gv.Bounds = new Rect (0, 0, 20, 10);
 			gv.Bounds = new Rect (0, 0, 20, 10);
 
 
@@ -295,7 +299,7 @@ namespace Terminal.Gui.ViewTests {
 		public void GraphSpaceToScreen_CustomCellSize_WithScrollOffset ()
 		public void GraphSpaceToScreen_CustomCellSize_WithScrollOffset ()
 		{
 		{
 			var gv = new GraphView ();
 			var gv = new GraphView ();
-			gv.LayoutSubviews ();
+			gv.BeginInit (); gv.EndInit ();
 
 
 			gv.Bounds = new Rect (0, 0, 20, 10);
 			gv.Bounds = new Rect (0, 0, 20, 10);
 
 
@@ -340,6 +344,8 @@ namespace Terminal.Gui.ViewTests {
 			InitFakeDriver ();
 			InitFakeDriver ();
 
 
 			var gv = new GraphView ();
 			var gv = new GraphView ();
+			gv.BeginInit (); gv.EndInit ();
+
 			gv.ColorScheme = new ColorScheme ();
 			gv.ColorScheme = new ColorScheme ();
 			gv.Bounds = new Rect (0, 0, 50, 30);
 			gv.Bounds = new Rect (0, 0, 50, 30);
 			gv.Series.Add (new ScatterSeries () { Points = new List<PointF> { new PointF (1, 1) } });
 			gv.Series.Add (new ScatterSeries () { Points = new List<PointF> { new PointF (1, 1) } });
@@ -363,6 +369,7 @@ namespace Terminal.Gui.ViewTests {
 		public void TestReversing_ScreenToGraphSpace ()
 		public void TestReversing_ScreenToGraphSpace ()
 		{
 		{
 			var gv = new GraphView ();
 			var gv = new GraphView ();
+			gv.BeginInit (); gv.EndInit ();
 			gv.Bounds = new Rect (0, 0, 50, 30);
 			gv.Bounds = new Rect (0, 0, 50, 30);
 
 
 			// How much graph space each cell of the console depicts
 			// How much graph space each cell of the console depicts
@@ -414,6 +421,7 @@ namespace Terminal.Gui.ViewTests {
 			GraphViewTests.InitFakeDriver ();
 			GraphViewTests.InitFakeDriver ();
 
 
 			var gv = new GraphView ();
 			var gv = new GraphView ();
+			gv.BeginInit (); gv.EndInit ();
 			gv.ColorScheme = new ColorScheme ();
 			gv.ColorScheme = new ColorScheme ();
 			gv.Bounds = new Rect (0, 0, 50, 30);
 			gv.Bounds = new Rect (0, 0, 50, 30);
 
 
@@ -460,6 +468,7 @@ namespace Terminal.Gui.ViewTests {
 			GraphViewTests.InitFakeDriver ();
 			GraphViewTests.InitFakeDriver ();
 
 
 			var gv = new GraphView ();
 			var gv = new GraphView ();
+			gv.BeginInit (); gv.EndInit ();
 			gv.ColorScheme = new ColorScheme ();
 			gv.ColorScheme = new ColorScheme ();
 			gv.Bounds = new Rect (0, 0, 50, 30);
 			gv.Bounds = new Rect (0, 0, 50, 30);
 
 
@@ -683,6 +692,7 @@ namespace Terminal.Gui.ViewTests {
 			GraphViewTests.InitFakeDriver ();
 			GraphViewTests.InitFakeDriver ();
 
 
 			var gv = new GraphView ();
 			var gv = new GraphView ();
+			gv.BeginInit (); gv.EndInit ();
 			gv.ColorScheme = new ColorScheme ();
 			gv.ColorScheme = new ColorScheme ();
 
 
 			// y axis goes from 0.1 to 1 across 10 console rows
 			// y axis goes from 0.1 to 1 across 10 console rows
@@ -1601,5 +1611,5 @@ namespace Terminal.Gui.ViewTests {
 			Assert.Equal (6.6f, render.Value);
 			Assert.Equal (6.6f, render.Value);
 		}
 		}
 	}
 	}
-#endif
+
 }
 }

+ 3 - 3
UnitTests/Views/SpinnerViewTests.cs

@@ -3,7 +3,7 @@ using Terminal.Gui;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace UnitTests.Views {
+namespace Terminal.Gui.ViewsTests {
 	public class SpinnerViewTests {
 	public class SpinnerViewTests {
 
 
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
@@ -23,11 +23,11 @@ namespace UnitTests.Views {
 			Assert.NotEmpty (Application.MainLoop.timeouts);
 			Assert.NotEmpty (Application.MainLoop.timeouts);
 
 
 			//More calls to AutoSpin do not add more timeouts
 			//More calls to AutoSpin do not add more timeouts
-			Assert.Equal (1,Application.MainLoop.timeouts.Count);
+			Assert.Single (Application.MainLoop.timeouts);
 			view.AutoSpin ();
 			view.AutoSpin ();
 			view.AutoSpin ();
 			view.AutoSpin ();
 			view.AutoSpin ();
 			view.AutoSpin ();
-			Assert.Equal (1, Application.MainLoop.timeouts.Count);
+			Assert.Single (Application.MainLoop.timeouts);
 
 
 			// Dispose clears timeout
 			// Dispose clears timeout
 			Assert.NotEmpty (Application.MainLoop.timeouts);
 			Assert.NotEmpty (Application.MainLoop.timeouts);

+ 20 - 7
UnitTests/Views/TableViewTests.cs

@@ -12,7 +12,6 @@ using System.Reflection;
 namespace Terminal.Gui.ViewTests {
 namespace Terminal.Gui.ViewTests {
 
 
 	public class TableViewTests {
 	public class TableViewTests {
-#if false // BUGBUG: v2 - Table scenarios are working fine; Will fix these unit test later
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 
 		public TableViewTests (ITestOutputHelper output)
 		public TableViewTests (ITestOutputHelper output)
@@ -267,6 +266,8 @@ namespace Terminal.Gui.ViewTests {
 
 
 			// ensure that TableView has the input focus
 			// ensure that TableView has the input focus
 			Application.Top.Add (tableView);
 			Application.Top.Add (tableView);
+			Application.Begin (Application.Top);
+			
 			Application.Top.FocusFirst ();
 			Application.Top.FocusFirst ();
 			Assert.True (tableView.HasFocus);
 			Assert.True (tableView.HasFocus);
 
 
@@ -294,6 +295,7 @@ namespace Terminal.Gui.ViewTests {
 				MultiSelect = true,
 				MultiSelect = true,
 				Bounds = new Rect (0, 0, 10, 5)
 				Bounds = new Rect (0, 0, 10, 5)
 			};
 			};
+			tableView.BeginInit (); tableView.EndInit ();
 
 
 			tableView.SelectAll ();
 			tableView.SelectAll ();
 			Assert.Equal (16, tableView.GetAllSelectedCells ().Count ());
 			Assert.Equal (16, tableView.GetAllSelectedCells ().Count ());
@@ -321,6 +323,7 @@ namespace Terminal.Gui.ViewTests {
 				MultiSelect = true,
 				MultiSelect = true,
 				Bounds = new Rect (0, 0, 10, 5)
 				Bounds = new Rect (0, 0, 10, 5)
 			};
 			};
+			tableView.BeginInit (); tableView.EndInit ();
 
 
 			tableView.ChangeSelectionToEndOfTable (false);
 			tableView.ChangeSelectionToEndOfTable (false);
 
 
@@ -349,6 +352,7 @@ namespace Terminal.Gui.ViewTests {
 				MultiSelect = multiSelect,
 				MultiSelect = multiSelect,
 				Bounds = new Rect (0, 0, 10, 5)
 				Bounds = new Rect (0, 0, 10, 5)
 			};
 			};
+			tableView.BeginInit (); tableView.EndInit ();
 
 
 			tableView.SetSelection (1, 1, false);
 			tableView.SetSelection (1, 1, false);
 
 
@@ -365,6 +369,7 @@ namespace Terminal.Gui.ViewTests {
 				MultiSelect = true,
 				MultiSelect = true,
 				Bounds = new Rect (0, 0, 10, 5)
 				Bounds = new Rect (0, 0, 10, 5)
 			};
 			};
+			tableView.BeginInit (); tableView.EndInit ();
 
 
 			// move cursor to 1,1
 			// move cursor to 1,1
 			tableView.SetSelection (1, 1, false);
 			tableView.SetSelection (1, 1, false);
@@ -390,6 +395,7 @@ namespace Terminal.Gui.ViewTests {
 				FullRowSelect = true,
 				FullRowSelect = true,
 				Bounds = new Rect (0, 0, 10, 5)
 				Bounds = new Rect (0, 0, 10, 5)
 			};
 			};
+			tableView.BeginInit (); tableView.EndInit ();
 
 
 			// move cursor to 1,1
 			// move cursor to 1,1
 			tableView.SetSelection (1, 1, false);
 			tableView.SetSelection (1, 1, false);
@@ -416,6 +422,7 @@ namespace Terminal.Gui.ViewTests {
 				MultiSelect = true,
 				MultiSelect = true,
 				Bounds = new Rect (0, 0, 10, 5)
 				Bounds = new Rect (0, 0, 10, 5)
 			};
 			};
+			tableView.BeginInit (); tableView.EndInit ();
 
 
 			/*  
 			/*  
 				Sets up disconnected selections like:
 				Sets up disconnected selections like:
@@ -1002,7 +1009,7 @@ namespace Terminal.Gui.ViewTests {
 		private TableView SetUpMiniTable ()
 		private TableView SetUpMiniTable ()
 		{
 		{
 			var tv = new TableView ();
 			var tv = new TableView ();
-			tv.LayoutSubviews ();
+			tv.BeginInit (); tv.EndInit ();
 			tv.Bounds = new Rect (0, 0, 10, 4);
 			tv.Bounds = new Rect (0, 0, 10, 4);
 
 
 			var dt = new DataTable ();
 			var dt = new DataTable ();
@@ -1026,10 +1033,10 @@ namespace Terminal.Gui.ViewTests {
 		public void ScrollDown_OneLineAtATime ()
 		public void ScrollDown_OneLineAtATime ()
 		{
 		{
 			var tableView = new TableView ();
 			var tableView = new TableView ();
+			tableView.BeginInit (); tableView.EndInit ();
 
 
 			// Set big table
 			// Set big table
 			tableView.Table = BuildTable (25, 50);
 			tableView.Table = BuildTable (25, 50);
-			tableView.LayoutSubviews ();
 
 
 			// 1 header + 4 rows visible
 			// 1 header + 4 rows visible
 			tableView.Bounds = new Rect (0, 0, 25, 5);
 			tableView.Bounds = new Rect (0, 0, 25, 5);
@@ -1054,6 +1061,8 @@ namespace Terminal.Gui.ViewTests {
 			GraphViewTests.InitFakeDriver ();
 			GraphViewTests.InitFakeDriver ();
 
 
 			var tableView = new TableView ();
 			var tableView = new TableView ();
+			tableView.BeginInit (); tableView.EndInit ();
+
 			tableView.ColorScheme = Colors.TopLevel;
 			tableView.ColorScheme = Colors.TopLevel;
 			tableView.LayoutSubviews ();
 			tableView.LayoutSubviews ();
 
 
@@ -1120,7 +1129,7 @@ namespace Terminal.Gui.ViewTests {
 			GraphViewTests.InitFakeDriver ();
 			GraphViewTests.InitFakeDriver ();
 
 
 			var tableView = new TableView ();
 			var tableView = new TableView ();
-			tableView.LayoutSubviews ();
+			tableView.BeginInit (); tableView.EndInit ();
 			tableView.ColorScheme = Colors.TopLevel;
 			tableView.ColorScheme = Colors.TopLevel;
 
 
 			// 3 columns are visibile
 			// 3 columns are visibile
@@ -1183,7 +1192,8 @@ namespace Terminal.Gui.ViewTests {
 		private TableView GetABCDEFTableView (out DataTable dt)
 		private TableView GetABCDEFTableView (out DataTable dt)
 		{
 		{
 			var tableView = new TableView ();
 			var tableView = new TableView ();
-			tableView.LayoutSubviews ();
+			tableView.BeginInit (); tableView.EndInit ();
+			
 			tableView.ColorScheme = Colors.TopLevel;
 			tableView.ColorScheme = Colors.TopLevel;
 
 
 			// 3 columns are visible
 			// 3 columns are visible
@@ -1742,7 +1752,8 @@ namespace Terminal.Gui.ViewTests {
 			GraphViewTests.InitFakeDriver ();
 			GraphViewTests.InitFakeDriver ();
 
 
 			var tableView = new TableView ();
 			var tableView = new TableView ();
-			tableView.LayoutSubviews ();
+			tableView.BeginInit (); tableView.EndInit ();
+			
 			tableView.ColorScheme = Colors.TopLevel;
 			tableView.ColorScheme = Colors.TopLevel;
 
 
 			// 25 characters can be printed into table
 			// 25 characters can be printed into table
@@ -1884,6 +1895,8 @@ namespace Terminal.Gui.ViewTests {
 			GraphViewTests.InitFakeDriver ();
 			GraphViewTests.InitFakeDriver ();
 
 
 			var tableView = new TableView ();
 			var tableView = new TableView ();
+			tableView.BeginInit (); tableView.EndInit ();
+
 			tableView.ColorScheme = Colors.TopLevel;
 			tableView.ColorScheme = Colors.TopLevel;
 
 
 			// 3 columns are visibile
 			// 3 columns are visibile
@@ -1987,6 +2000,7 @@ namespace Terminal.Gui.ViewTests {
 		public void Test_ScreenToCell ()
 		public void Test_ScreenToCell ()
 		{
 		{
 			var tableView = GetTwoRowSixColumnTable ();
 			var tableView = GetTwoRowSixColumnTable ();
+			tableView.BeginInit (); tableView.EndInit ();
 			tableView.LayoutSubviews ();
 			tableView.LayoutSubviews ();
 
 
 			tableView.Redraw (tableView.Bounds);
 			tableView.Redraw (tableView.Bounds);
@@ -2162,6 +2176,5 @@ namespace Terminal.Gui.ViewTests {
 			tableView.Table = dt;
 			tableView.Table = dt;
 			return tableView;
 			return tableView;
 		}
 		}
-#endif 
 	}
 	}
 }
 }