1. limited with Game_Views; 
  2.  
  3. package Widgets.Buttons.Toggles is 
  4.  
  5.     -- A Toggle_Button is a variation of a button that toggles its state when 
  6.     -- pressed with a mouse or activated with the keyboard. It's state remains 
  7.     -- until the mouse presses on it again to toggle the state back again. 
  8.     type Toggle_Button is new Button with private; 
  9.     type A_Toggle_Button is access all Toggle_Button'Class; 
  10.  
  11.     -- Creates a new toggle button within 'view' with id 'id'. 'text' is the 
  12.     -- button's text and 'icon' is the filename of the icon to use. Both are 
  13.     -- optional but at least one should be specified or the button will be 
  14.     -- blank. The default state of the new button is False. 
  15.     function Create_Toggle_Button( view : not null access Game_Views.Game_View'Class; 
  16.                                    id   : String; 
  17.                                    text : String := ""; 
  18.                                    icon : String := "" ) return A_Button; 
  19.     pragma Precondition( id'Length > 0 ); 
  20.     pragma Postcondition( Create_Toggle_Button'Result /= null ); 
  21.  
  22. private 
  23.  
  24.     type Toggle_Button is new Button with null record; 
  25.  
  26.     -- Handles Space, Enter and Keypad-Enter keys to toggle the state of the 
  27.     -- button. 
  28.     function Handle_Key_Press( this : access Toggle_Button; 
  29.                                evt  : not null A_Key_Event ) return Boolean; 
  30.  
  31.     -- Handles a left mouse button press to toggle the state of the button. The 
  32.     -- other mouse buttons are not used. 
  33.     procedure Handle_Mouse_Press( this : access Toggle_Button; 
  34.                                   evt  : not null A_Mouse_Button_Event ); 
  35.  
  36. end Widgets.Buttons.Toggles;