From 7866e800cc966ec5d06b6728f02817aba068a0b2 Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 15 Oct 2024 07:50:50 -0600 Subject: [PATCH] MouseEventArgs cleanup --- Terminal.Gui/Application/Application.Mouse.cs | 8 ++++---- Terminal.Gui/Input/MouseEventArgs.cs | 7 ++++--- Terminal.Gui/Views/TabMouseEventArgs.cs | 2 +- docfx/docs/migratingfromv1.md | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Terminal.Gui/Application/Application.Mouse.cs b/Terminal.Gui/Application/Application.Mouse.cs index 47714c03f..7bf67f809 100644 --- a/Terminal.Gui/Application/Application.Mouse.cs +++ b/Terminal.Gui/Application/Application.Mouse.cs @@ -255,17 +255,17 @@ public static partial class Application // Mouse handling } /// - /// Raised when a mouse event occurs. Can be cancelled by setting to . + /// Raised when a mouse event occurs. Can be cancelled by setting to . /// /// /// - /// coordinates are screen-relative. + /// coordinates are screen-relative. /// /// - /// will be the deepest view under the under the mouse. + /// will be the deepest view under the under the mouse. /// /// - /// coordinates are view-relative. + /// coordinates are view-relative. Only valid if is set. /// /// /// Use this evento to handle mouse events at the application level, before View-specific handling. diff --git a/Terminal.Gui/Input/MouseEventArgs.cs b/Terminal.Gui/Input/MouseEventArgs.cs index ce1b27495..24c8cbfda 100644 --- a/Terminal.Gui/Input/MouseEventArgs.cs +++ b/Terminal.Gui/Input/MouseEventArgs.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +#nullable enable +using System.ComponentModel; namespace Terminal.Gui; @@ -20,12 +21,12 @@ public class MouseEventArgs : HandledEventArgs public Point ScreenPosition { get; set; } /// The deepest View who's contains . - public View View { get; set; } + public View? View { get; set; } /// The position of the mouse in 's Viewport-relative coordinates. Only valid if is set. public Point Position { get; set; } /// Returns a that represents the current . /// A that represents the current . - public override string ToString () { return $"({ScreenPosition}):{Flags}:{View.Id}:{Position}"; } + public override string ToString () { return $"({ScreenPosition}):{Flags}:{View?.Id}:{Position}"; } } diff --git a/Terminal.Gui/Views/TabMouseEventArgs.cs b/Terminal.Gui/Views/TabMouseEventArgs.cs index 707f68211..22a23ad01 100644 --- a/Terminal.Gui/Views/TabMouseEventArgs.cs +++ b/Terminal.Gui/Views/TabMouseEventArgs.cs @@ -13,7 +13,7 @@ public class TabMouseEventArgs : EventArgs } /// - /// Gets the actual mouse event. Use to cancel this event and perform custom + /// Gets the actual mouse event. Use to cancel this event and perform custom /// behavior (e.g. show a context menu). /// public MouseEventArgs MouseEvent { get; } diff --git a/docfx/docs/migratingfromv1.md b/docfx/docs/migratingfromv1.md index 3318aa448..2239bd7ff 100644 --- a/docfx/docs/migratingfromv1.md +++ b/docfx/docs/migratingfromv1.md @@ -196,7 +196,7 @@ In v1, the `Command` enum had duplicate entries and inconsistent naming. In v2 i The API for mouse input is now internally consistent and easier to use. -* The @Terminal.Gui.MouseEvent class replaces `MouseEventEventArgs`. +* The @Terminal.Gui.MouseEventArgs class replaces `MouseEventEventArgs`. * More granular APIs are provided to ease handling specific mouse actions. See [Mouse API](mouse.md). * Views can use the @Terminal.Gui.View.Highlight event to have the view be visibly highlighted on various mouse events. * Views can set `View.WantContinousButtonPresses = true` to have their @Terminal.Gui.Command.Accept command be invoked repeatedly as the user holds a mouse button down on the view. @@ -213,7 +213,7 @@ The API for mouse input is now internally consistent and easier to use. ```diff - Application.RootMouseEvent(KeyEvent arg) -+ Application.MouseEvent(object? sender, MouseEvent mouseEvent) ++ Application.MouseEvent(object? sender, MouseEventArgs mouseEvent) ``` ## Navigation - `Cursor`, `Focus`, `TabStop` etc...