Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abandoned - Fixes #3691. Adds Popover #3749

Draft
wants to merge 66 commits into
base: v2_develop
Choose a base branch
from

Conversation

tig
Copy link
Collaborator

@tig tig commented Sep 19, 2024

Fixes

fykztjo 1

fImBrr3 1

Proposed Changes/Todos

Future PRs

  • Replace Menu and MenuBar using Bar (aka finish Menuv2

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

@tig tig changed the title V2 3691 popover Fixes #3691. Adds Popover Sep 19, 2024
@tig
Copy link
Collaborator Author

tig commented Sep 19, 2024

FWIW, here's the API in action (the prototype for the File menubar item in Bars):

var fileMenuBarItem = new Shortcut
{
    Title = "_File",
    HelpText = "File Menu",
    Key = Key.D0.WithAlt,
};

fileMenuBarItem.Accept += (sender, args) =>
                          {
                              var fileMenu = new Menuv2
                              {
                                  Id = "fileMenu",
                              };
                              ConfigureMenu (fileMenu);
                              fileMenu.VisibleChanged += (sender, args) =>
                                                         {
                                                             if (Application.Popover == _popoverMenu && Application.Popover is { Visible: false })
                                                             {
                                                                 Application.Popover?.Dispose ();
                                                                 Application.Popover = null;
                                                             }
                                                         };
                              Application.Popover = fileMenu;
                              Rectangle screen = fileMenuBarItem.FrameToScreen ();
                              fileMenu.X = screen.X;
                              fileMenu.Y = screen.Y + screen.Height;
                              fileMenu.Visible = true;

                          };

Here's the entirety of the new API (on Application):

    /// <summary>Gets or sets the Application Popover View.</summary>
    /// <remarks>
    ///     <para>
    ///         To show or hide the Popover, set it's <see cref="View.Visible"/> property.
    ///     </para>
    /// </remarks>
    public static View? Popover

@tig
Copy link
Collaborator Author

tig commented Sep 23, 2024

ZtNvfaH 1

@tig
Copy link
Collaborator Author

tig commented Sep 23, 2024

Kinda cool. Mouse wheel will now be able to nav within a Bar (or Menu).

AKE5pyM 1

@tig
Copy link
Collaborator Author

tig commented Sep 26, 2024

n4wBc8q 1

A new ContextMenuv2 implementation.

TextField now uses it instead of the old one.

@tig tig marked this pull request as draft November 10, 2024 15:35
@tig
Copy link
Collaborator Author

tig commented Nov 25, 2024

Here's how this PR current works:

There's a new property on Application:

    /// <summary>Gets or sets the Application Popover View.</summary>
    /// <remarks>
    ///     <para>
    ///         To show or hide the Popover, set it's <see cref="View.Visible"/> property.
    ///     </para>
    /// </remarks>
    public static View? Popover

When set, if there's an Popover it's made Visible = false. Then the new View is set as the popover, initialized if needed.

A handler for _popover.VisibleChanged is added which does the heavy lifting.

To show a Popover, e.g. on a right mouse click, simply :

  • Set your View's X/Y to the Screen-relative coords you want
  • Set Application.Popover to your View
  • Set yourView.Visible = true
        void TestFrameOnMouseClick (object sender, MouseEventArgs e)
        {
            if (e.Flags == MouseFlags.Button3Clicked)
            {
                popoverView.X = e.ScreenPosition.X;
                popoverView.Y = e.ScreenPosition.Y;
                Application.Popover = popoverView;
                Application.Popover!.Visible = true;
            }
        }

The View will remain visible and will prevent any other view from getting mouse/keyboard input until

  • The user clicks outside of the popover's fame
  • The user presses QuitKey
  • Someone sets Applicaiton.Popover.Visible = false
  • Someone sets a new View to Application.Popover

This works fairly brilliantly for:

Standalone use-cases as shown in ViewExperiments.cs

06cV1tE 1
S

ContextMenu (hacked to use Menuv2/Bar - No sub-menus

Q7F4sIY 1

Menuv (Prototype)

TXHKxsX 1

Problems

  • It's really not a good design to couple more View logic in Application. I would really prefer that Application just knows about a single Top. This design actually works against what I'm trying to do with

  • MenuBar scenarios require the MenuBar, which is not a Popover, to still receive input when a sub-menu is shown as the Popo er. All modern menu systems, esp on Windows, let you hover over the menu bar once activated and sub-menus are automatcially shown/hidden as you do so:

Ifu2n1N 1

qy3du96 1

With this design, there's no clean way to make this happen. Here's what it looks like now (I have to click on a menu bar item to activate it's submenu):
NfYHxD5 1

There's also no good way, with this design, to enable sub-menus.

I've spent a bunch of time noodling on this particular issue and tried several ideas, all of which seem like hacks and just cause more issues:

  • Transform this._menuBar into a Popover dynamically (e.g.. clone it and set the clone to Application.Popover).
  • Make Application.Popover be Stack<View> Popovers in conjunction with the clone idea.

So, for this reason, for now, I'm going to abandon this PR, fork the branch, and create a new PR that will try a different approach:

  • Add ViewArrangement.Popover
  • Any view with this flag set, will be "homed" from a layout/mouse/keyboard input perspective as though they were subviews of Application.Top

@tig tig changed the title Fixes #3691. Adds Popover Abandoned - Fixes #3691. Adds Popover Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants