Skip to content

Commit

Permalink
Merge pull request #3461 from tig/v2_3460-xxxToxxx-Consistency
Browse files Browse the repository at this point in the history
Fixes #3460.  `xxxtoxxx` consistency
  • Loading branch information
tig committed May 11, 2024
2 parents 2dbfbfc + 3891b23 commit 6c6dec1
Show file tree
Hide file tree
Showing 81 changed files with 662 additions and 681 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.9.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.1.0">
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.1" PrivateAssets="all" />
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.12.1" PrivateAssets="all" />
<PackageReference Include="Roslynator.CSharp" Version="4.12.1" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.2" PrivateAssets="all" />
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.12.2" PrivateAssets="all" />
<PackageReference Include="Roslynator.CSharp" Version="4.12.2" PrivateAssets="all" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" PrivateAssets="all" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" PrivateAssets="all" />
<PackageReference Include="System.Runtime.Numerics" Version="4.3.0" PrivateAssets="all" />
Expand Down
2 changes: 1 addition & 1 deletion ReactiveExample/ReactiveExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
<PackageReference Include="ReactiveUI" Version="19.6.1" />
<PackageReference Include="ReactiveUI" Version="20.0.1" />
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.3.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
Expand Down
61 changes: 27 additions & 34 deletions Terminal.Gui/Application.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Reflection.Metadata.Ecma335;
using System.Text.Json.Serialization;
using static Unix.Terminal.Curses;

namespace Terminal.Gui;

Expand Down Expand Up @@ -972,7 +969,7 @@ public static void RunIteration (ref RunState state, ref bool firstIteration)

if (PositionCursor (state.Toplevel))
{
Driver.UpdateCursor();
Driver.UpdateCursor ();
}

// else
Expand Down Expand Up @@ -1231,10 +1228,10 @@ public static void End (RunState runState)
/// <value>The current.</value>
public static Toplevel Current { get; private set; }

private static void EnsureModalOrVisibleAlwaysOnTop (Toplevel Toplevel)
private static void EnsureModalOrVisibleAlwaysOnTop (Toplevel topLevel)
{
if (!Toplevel.Running
|| (Toplevel == Current && Toplevel.Visible)
if (!topLevel.Running
|| (topLevel == Current && topLevel.Visible)
|| OverlappedTop == null
|| _topLevels.Peek ().Modal)
{
Expand All @@ -1251,24 +1248,24 @@ private static void EnsureModalOrVisibleAlwaysOnTop (Toplevel Toplevel)
}
}

if (!Toplevel.Visible && Toplevel == Current)
if (!topLevel.Visible && topLevel == Current)
{
OverlappedMoveNext ();
}
}

