|
@@ -20,6 +20,10 @@ namespace Terminal.Gui;
|
|
/// no other <see cref="View"/> processes the key, the <see cref="Button"/>'s <see cref="View.Accept"/> event will
|
|
/// no other <see cref="View"/> processes the key, the <see cref="Button"/>'s <see cref="View.Accept"/> event will
|
|
/// be fired.
|
|
/// be fired.
|
|
/// </para>
|
|
/// </para>
|
|
|
|
+/// <para>
|
|
|
|
+/// Set <see cref="View.WantContinuousButtonPressed"/> to <see langword="true"/> to have the <see cref="View.Accept"/> event
|
|
|
|
+/// invoked repeatedly while the button is pressed.
|
|
|
|
+/// </para>
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public class Button : View
|
|
public class Button : View
|
|
{
|
|
{
|
|
@@ -46,6 +50,7 @@ public class Button : View
|
|
|
|
|
|
CanFocus = true;
|
|
CanFocus = true;
|
|
AutoSize = true;
|
|
AutoSize = true;
|
|
|
|
+ InvertColorsOnPress = true;
|
|
|
|
|
|
// Override default behavior of View
|
|
// Override default behavior of View
|
|
AddCommand (Command.HotKey, () =>
|
|
AddCommand (Command.HotKey, () =>
|
|
@@ -59,72 +64,7 @@ public class Button : View
|
|
|
|
|
|
TitleChanged += Button_TitleChanged;
|
|
TitleChanged += Button_TitleChanged;
|
|
MouseClick += Button_MouseClick;
|
|
MouseClick += Button_MouseClick;
|
|
- InvertColorsOnPress = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- [CanBeNull]
|
|
|
|
- private ColorScheme _savedColorScheme;
|
|
|
|
-
|
|
|
|
- private void Button_MouseEvent (object sender, MouseEventEventArgs e)
|
|
|
|
- {
|
|
|
|
- // Default behavior is to invoke Accept (via HotKey) on clicked.
|
|
|
|
- if (!WantContinuousButtonPressed &&
|
|
|
|
- Application.MouseGrabView != this &&
|
|
|
|
- e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked))
|
|
|
|
- {
|
|
|
|
- e.Handled = InvokeCommand (Command.HotKey) == true;
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed))
|
|
|
|
- {
|
|
|
|
- // If WantContinuousButtonPressed is true, and this is not the first pressed event,
|
|
|
|
- // invoke Accept (via HotKey)
|
|
|
|
- if (WantContinuousButtonPressed && Application.MouseGrabView == this)
|
|
|
|
- {
|
|
|
|
- e.Handled = InvokeCommand (Command.HotKey) == true;
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // The first time we get pressed event, grab the mouse and invert the colors
|
|
|
|
- if (Application.MouseGrabView != this)
|
|
|
|
- {
|
|
|
|
- Application.GrabMouse (this);
|
|
|
|
- _savedColorScheme = ColorScheme;
|
|
|
|
- var cs = new ColorScheme (new Attribute (ColorScheme.Normal.Background, ColorScheme.Normal.Foreground));
|
|
|
|
- ColorScheme = cs;
|
|
|
|
-
|
|
|
|
- // Set the focus, but don't invoke Accept
|
|
|
|
- SetFocus ();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Released))
|
|
|
|
- {
|
|
|
|
- // When the mouse is released, if WantContinuousButtonPressed is set, invoke Accept one last time.
|
|
|
|
- if (WantContinuousButtonPressed)
|
|
|
|
- {
|
|
|
|
- e.Handled = InvokeCommand (Command.HotKey) == true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Application.MouseGrabView == this)
|
|
|
|
- {
|
|
|
|
- Application.UngrabMouse ();
|
|
|
|
- if (_savedColorScheme is { })
|
|
|
|
- {
|
|
|
|
- ColorScheme = _savedColorScheme;
|
|
|
|
- _savedColorScheme = null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <inheritdoc />
|
|
|
|
- protected internal override bool OnMouseLeave (MouseEvent e)
|
|
|
|
- {
|
|
|
|
- return base.OnMouseLeave (e);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
private void Button_MouseClick (object sender, MouseEventEventArgs e)
|
|
private void Button_MouseClick (object sender, MouseEventEventArgs e)
|
|
{
|
|
{
|
|
e.Handled = InvokeCommand (Command.HotKey) == true;
|
|
e.Handled = InvokeCommand (Command.HotKey) == true;
|