Browse Source

Merge pull request #492 from tig/fix_ensurevisiblebounds_crash

Fix ensurevisiblebounds crash
Charlie Kindel 5 years ago
parent
commit
f4d345af02

+ 2 - 2
Terminal.Gui/Core.cs

@@ -1643,13 +1643,13 @@ namespace Terminal.Gui {
 			nx = Math.Max (x, 0);
 			nx = nx + top.Frame.Width > Driver.Cols ? Math.Max (Driver.Cols - top.Frame.Width, 0) : nx;
 			bool m, s;
-			if (SuperView == null)
+			if (SuperView == null || SuperView.GetType() != typeof(Toplevel))
 				m = Application.Top.MenuBar != null;
 			else
 				m = ((Toplevel)SuperView).MenuBar != null;
 			int l = m ? 1 : 0;
 			ny = Math.Max (y, l);
-			if (SuperView == null)
+			if (SuperView == null || SuperView.GetType() != typeof(Toplevel))
 				s = Application.Top.StatusBar != null;
 			else
 				s = ((Toplevel)SuperView).StatusBar != null;

+ 0 - 2
Terminal.Gui/Drivers/WindowsDriver.cs

@@ -677,8 +677,6 @@ namespace Terminal.Gui {
 						keyHandler (new KeyEvent (map));
 						keyDownHandler (new KeyEvent (map));
 					} else {
-						// Key Up - Fire KeyDown Event and KeyStroke (ProcessKey) Event
-						keyHandler (new KeyEvent (map));
 						keyUpHandler (new KeyEvent (map));
 					}
 				}

+ 30 - 0
UICatalog/Scenarios/ComputedLayout.cs

@@ -98,6 +98,36 @@ namespace UICatalog {
 				Y = Pos.At(10)
 			};
 			Win.Add (absoluteButton);
+
+			// Centering multiple controls horizontally. 
+			// This is intentionally convoluted to illustrate potential bugs.
+			var bottomLabel = new Label ("This should be the last line (Bug #xxx).") {
+				TextAlignment = Terminal.Gui.TextAlignment.Centered,
+				ColorScheme = Colors.TopLevel,
+				Width = Dim.Fill (),
+				X = Pos.Center (),
+				Y = Pos.Bottom (Win) - 3  // BUGBUG: -1 should be just above border; but it has to be -3
+			};
+
+			var centerButton = new Button ("Center") {
+				X = Pos.Center (),
+				Y = Pos.Top(bottomLabel) - 1
+			};
+			var leftButton = new Button ("Left") {
+				Y = Pos.Top (bottomLabel) - 1
+			};
+			var rightButton = new Button ("Right") {
+				Y = Pos.Top (bottomLabel) - 1
+			};
+
+			leftButton.X = Pos.Left (centerButton) - leftButton.Frame.Width - 5;
+			rightButton.X = Pos.Right (centerButton) + 5;
+
+			Win.Add (bottomLabel);
+			Win.Add (leftButton);
+			Win.Add (centerButton);
+			Win.Add (rightButton);
+
 		}
 
 		public override void Run ()