#nullable enable
private static Toplevel? FindDeepestTop (Toplevel start, int x, int y)
private static Toplevel? FindDeepestTop (Toplevel start, in Point location)
{
if (!start.Frame.Contains (x, y))
if (!start.Frame.Contains (location))
{
return null;
}

if (_topLevels is { Count: > 0 })
{
int rx = x - start.Frame.X;
int ry = y - start.Frame.Y;
int rx = location.X - start.Frame.X;
int ry = location.Y - start.Frame.Y;

foreach (Toplevel t in _topLevels)
{
Expand Down Expand Up @@ -1561,7 +1558,7 @@ internal static void OnMouseEvent (MouseEvent mouseEvent)
return;
}

var view = View.FindDeepestView (Current, mouseEvent.X, mouseEvent.Y);
var view = View.FindDeepestView (Current, mouseEvent.Position);

if (view is { })
{
Expand All @@ -1579,18 +1576,17 @@ internal static void OnMouseEvent (MouseEvent mouseEvent)
{
// If the mouse is grabbed, send the event to the view that grabbed it.
// The coordinates are relative to the Bounds of the view that grabbed the mouse.
Point frameLoc = MouseGrabView.ScreenToViewport (mouseEvent.X, mouseEvent.Y);
Point frameLoc = MouseGrabView.ScreenToViewport (mouseEvent.Position);

var viewRelativeMouseEvent = new MouseEvent
{
X = frameLoc.X,
Y = frameLoc.Y,
Position = frameLoc,
Flags = mouseEvent.Flags,
ScreenPosition = new (mouseEvent.X, mouseEvent.Y),
ScreenPosition = mouseEvent.Position,
View = MouseGrabView
};

if ((MouseGrabView.Viewport with { Location = Point.Empty }).Contains (viewRelativeMouseEvent.X, viewRelativeMouseEvent.Y) is false)
if ((MouseGrabView.Viewport with { Location = Point.Empty }).Contains (viewRelativeMouseEvent.Position) is false)
{
// The mouse has moved outside the bounds of the view that grabbed the mouse
_mouseEnteredView?.NewMouseLeaveEvent (mouseEvent);
Expand Down Expand Up @@ -1623,10 +1619,10 @@ internal static void OnMouseEvent (MouseEvent mouseEvent)
{
// This occurs when there are multiple overlapped "tops"
// E.g. "Mdi" - in the Background Worker Scenario
View? top = FindDeepestTop (Top, mouseEvent.X, mouseEvent.Y);
view = View.FindDeepestView (top, mouseEvent.X, mouseEvent.Y);
View? top = FindDeepestTop (Top, mouseEvent.Position);
view = View.FindDeepestView (top, mouseEvent.Position);

if (view is { } && view != OverlappedTop && top != Current)
if (view is { } && view != OverlappedTop && top != Current && top is { })
{
MoveCurrent ((Toplevel)top);
}
Expand All @@ -1642,27 +1638,25 @@ internal static void OnMouseEvent (MouseEvent mouseEvent)

if (view is Adornment adornment)
{
Point frameLoc = adornment.ScreenToFrame (mouseEvent.X, mouseEvent.Y);
Point frameLoc = adornment.ScreenToFrame (mouseEvent.Position);

me = new ()
{
X = frameLoc.X,
Y = frameLoc.Y,
Position = frameLoc,
Flags = mouseEvent.Flags,
ScreenPosition = new (mouseEvent.X, mouseEvent.Y),
ScreenPosition = mouseEvent.Position,
View = view
};
}
else if (view.ViewportToScreen (Rectangle.Empty with { Size = view.Viewport.Size }).Contains (mouseEvent.X, mouseEvent.Y))
else if (view.ViewportToScreen (Rectangle.Empty with { Size = view.Viewport.Size }).Contains (mouseEvent.Position))
{
Point viewportLocation = view.ScreenToViewport (mouseEvent.X, mouseEvent.Y);
Point viewportLocation = view.ScreenToViewport (mouseEvent.Position);

me = new ()
{
X = viewportLocation.X,
Y = viewportLocation.Y,
Position = viewportLocation,
Flags = mouseEvent.Flags,
ScreenPosition = new (mouseEvent.X, mouseEvent.Y),
ScreenPosition = mouseEvent.Position,
View = view
};
}
Expand Down Expand Up @@ -1714,14 +1708,13 @@ internal static void OnMouseEvent (MouseEvent mouseEvent)
break;
}

Point boundsPoint = view.ScreenToViewport (mouseEvent.X, mouseEvent.Y);
Point boundsPoint = view.ScreenToViewport (mouseEvent.Position);

me = new ()
{
X = boundsPoint.X,
Y = boundsPoint.Y,
Position = boundsPoint,
Flags = mouseEvent.Flags,
ScreenPosition = new (mouseEvent.X, mouseEvent.Y),
ScreenPosition = mouseEvent.Position,
View = view
};
}
Expand Down
4 changes: 2 additions & 2 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ bool IsButtonClickedOrDoubleClicked (MouseFlags flag)

_lastMouseFlags = mouseFlag;

var me = new MouseEvent { Flags = mouseFlag, X = pos.X, Y = pos.Y };
Debug.WriteLine ($"CursesDriver: ({me.X},{me.Y}) - {me.Flags}");
var me = new MouseEvent { Flags = mouseFlag, Position = pos };
//Debug.WriteLine ($"CursesDriver: ({me.Position}) - {me.Flags}");

OnMouseEvent (me);
}
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/ConsoleDrivers/NetDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ private MouseEvent ToDriverMouse (NetEvents.MouseEvent me)
mouseFlag |= MouseFlags.ButtonAlt;
}

return new MouseEvent { X = me.Position.X, Y = me.Position.Y, Flags = mouseFlag };
return new MouseEvent { Position = me.Position, Flags = mouseFlag };
}

#endregion Mouse Handling
Expand Down
13 changes: 5 additions & 8 deletions Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void ReadFromConsoleOutput (Size size, Coord coords, ref SmallRect window
}
}

