Skip to content

Commit

Permalink
Fixes #2558. MenuBar positions wrong in some situations. (#2567)
Browse files Browse the repository at this point in the history
* Fixes #2558. MenuBar positions wrong in some situations.

* Replacing Application.Top with Application.Current.

* Fix typo.

* Fix shortcut tag overlapping help on smaller width and add more unit test.

* Resizing the console will close all opened menus.

* Resize first the console before show ContextMenu.

* Remove DriverFrame and DriverFrameOffset as not relevant.

* Replace _frame with Frame as requested.

* Fix xml document comment.

* Compare equality between Dialog and Application.Top.

* Move GetDriverLocationOffset and GetDriverLocationOffsetFromCurrent to the Menu.cs.

* Fix merge errors.

* Ensure menu is closed on click.

* Force Height always be 1 to avoid mouse events respond even outside bounds.

* Recovering UseSubMenusSingleFrame hope doesn't break again.

* Fix bugs and made requested changes.

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
  • Loading branch information
BDisp and tig committed May 5, 2023
1 parent ea24de3 commit 915af9b
Show file tree
Hide file tree
Showing 11 changed files with 1,576 additions and 414 deletions.
6 changes: 3 additions & 3 deletions Terminal.Gui/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1208,9 +1208,9 @@ static void OnUnGrabbedMouse (View view)

static void ProcessMouseEvent (MouseEvent me)
{
bool OutsideFrame (Point p, Rect r)
bool OutsideBounds (Point p, Rect r)
{
return p.X < 0 || p.X > r.Width - 1 || p.Y < 0 || p.Y > r.Height - 1;
return p.X < 0 || p.X > r.Right || p.Y < 0 || p.Y > r.Bottom;
}

if (IsMouseDisabled) {
Expand Down Expand Up @@ -1243,7 +1243,7 @@ bool OutsideFrame (Point p, Rect r)
OfY = me.Y - newxy.Y,
View = view
};
if (OutsideFrame (new Point (nme.X, nme.Y), _mouseGrabView.Frame)) {
if (OutsideBounds (new Point (nme.X, nme.Y), _mouseGrabView.Bounds)) {
_lastMouseOwnerView?.OnMouseLeave (me);
}
//System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{mouseGrabView}");
Expand Down
4 changes: 2 additions & 2 deletions Terminal.Gui/View/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public override bool Enabled {
}
}
}

/// <summary>
/// Event fired when the <see cref="Visible"/> value is being changed.
/// </summary>
Expand Down Expand Up @@ -481,7 +481,7 @@ bool CanBeVisible (View view)

return true;
}

/// <summary>
/// Pretty prints the View
/// </summary>
Expand Down
19 changes: 5 additions & 14 deletions Terminal.Gui/Views/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public sealed class ContextMenu : IDisposable {
public ContextMenu () : this (0, 0, new MenuBarItem ()) { }

/// <summary>
/// Initializes a context menu, with a <see cref="View"/> specifiying the parent/hose of the menu.
/// Initializes a context menu, with a <see cref="View"/> specifying the parent/host of the menu.
/// </summary>
/// <param name="host">The host view.</param>
/// <param name="menuItems">The menu items for the context menu.</param>
Expand Down Expand Up @@ -79,7 +79,6 @@ public void Dispose ()
}
if (container != null) {
container.Closing -= Container_Closing;
container.TerminalResized -= Container_Resized;
}
}

Expand All @@ -91,13 +90,12 @@ public void Show ()
if (menuBar != null) {
Hide ();
}
container = Application.Top;
container = Application.Current;
container.Closing += Container_Closing;
container.TerminalResized += Container_Resized;
var frame = container.Frame;
var frame = new Rect (0, 0, View.Driver.Cols, View.Driver.Rows);
var position = Position;
if (Host != null) {
Host.ViewToScreen (container.Frame.X, container.Frame.Y, out int x, out int y);
Host.ViewToScreen (frame.X, frame.Y, out int x, out int y);
var pos = new Point (x, y);
pos.Y += Host.Frame.Height - 1;
if (position != pos) {
Expand All @@ -119,7 +117,7 @@ public void Show ()
if (Host == null) {
position.Y = frame.Bottom - rect.Height - 1;
} else {
Host.ViewToScreen (container.Frame.X, container.Frame.Y, out int x, out int y);
Host.ViewToScreen (frame.X, frame.Y, out int x, out int y);
var pos = new Point (x, y);
position.Y = pos.Y - rect.Height - 1;
}
Expand All @@ -145,13 +143,6 @@ public void Show ()
menuBar.OpenMenu ();
}

private void Container_Resized (object sender, SizeChangedEventArgs e)
{
if (IsShow) {
Show ();
}
}

private void Container_Closing (object sender, ToplevelClosingEventArgs obj)
{
Hide ();
Expand Down
Loading

0 comments on commit 915af9b

Please sign in to comment.