gui-cs / Terminal.Gui

Cross Platform Terminal UI toolkit for .NET
MIT License
9.57k stars 682 forks source link

`Popover` - A consistent way of enabling a Subview to popup outside of a View #3691

Open tig opened 3 weeks ago

tig commented 3 weeks ago

(Very drafty for now... just some thoughts).

This Issue is a proposal for how to build into TG v2 a consistent way for a View to have a UI element show itself outside of the View's Viewport.

Popover - A View that that is displayed outside of the View that owns it's Viewport.   There are at least these use-cases of Popovers:

Autocomplete Popup

TextView would like a list of autocomplete items to be displayed below the view, at the cursor position as the user types. The user can use mouse/keyboard to select an autocomplete item and the pop over disappears.

Current Implementation

Current Implementation

Menus (from MenuBar)

Current Implementation

Context Menus

Current Implementation

Tooltip

As a user, when I hover the mouse over a View, I'd like a temporary popup to appear providing a "tip" regarding the View's purpose.

Current Implementation

Proposal

Tenets (Unless you know better ones...)

Design

At the Application level we'll add a peer of Application.Top named Application.Popover:

public static bool ShowPopover (View popoverView) 
{
   if (Popover is {})
   {
      Popover.Visible = false;
   }

   if (!popoverView.IsInitialized)
   {
      popoverView.BeginInit();
      popoverView.EndInit();
   }

   Popover = popoverView;
   Popover.Visible = true;
   Popover.SetRelativeLayout(screen);
}
public static void HidePopover () 
{
   if (Popover is {})
   {
      Popover.Visible = false;
   }
}

View will have no knowledge of the popover concept.

Any View subclass that wants a Popover, will:

BDisp commented 3 weeks ago
  • There can only be one - Just like in Highlander, there can only be one Popover visible and active to the user at a time. None of the use-cases above lead to needing to have more than one, thus this is a simplifier. 1

If I remember, only occur to me that ComboBox has an option to let the dropdown list always visible. How you'll deal about that?

I love the Tooltip implementation and all the others stuff.

tig commented 3 weeks ago
  • There can only be one - Just like in Highlander, there can only be one Popover visible and active to the user at a time. None of the use-cases above lead to needing to have more than one, thus this is a simplifier. 1

If I remember, only occur to me that ComboBox has an option to let the dropdown list always visible. How you'll deal about that?

If the list is always available it is not a "Dropdown Combobox", but just a ComboBox. The current implementation doesn't really provide a "Dropdown Combobox".

tig commented 3 weeks ago

Q: What's the difference between a Modal and a Popover?

Q: Can't I use a Modal for something like the Autocomplete popup?

Q: But, can Modal be implemented using the Popover support described above?

tig commented 3 weeks ago
  • In focus/navigation handling, if Popover.HasFocus, if any other View gets focus, we'll set Popover.Visible = false.

This should say "if any other View than the Popover's owner gets focus".

Otherwise, how would the TextViewAutoComplete popover work?

BDisp commented 3 weeks ago

If the list is always available it is not a "Dropdown Combobox", but just a ComboBox. The current implementation doesn't really provide a "Dropdown Combobox".

I have a suggestion for this. If it's a "Dropdown Combobox" then Popover will be used. With a fixed ComboBox that always has the ListView visible, then ComboBox must have the available dimension to acommodate the TextField and the ListView.

tig commented 3 weeks ago

If the list is always available it is not a "Dropdown Combobox", but just a ComboBox. The current implementation doesn't really provide a "Dropdown Combobox".

I have a suggestion for this. If it's a "Dropdown Combobox" then Popover will be used. With a fixed ComboBox that always has the ListView visible, then ComboBox must have the available dimension to acommodate the TextField and the ListView.

Yes!