mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 09:47:58 +01:00
Merge pull request #807 from BDisp/mouse-button-click
Fixes #806. Button now support clicks.
This commit is contained in:
@@ -203,29 +203,19 @@ namespace Terminal.Gui {
|
||||
/// </remarks>
|
||||
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 false;
|
||||
|
||||
@@ -69,6 +69,11 @@ namespace UICatalog {
|
||||
Height = Dim.Fill (3),
|
||||
ColorScheme = Colors.TopLevel
|
||||
};
|
||||
embedded3.Add (new Button (2, 2, "click me") {
|
||||
Clicked = () => {
|
||||
MessageBox.Query (10, 5, "Test", "test message", "Ok");
|
||||
}
|
||||
});
|
||||
embedded2.Add (embedded3);
|
||||
|
||||
scrollView.Add (embedded1);
|
||||
|
||||
Reference in New Issue
Block a user