SetInitialCursorVisibility();
SetInitialCursorVisibility ();

if (!SetConsoleActiveScreenBuffer (_screenBuffer))
{
Expand Down Expand Up @@ -1483,7 +1483,7 @@ internal void ProcessInput (WindowsConsole.InputRecord inputEvent)
case WindowsConsole.EventType.Mouse:
MouseEvent me = ToDriverMouse (inputEvent.MouseEvent);

if (me is null || me.Flags == MouseFlags.None)
if (me is null || me.Flags == MouseFlags.None)
{
break;
}
Expand All @@ -1494,8 +1494,7 @@ internal void ProcessInput (WindowsConsole.InputRecord inputEvent)
{
OnMouseEvent (new ()
{
X = me.X,
Y = me.Y,
Position = me.Position,
Flags = ProcessButtonClick (inputEvent.MouseEvent)
});
}
Expand Down Expand Up @@ -1814,8 +1813,7 @@ private async Task ProcessContinuousButtonPressedAsync (MouseFlags mouseFlag)
{
var me = new MouseEvent
{
X = _pointMove.X,
Y = _pointMove.Y,
Position = _pointMove,
Flags = mouseFlag
};

Expand Down Expand Up @@ -2129,8 +2127,7 @@ private MouseEvent ToDriverMouse (WindowsConsole.MouseEventRecord mouseEvent)

return new MouseEvent
{
X = mouseEvent.MousePosition.X,
Y = mouseEvent.MousePosition.Y,
Position = new (mouseEvent.MousePosition.X, mouseEvent.MousePosition.Y),
Flags = mouseFlag
};
}
Expand Down
24 changes: 11 additions & 13 deletions Terminal.Gui/Drawing/Thickness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace Terminal.Gui;
/// </summary>
/// <remarks>
/// <para>
/// Use the helper API (<see cref="GetInside(Rectangle)"/> to get the rectangle describing the insides of the frame,
/// Use the helper API (<see cref="GetInside(Rectangle)"/> to get the rectangle describing the insides of the
/// frame,
/// with the thickness widths subtracted.
/// </para>
/// <para>Use the helper API (<see cref="Draw(Rectangle, string)"/> to draw the frame with the specified thickness.</para>
Expand Down Expand Up @@ -86,32 +87,29 @@ public int Vertical
public bool Equals (Thickness other) { return other is { } && Left == other.Left && Right == other.Right && Top == other.Top && Bottom == other.Bottom; }

/// <summary>
/// Gets whether the specified coordinates lie within the thickness (inside the bounding rectangle but outside of
/// Gets whether the specified coordinates lie within the thickness (inside the bounding rectangle but outside
/// the rectangle described by <see cref="GetInside(Rectangle)"/>.
/// </summary>
/// <param name="outside">Describes the location and size of the rectangle that contains the thickness.</param>
/// <param name="x">The x coord to check.</param>
/// <param name="y">The y coord to check.</param>
/// <param name="location">The coordinate to check.</param>
/// <returns><see langword="true"/> if the specified coordinate is within the thickness; <see langword="false"/> otherwise.</returns>
public bool Contains (Rectangle outside, int x, int y)
public bool Contains (in Rectangle outside, in Point location)
{
Rectangle inside = GetInside (outside);

return outside.Contains (x, y) && !inside.Contains (x, y);
return outside.Contains (location) && !inside.Contains (location);
}

/// <summary>
/// Adds the thickness widths of another <see cref="Thickness"/> to the current <see cref="Thickness"/>, returning a new <see cref="Thickness"/>.
/// Adds the thickness widths of another <see cref="Thickness"/> to the current <see cref="Thickness"/>, returning a
/// new <see cref="Thickness"/>.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public Thickness Add (Thickness other)
{
return new Thickness (Left + other.Left, Top + other.Top, Right + other.Right, Bottom + other.Bottom);
}
public Thickness Add (Thickness other) { return new (Left + other.Left, Top + other.Top, Right + other.Right, Bottom + other.Bottom); }

/// <summary>
/// Adds the thickness widths of another <see cref="Thickness"/> to another <see cref="Thickness"/>.
/// Adds the thickness widths of another <see cref="Thickness"/> to another <see cref="Thickness"/>.
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
Expand Down Expand Up @@ -194,7 +192,7 @@ rect with
);
}

