Browse Source

Changed from Enum HeightSize to bool HeightAsBuffer.

BDisp 4 years ago
parent
commit
9b0ea4e992

+ 1 - 1
Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

@@ -20,7 +20,7 @@ namespace Terminal.Gui {
 		public override int Cols => Curses.Cols;
 		public override int Rows => Curses.Lines;
 		public override int Top => 0;
-		public override HeightSize HeightSize { get; set; }
+		public override bool HeightAsBuffer { get; set; }
 
 		// Current row, and current col, tracked by Move/AddRune only
 		int ccol, crow;

+ 1 - 1
Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs

@@ -20,7 +20,7 @@ namespace Terminal.Gui {
 		public override int Cols => cols;
 		public override int Rows => rows;
 		public override int Top => 0;
-		public override HeightSize HeightSize { get; set; }
+		public override bool HeightAsBuffer { get; set; }
 
 		// The format is rows, columns and 3 values on the last column: Rune, Attribute and Dirty Flag
 		int [,,] contents;

+ 10 - 17
Terminal.Gui/ConsoleDrivers/NetDriver.cs

@@ -18,7 +18,7 @@ namespace Terminal.Gui {
 		public override int Cols => cols;
 		public override int Rows => rows;
 		public override int Top => top;
-		public override HeightSize HeightSize { get; set; }
+		public override bool HeightAsBuffer { get; set; }
 
 		// The format is rows, columns and 3 values on the last column: Rune, Attribute and Dirty Flag
 		int [,,] contents;
@@ -149,8 +149,7 @@ namespace Terminal.Gui {
 
 		void ResizeScreen ()
 		{
-			switch (HeightSize) {
-			case HeightSize.WindowHeight:
+			if (!HeightAsBuffer) {
 				if (Console.WindowHeight > 0) {
 					// Can raise an exception while is still resizing.
 					try {
@@ -174,8 +173,7 @@ namespace Terminal.Gui {
 						return;
 					}
 				}
-				break;
-			case HeightSize.BufferHeight:
+			} else {
 				if (isWinPlatform && Console.WindowHeight > 0) {
 					// Can raise an exception while is still resizing.
 					try {
@@ -189,8 +187,8 @@ namespace Terminal.Gui {
 					Console.Out.Write ($"\x1b[{top};{Console.WindowLeft}" +
 						$";{Rows};{Cols}w");
 				}
-				break;
 			}
+
 			Clip = new Rect (0, 0, Cols, Rows);
 
 			contents = new int [Rows, Cols, 3];
@@ -240,8 +238,8 @@ namespace Terminal.Gui {
 		public override void UpdateScreen ()
 		{
 			if (winChanging || Console.WindowHeight == 0
-				|| (HeightSize == HeightSize.WindowHeight && Rows != Console.WindowHeight)
-				|| (HeightSize == HeightSize.BufferHeight && Rows != Console.BufferHeight)) {
+				|| (!HeightAsBuffer && Rows != Console.WindowHeight)
+				|| (HeightAsBuffer && Rows != Console.BufferHeight)) {
 				return;
 			}
 
@@ -467,16 +465,13 @@ namespace Terminal.Gui {
 				winChanging = true;
 				const int Min_WindowWidth = 14;
 				Size size = new Size ();
-				switch (HeightSize) {
-				case HeightSize.WindowHeight:
+				if (!HeightAsBuffer) {
 					size = new Size (Math.Max (Min_WindowWidth, Console.WindowWidth),
 						Console.WindowHeight);
 					top = 0;
-					break;
-				case HeightSize.BufferHeight:
+				} else {
 					size = new Size (Console.BufferWidth, Console.BufferHeight);
 					top = e;
-					break;
 				}
 				cols = size.Width;
 				rows = size.Height;
@@ -579,13 +574,11 @@ namespace Terminal.Gui {
 		void WaitWinChange ()
 		{
 			while (true) {
-				switch (consoleDriver.HeightSize) {
-				case HeightSize.WindowHeight:
+				if (!consoleDriver.HeightAsBuffer) {
 					if (Console.WindowWidth != consoleDriver.Cols || Console.WindowHeight != consoleDriver.Rows) {
 						return;
 					}
-					break;
-				case HeightSize.BufferHeight:
+				} else {
 					if (Console.BufferWidth != consoleDriver.Cols || Console.BufferHeight != consoleDriver.Rows
 						|| Console.WindowTop != consoleDriver.Top
 						|| Console.WindowHeight != lastWindowHeight) {

+ 3 - 5
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -523,7 +523,7 @@ namespace Terminal.Gui {
 		public override int Cols => cols;
 		public override int Rows => rows;
 		public override int Top => top;
-		public override HeightSize HeightSize { get; set; }
+		public override bool HeightAsBuffer { get; set; }
 
 		public WindowsConsole WinConsole {
 			get => winConsole;
@@ -1334,14 +1334,12 @@ namespace Terminal.Gui {
 		void WaitWinChange ()
 		{
 			while (true) {
-				switch (consoleDriver.HeightSize) {
-				case HeightSize.WindowHeight:
+				if (!consoleDriver.HeightAsBuffer) {
 					if (Console.WindowWidth != consoleDriver.Cols || Console.WindowHeight != consoleDriver.Rows
 						|| Console.WindowTop != consoleDriver.Top) {    // Top only working on Windows.
 						return;
 					}
-					break;
-				case HeightSize.BufferHeight:
+				} else {
 					if (Console.BufferWidth != consoleDriver.Cols || Console.BufferHeight != consoleDriver.Rows) {
 						return;
 					}

+ 5 - 5
Terminal.Gui/Core/Application.cs

@@ -79,21 +79,21 @@ namespace Terminal.Gui {
 		public static View CurrentView { get; set; }
 
 		/// <summary>
-		/// The current <see cref="Terminal.Gui.HeightSize"/> used in the terminal.
+		/// The current <see cref="ConsoleDriver.HeightAsBuffer"/> used in the terminal.
 		/// </summary>
-		public static HeightSize HeightSize {
+		public static bool HeightAsBuffer {
 			get {
 				if (Driver == null) {
 					throw new ArgumentNullException ("The driver must be initialized first.");
 				}
-				return Driver.HeightSize;
+				return Driver.HeightAsBuffer;
 			}
 			set {
 				if (Driver == null) {
 					throw new ArgumentNullException ("The driver must be initialized first.");
 				}
-				if (Driver.HeightSize != value) {
-					Driver.HeightSize = value;
+				if (Driver.HeightAsBuffer != value) {
+					Driver.HeightAsBuffer = value;
 					Driver.Refresh ();
 				}
 			}

+ 3 - 16
Terminal.Gui/Core/ConsoleDriver.cs

@@ -458,20 +458,6 @@ namespace Terminal.Gui {
 		public static Dictionary<string, ColorScheme> ColorSchemes { get; }
 	}
 
-	/// <summary>
-	/// The visible height should be used on the window.
-	/// </summary>
-	public enum HeightSize {
-		/// <summary>
-		/// Only window height will be visible not allowing scroll.
-		/// </summary>
-		WindowHeight,
-		/// <summary>
-		/// All buffer height will be visible allowing scroll.
-		/// </summary>
-		BufferHeight
-	}
-
 	///// <summary>
 	///// Special characters that can be drawn with 
 	///// </summary>
@@ -561,9 +547,10 @@ namespace Terminal.Gui {
 		public abstract int Top { get; }
 
 		/// <summary>
-		/// The current <see cref="HeightSize"/> used in the terminal.
+		/// If false height is measured by the window height and thus no scrolling.
+		/// If true then height is measured by the buffer height, enabling scrolling.
 		/// </summary>
-		public abstract HeightSize HeightSize { get; set; }
+		public abstract bool HeightAsBuffer { get; set; }
 
 		/// <summary>
 		/// Initializes the driver