package Widgets.Buttons.Checkboxes is
-- A Checkbox is a variation of a button that toggles its state when
-- pressed with a mouse or activated with the keyboard. It differs from a
-- toggle button in that it has a checkbox icon that changes with the state,
-- not a pressed/released look. It's state remains until the mouse presses
-- on it again to toggle the state back again.
type Checkbox is new Button with private;
type A_Checkbox is access all Checkbox'Class;
-- Creates a new checkbox within 'view' with id 'id'. 'text' is the
-- checkbox's text and 'icon' is the filename to use for the icon next to
-- the text. Both are optional but at least one should be specified or the
-- checkbox will be blank. The default state of the new checkbox is False.
function Create_Checkbox( view : not null access Game_Views.Game_View'Class;
id : String;
text : String := "";
icon : String := "" ) return A_Checkbox;
pragma Precondition( id'Length > 0 );
pragma Postcondition( Create_Checkbox'Result /= null );
-- Sets the filename of the checkmark icon to display in the box when the
-- checkbox is checked. The icon should be BOX_SIZE pixels square.
procedure Set_Check_Icon( this : access Checkbox; icon : String );
private
-- the width of the checkmark icon
BOX_SIZE : constant := 12;
----------------------------------------------------------------------------
type Checkbox is new Button with
record
checkIcon : Natural := 0;
end record;
-- Draws the checkbox widget.
procedure Draw_Content( this : access Checkbox; dc : Drawing_Context );
-- Returns the minimum height of the checkbox, based on its icon and text.
function Get_Min_Height( this : access Checkbox ) return Natural;
-- Returns the minimum width of the button, based on its icon and text.
function Get_Min_Width( this : access Checkbox ) return Natural;
-- Handles Space, Enter and Keypad-Enter keys to toggle the state of the
-- checkbox.
function Handle_Key_Press( this : access Checkbox;
evt : not null A_Key_Event ) return Boolean;
-- Handles a left mouse button press to toggle the state of the checkbox.
-- The other mouse buttons are not used.
procedure Handle_Mouse_Press( this : access Checkbox;
evt : not null A_Mouse_Button_Event );
end Widgets.Buttons.Checkboxes;