with Widgets.Menu_Items; use Widgets.Menu_Items;
package Widgets.Containers.Panels.Popups is
-- A Popup widget is a menu widget that contains a single column of
-- Menu_Items. It allows widgets to register for notifications when the
-- widget loses visibility. It's minimum size is calculated from the minimum
-- size of its children so its size can be computed automatically. The popup
-- widget registers itself as a listener for menu items added to it, and
-- hides automatically when a menu item in it is activated.
type Popup is new Panel and Menu_Listener with private;
type A_Popup is access all Popup'Class;
-- Creates a new Popup menu within 'view' with id 'id'. If 'title' or 'icon'
-- are given a value, the menu will have a title bar like a standard panel,
-- displaying the popup menu's title text and/or icon. 'icon' is the
-- filename of the icon in the theme's tile library.
function Create_Popup( view : not null access Game_Views.Game_View'Class;
id : String;
title : String := "";
icon : String := "" ) return A_Popup;
pragma Precondition( id'Length > 0 );
pragma Postcondition( Create_Popup'Result /= null );
-- Appends an item to the menu. Note that a Constraint_Error will be raised
-- if 'child' is not a Menu_Item. Otherwise, if 'consume' is True then
-- 'child' will be consumed. Regardless of the value of 'consume', 'child'
-- will belong to the Popup widget.
procedure Add( this : access Popup;
child : in out A_Widget;
consume : Boolean := True );
pragma Precondition( child /= null );
pragma Postcondition( consume xor child /= null );
private
type Popup is new Panel and Menu_Listener with null record;
procedure Construct( this : access Popup;
view : not null access Game_Views.Game_View'Class;
id : String;
title : String;
icon : String );
pragma Precondition( id'Length > 0 );
-- Returns the minimum height of the Popup menu, calculated as a sum of the
-- heights of the menu's items. If the minimum height of the Popup was
-- manually specified, it will override.
function Get_Min_Height( this : access Popup ) return Natural;
-- Returns the minimum width of the Popup menu, calculated as the maximum
-- width of the menu's items. If the minimum width of the Popup was
-- manually specified, it will override.
function Get_Min_Width( this : access Popup ) return Natural;
-- Hides the widget when a child menu item is activated.
procedure Handle_Action( this : access Popup;
action : A_Menu_Action );
-- Packs the Popup menu, automatically adjusting the layout of each item
-- to fit in the menu. If the height of the popup menu was specified to be
-- larger than the space needed by its children, the empty space will be at
-- the bottom. The children will fill the entire width of the menu.
procedure Pack( this : access Popup );
end Widgets.Containers.Panels.Popups;