with Widgets.Buttons; use Widgets.Buttons;
private with Widgets.Scrollbars;
package Widgets.Containers.Scroll_Panes is
-- A Scroll_Pane is a simple container widget with horizontal and
-- vertical scrollbars that control a client widget's viewport. The client
-- is displayed within the Scroll_Pane's content area as a child widget.
-- Clients should implement the Scrollable interface to support scrolling.
type Scroll_Pane is new Container and Button_Listener with private;
type A_Scroll_Pane is access all Scroll_Pane'Class;
-- Creates a new Scroll_Pane within 'view' with id 'id'.
function Create_Scroll_Pane( view : not null access Game_Views.Game_View'Class;
id : String ) return A_Scroll_Pane;
pragma Precondition( id'Length > 0 );
pragma Postcondition( Create_Scroll_Pane'Result /= null );
-- Shows or hides the horizontal scrollbar. If 'draw' is True, the scrollbar
-- will be drawn. Toggling the draw state of the scrollbar will repack the
-- scroll pane.
procedure Draw_Hbar( this : access Scroll_Pane; draw : Boolean );
-- Shows or hides the vertical scrollbar. If 'draw' is True, the scrollbar
-- will be drawn. Toggling the draw state of the scrollbar will repack the
-- scroll pane.
procedure Draw_Vbar( this : access Scroll_Pane; draw : Boolean );
-- Sets the single client widget of the scroll pane. If the scroll pane
-- already has a client, the old one will be deleted. The client widget
-- should implement the Scrollable interface to support scrolling. 'client'
-- will be consumed.
procedure Set_Client( this : access Scroll_Pane;
client : in out A_Widget );
pragma Postcondition( client = null );
-- Sets the padding (in pixels) between the edges of the client and the
-- edges of the scroll pane and scroll bars. See diagram below.
--
-- padding padding
-- -- --
-- +------------+--+
-- | |##| | padding
-- | +------+ |v |
-- | |client| |b |
-- | | | |a |
-- | +------+ |r |
-- | |##| | padding
-- +------------+--+
-- |# hbar #|//|
-- +------------+--+
procedure Set_Padding( this : access Scroll_Pane; padding : Natural );
private
use Widgets.Scrollbars;
type Scroll_Pane is new Container and Button_Listener with
record
client : A_Widget := null;
hscroll : A_H_Scrollbar := null;
vscroll : A_V_Scrollbar := null;
left,
right,
up,
down : A_Button := null;
drawHbar,
drawVbar : Boolean := True;
padding : Natural := 0; -- used for all sides
end record;
-- Re-applies the scroll pane's child layout, taking into account the
-- visibility of the scroll bars and the padding distance around the client.
procedure Adjust_Layout( this : access Scroll_Pane );
procedure Construct( this : access Scroll_Pane;
view : not null access Game_Views.Game_View'Class;
id : String );
pragma Precondition( id'Length > 0 );
-- Draws the scroll pane's background, including the small square in the
-- lower right that appears when both scroll bars are visible.
procedure Draw_Content( this : access Scroll_Pane; dc : Drawing_Context );
-- Returns the client's scrolling increment, in pixels, in the X dimension.
-- A default scroll increment will be returned if the scroll pane does not
-- have a client, or the client does not implement Scrollable.
function Get_Inc_X( this : access Scroll_Pane ) return Integer;
-- Returns the client's scrolling increment, in pixels, in the Y dimension.
-- A default scroll increment will be returned if the scroll pane does not
-- have a client, or the client does not implement Scrollable.
function Get_Inc_Y( this : access Scroll_Pane ) return Integer;
-- Handles Press and Held actions from the buttons at the ends of the scroll
-- bars.
procedure Handle_Action( this : access Scroll_Pane;
action : A_Button_Action );
-- Handles mouse scroll wheel actions to scroll vertically, if the client
-- doesn't handle them.
function Handle_Mouse_Scroll( this : access Scroll_Pane;
evt : not null A_Mouse_Scroll_Event ) return Boolean;
-- Adjusts the child layout after a resize.
procedure Handle_Resize( this : access Scroll_Pane );
end Widgets.Containers.Scroll_Panes;