瀏覽代碼

Fixes #1984. Setting Label.Visible to false does not hide the Label (#1985)

BDisp 2 年之前
父節點
當前提交
9505987d40
共有 2 個文件被更改,包括 34 次插入2 次删除
  1. 5 2
      Terminal.Gui/Core/View.cs
  2. 29 0
      UnitTests/ViewTests.cs

+ 5 - 2
Terminal.Gui/Core/View.cs

@@ -2562,8 +2562,11 @@ namespace Terminal.Gui {
 			set {
 				if (base.Visible != value) {
 					base.Visible = value;
-					if (!value && HasFocus) {
-						SetHasFocus (false, this);
+					if (!value) {
+						if (HasFocus) {
+							SetHasFocus (false, this);
+						}
+						Clear ();
 					}
 					OnVisibleChanged ();
 					SetNeedsDisplay ();

+ 29 - 0
UnitTests/ViewTests.cs

@@ -3803,5 +3803,34 @@ e
 ", output);
 		}
 
+		[Fact, AutoInitShutdown]
+		public void Visible_Clear_The_View_Output ()
+		{
+			var label = new Label ("Testing visibility.");
+			var win = new Window ();
+			win.Add (label);
+			var top = Application.Top;
+			top.Add (win);
+			Application.Begin (top);
+
+			Assert.True (label.Visible);
+			((FakeDriver)Application.Driver).SetBufferSize (30, 5);
+			GraphViewTests.AssertDriverContentsWithFrameAre (@"
+┌────────────────────────────┐
+│Testing visibility.         │
+│                            │
+│                            │
+└────────────────────────────┘
+", output);
+
+			label.Visible = false;
+			GraphViewTests.AssertDriverContentsWithFrameAre (@"
+┌────────────────────────────┐
+│                            │
+│                            │
+│                            │
+└────────────────────────────┘
+", output);
+		}
 	}
 }