Browse Source

Merge pull request #807 from BDisp/mouse-button-click

Fixes #806. Button now support clicks.
Charlie Kindel 5 years ago
parent
commit
84b8938d3b
2 changed files with 15 additions and 20 deletions
  1. 10 20
      Terminal.Gui/Views/Button.cs
  2. 5 0
      UICatalog/Scenarios/Clipping.cs

+ 10 - 20
Terminal.Gui/Views/Button.cs

@@ -203,29 +203,19 @@ namespace Terminal.Gui {
 		/// </remarks>
 		/// </remarks>
 		public Action Clicked;
 		public Action Clicked;
 
 
-		/// <summary>
-		/// Method invoked when a mouse event is generated
-		/// </summary>
-		/// <param name="mouseEvent"></param>
-		/// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
-		public override bool OnMouseEvent (MouseEvent mouseEvent)
+		///<inheritdoc/>
+		public override bool MouseEvent (MouseEvent me)
 		{
 		{
-			MouseEventArgs args = new MouseEventArgs (mouseEvent);
-			MouseClick?.Invoke (args);
-			if (args.Handled)
-				return true;
-			if (MouseEvent (mouseEvent))
-				return true;
-
-
-			if (mouseEvent.Flags == MouseFlags.Button1Clicked || mouseEvent.Flags == MouseFlags.Button1DoubleClicked ||
-				mouseEvent.Flags == MouseFlags.Button1TripleClicked) {
-				if (!HasFocus && SuperView != null) {
-					SuperView.SetFocus (this);
-					SetNeedsDisplay ();
+			if (me.Flags == MouseFlags.Button1Clicked || me.Flags == MouseFlags.Button1DoubleClicked ||
+				me.Flags == MouseFlags.Button1TripleClicked) {
+				if (CanFocus) {
+					if (!HasFocus) {
+						SuperView?.SetFocus (this);
+						SetNeedsDisplay ();
+					}
+					Clicked?.Invoke ();
 				}
 				}
 
 
-				Clicked?.Invoke ();
 				return true;
 				return true;
 			}
 			}
 			return false;
 			return false;

+ 5 - 0
UICatalog/Scenarios/Clipping.cs

@@ -69,6 +69,11 @@ namespace UICatalog {
 				Height = Dim.Fill (3),
 				Height = Dim.Fill (3),
 				ColorScheme = Colors.TopLevel
 				ColorScheme = Colors.TopLevel
 			};
 			};
+			embedded3.Add (new Button (2, 2, "click me") {
+				Clicked = () => {
+					MessageBox.Query (10, 5, "Test", "test message", "Ok");
+				}
+			});
 			embedded2.Add (embedded3);
 			embedded2.Add (embedded3);
 
 
 			scrollView.Add (embedded1);
 			scrollView.Add (embedded1);