namespace Terminal.Gui.App;
///
/// Wraps any to make it a popover, similar to how
/// wraps views to make them runnable.
///
/// The type of view being wrapped.
///
///
/// This class enables any View to be shown as a popover with
///
/// without requiring the View to implement or derive from
/// .
///
///
/// The wrapper automatically handles:
///
/// - Setting proper viewport settings (transparent, transparent mouse)
/// - Configuring focus behavior
/// - Handling the quit command to hide the popover
/// - Sizing to fill the screen by default
///
///
///
/// Use for a fluent API approach.
///
///
///
/// // Wrap a custom view to make it a popover
/// var myView = new View
/// {
/// X = Pos.Center (),
/// Y = Pos.Center (),
/// Width = 40,
/// Height = 10,
/// BorderStyle = LineStyle.Single
/// };
/// myView.Add (new Label { Text = "Hello Popover!" });
///
/// var popover = new PopoverWrapper<View> { WrappedView = myView };
/// app.Popover.Register (popover);
/// app.Popover.Show (popover);
///
///
///
public class PopoverWrapper : PopoverBaseImpl where TView : View
{
///
/// Initializes a new instance of .
///
public PopoverWrapper ()
{
Id = "popoverWrapper";
Width = Dim.Auto ();
Height = Dim.Auto ();
}
private TView? _wrappedView;
///
/// Gets or sets the wrapped view that is being made into a popover.
///
///
///
/// This property must be set before the wrapper is initialized.
/// Access this property to interact with the original view or configure its behavior.
///
///
/// Thrown if the property is set after initialization.
public required TView WrappedView
{
get => _wrappedView ?? throw new InvalidOperationException ("WrappedView must be set before use.");
init
{
if (IsInitialized)
{
throw new InvalidOperationException ("WrappedView cannot be changed after initialization.");
}
_wrappedView = value;
}
}
///
public override void EndInit ()
{
base.EndInit ();
// Add the wrapped view as a subview after initialization
if (_wrappedView is { })
{
Add (_wrappedView);
}
}
}