if (View.Diagnostics.HasFlag(ViewDiagnosticFlags.Ruler))
if (View.Diagnostics.HasFlag (ViewDiagnosticFlags.Ruler))
{
// PERF: This can almost certainly be simplified down to a single point offset and fewer calls to Draw
// Top
Expand Down
23 changes: 10 additions & 13 deletions Terminal.Gui/Input/Mouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,15 @@ public class MouseEvent
/// <summary>The View at the location for the mouse event.</summary>
public View View { get; set; }

/// <summary>The X position of the mouse in <see cref="Gui.View.Viewport"/>-relative coordinates.</summary>
public int X { get; set; }

/// <summary>The Y position of the mouse in <see cref="Gui.View.Viewport"/>-relative coordinates.</summary>
public int Y { get; set; }

/// <summary>
/// Indicates if the current mouse event has been processed. Set this value to <see langword="true"/> to indicate the mouse
/// event was handled.
/// </summary>
public bool Handled { get; set; }
/// <summary>The position of the mouse in <see cref="Gui.View.Viewport"/>-relative coordinates.</summary>
public Point Position { get; set; }

/// <summary>
/// The screen-relative mouse position.
/// </summary>
/// <remarks>
/// <para>
/// The <see cref="X"/> and <see cref="Y"/> properties are always <see cref="Gui.View.Viewport"/>-relative. When the mouse is grabbed by a view,
/// <see cref="Position"/> is <see cref="Gui.View.Viewport"/>-relative. When the mouse is grabbed by a view,
/// <see cref="ScreenPosition"/> provides the mouse position screen-relative coordinates, enabling the grabbed view to know how much the
/// mouse has moved.
/// </para>
Expand All @@ -143,7 +134,13 @@ public class MouseEvent
/// </remarks>
public Point ScreenPosition { get; set; }

/// <summary>
/// Indicates if the current mouse event has been processed. Set this value to <see langword="true"/> to indicate the mouse
/// event was handled.
/// </summary>
public bool Handled { get; set; }

/// <summary>Returns a <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</summary>
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</returns>
public override string ToString () { return $"({X},{Y}):{Flags}"; }
public override string ToString () { return $"({Position}):{Flags}"; }
}
6 changes: 3 additions & 3 deletions Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public override bool OnMouseEvent (MouseEvent me, bool fromHost = false)

if (me.Flags == MouseFlags.Button1Clicked)
{
SelectedIdx = me.Y - ScrollOffset;
SelectedIdx = me.Position.Y - ScrollOffset;

return Select ();
}
Expand Down Expand Up @@ -465,9 +465,9 @@ protected void MoveUp ()
/// <param name="me"></param>
protected void RenderSelectedIdxByMouse (MouseEvent me)
{
if (SelectedIdx != me.Y - ScrollOffset)
if (SelectedIdx != me.Position.Y - ScrollOffset)
{
SelectedIdx = me.Y - ScrollOffset;
SelectedIdx = me.Position.Y - ScrollOffset;

if (LastPopupPos is { })
{
Expand Down

0 comments on commit 6c6dec1

Please sign in to comment.