mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Updated Mouse scenario with filter
This commit is contained in:
@@ -1712,7 +1712,7 @@ internal class WindowsDriver : ConsoleDriver
|
||||
{
|
||||
// When a user presses-and-holds, start generating pressed events every `startDelay`
|
||||
// After `iterationsUntilFast` iterations, speed them up to `fastDelay` ms
|
||||
const int startDelay = 500;
|
||||
const int startDelay = 50;
|
||||
const int iterationsUntilFast = 4;
|
||||
const int fastDelay = 50;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public partial class View
|
||||
/// <summary>Gets or sets whether the <see cref="View"/> wants mouse position reports.</summary>
|
||||
/// <value><see langword="true"/> if mouse position reports are wanted; otherwise, <see langword="false"/>.</value>
|
||||
public virtual bool WantMousePositionReports { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called when the mouse enters the View's <see cref="Bounds"/>. The view will now receive mouse events until the
|
||||
/// mouse leaves
|
||||
@@ -104,16 +104,22 @@ public partial class View
|
||||
var args = new MouseEventEventArgs (mouseEvent);
|
||||
|
||||
// Default behavior is to invoke Accept (via HotKey) on clicked.
|
||||
if (!WantContinuousButtonPressed
|
||||
&& Application.MouseGrabView != this
|
||||
if (
|
||||
!HighlightOnPress
|
||||
&& Application.MouseGrabView is null
|
||||
&& (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button2Clicked)
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button4Clicked)))
|
||||
{
|
||||
{
|
||||
return OnMouseClick (args);
|
||||
}
|
||||
|
||||
if (!HighlightOnPress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button2Pressed)
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button3Pressed)
|
||||
@@ -130,10 +136,10 @@ public partial class View
|
||||
if (Application.MouseGrabView != this)
|
||||
{
|
||||
Application.GrabMouse (this);
|
||||
_savedColorScheme = ColorScheme;
|
||||
|
||||
if (HighlightOnPress && ColorScheme is { })
|
||||
{
|
||||
_savedColorScheme = ColorScheme;
|
||||
if (CanFocus)
|
||||
{
|
||||
// TODO: Make the inverted color configurable
|
||||
@@ -158,8 +164,8 @@ public partial class View
|
||||
// Set the focus, but don't invoke Accept
|
||||
SetFocus ();
|
||||
}
|
||||
args.Handled = true;
|
||||
}
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Released)
|
||||
@@ -167,14 +173,15 @@ public partial class View
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button3Released)
|
||||
|| mouseEvent.Flags.HasFlag (MouseFlags.Button4Released))
|
||||
{
|
||||
// When the mouse is released, if WantContinuousButtonPressed is set, invoke Accept one last time.
|
||||
if (WantContinuousButtonPressed)
|
||||
{
|
||||
OnMouseClick (args);
|
||||
}
|
||||
|
||||
if (Application.MouseGrabView == this)
|
||||
{
|
||||
// When the mouse is released, if WantContinuousButtonPressed is set, invoke Accept one last time.
|
||||
//if (WantContinuousButtonPressed)
|
||||
{
|
||||
OnMouseClick (args);
|
||||
}
|
||||
|
||||
Application.UngrabMouse ();
|
||||
|
||||
if (HighlightOnPress && _savedColorScheme is { })
|
||||
@@ -182,8 +189,8 @@ public partial class View
|
||||
ColorScheme = _savedColorScheme;
|
||||
_savedColorScheme = null;
|
||||
}
|
||||
args.Handled = true;
|
||||
}
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
if (args.Handled != true)
|
||||
@@ -209,6 +216,7 @@ public partial class View
|
||||
/// <see cref="MouseEvent.Flags"/> to see which button was clicked.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
||||
protected bool OnMouseClick (MouseEventEventArgs args)
|
||||
{
|
||||
if (!Enabled)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.Linq;
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace UICatalog.Scenarios;
|
||||
@@ -14,19 +17,53 @@ public class Mouse : Scenario
|
||||
Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
|
||||
};
|
||||
|
||||
|
||||
var filterSlider = new Slider<MouseFlags> ()
|
||||
{
|
||||
Title = "_Filter",
|
||||
X = 0,
|
||||
Y = 0,
|
||||
AutoSize = true,
|
||||
BorderStyle = LineStyle.Single,
|
||||
Type = SliderType.Multiple,
|
||||
Orientation = Orientation.Vertical,
|
||||
};
|
||||
filterSlider.Options = Enum.GetValues (typeof (MouseFlags))
|
||||
.Cast<MouseFlags> ()
|
||||
.Where (value => !value.ToString ().Contains ("None") &&
|
||||
!value.ToString().Contains("All"))
|
||||
.Select (value => new SliderOption<MouseFlags>
|
||||
{
|
||||
Legend = value.ToString (),
|
||||
Data = value,
|
||||
})
|
||||
.ToList ();
|
||||
for (int i = 0; i < filterSlider.Options.Count; i++)
|
||||
{
|
||||
filterSlider.SetOption (i);
|
||||
}
|
||||
win.Add (filterSlider);
|
||||
|
||||
var clearButton = new Button ()
|
||||
{
|
||||
Title = "_Clear Logs",
|
||||
X = 1,
|
||||
Y = Pos.Bottom (filterSlider) + 1,
|
||||
};
|
||||
win.Add (clearButton);
|
||||
Label ml;
|
||||
var count = 0;
|
||||
ml = new Label { X = 1, Y = 1, Text = "Mouse: " };
|
||||
ml = new Label { X = Pos.Right(filterSlider), Y = 0, Text = "Mouse: " };
|
||||
|
||||
win.Add (ml);
|
||||
|
||||
CheckBox cbWantContinuousPresses = new CheckBox ()
|
||||
{
|
||||
X = 0,
|
||||
Y = Pos.Bottom(ml) + 1,
|
||||
X = Pos.Right (filterSlider),
|
||||
Y = Pos.Bottom (ml) + 1,
|
||||
Title = "_Want Continuous Button Presses",
|
||||
};
|
||||
cbWantContinuousPresses.Toggled += (s,e) =>
|
||||
cbWantContinuousPresses.Toggled += (s, e) =>
|
||||
{
|
||||
win.WantContinuousButtonPressed = !win.WantContinuousButtonPressed;
|
||||
};
|
||||
@@ -35,10 +72,10 @@ public class Mouse : Scenario
|
||||
|
||||
var demo = new MouseDemo ()
|
||||
{
|
||||
X = 0,
|
||||
X = Pos.Right (filterSlider),
|
||||
Y = Pos.Bottom (cbWantContinuousPresses) + 1,
|
||||
Width = 20,
|
||||
Height = 5,
|
||||
Height = 3,
|
||||
Text = "Enter/Leave Demo",
|
||||
TextAlignment = TextAlignment.Centered,
|
||||
VerticalTextAlignment = VerticalTextAlignment.Middle,
|
||||
@@ -49,15 +86,16 @@ public class Mouse : Scenario
|
||||
var label = new Label ()
|
||||
{
|
||||
Text = "_App Events:",
|
||||
X = 0,
|
||||
X = Pos.Right (filterSlider),
|
||||
Y = Pos.Bottom (demo),
|
||||
};
|
||||
|
||||
List<string> appLogList = new ();
|
||||
var appLog = new ListView
|
||||
{
|
||||
X = Pos.Left (label),
|
||||
Y = Pos.Bottom (label),
|
||||
Width = Dim.Percent(49),
|
||||
Width = 50,
|
||||
Height = Dim.Fill (),
|
||||
ColorScheme = Colors.ColorSchemes ["TopLevel"],
|
||||
Source = new ListWrapper (appLogList)
|
||||
@@ -66,22 +104,26 @@ public class Mouse : Scenario
|
||||
|
||||
Application.MouseEvent += (sender, a) =>
|
||||
{
|
||||
ml.Text = $"MouseEvent: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count}";
|
||||
appLogList.Add ($"({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}");
|
||||
appLog.MoveDown ();
|
||||
var i = filterSlider.Options.FindIndex (o => o.Data == a.MouseEvent.Flags);
|
||||
if (filterSlider.GetSetOptions().Contains(i))
|
||||
{
|
||||
ml.Text = $"MouseEvent: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count}";
|
||||
appLogList.Add ($"({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}");
|
||||
appLog.MoveDown ();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
label = new Label ()
|
||||
{
|
||||
Text = "_Window Events:",
|
||||
X = Pos.Percent(50),
|
||||
Y = Pos.Bottom (demo),
|
||||
X = Pos.Right (appLog)+1,
|
||||
Y = Pos.Top (label),
|
||||
};
|
||||
List<string> winLogList = new ();
|
||||
var winLog = new ListView
|
||||
{
|
||||
X = Pos.Left(label),
|
||||
X = Pos.Left (label),
|
||||
Y = Pos.Bottom (label),
|
||||
Width = Dim.Percent (50),
|
||||
Height = Dim.Fill (),
|
||||
@@ -89,6 +131,13 @@ public class Mouse : Scenario
|
||||
Source = new ListWrapper (winLogList)
|
||||
};
|
||||
win.Add (label, winLog);
|
||||
|
||||
clearButton.Accept += (s, e) =>
|
||||
{
|
||||
appLogList.Clear ();
|
||||
winLogList.Clear ();
|
||||
};
|
||||
|
||||
win.MouseEvent += (sender, a) =>
|
||||
{
|
||||
winLogList.Add ($"MouseEvent: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}");
|
||||
|
||||
Reference in New Issue
Block a user