1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. package Widgets.Labels is 
  10.  
  11.     -- A Label widget is a simple text string with an optional icon to the left 
  12.     -- of the text. A label is intended for displaying static strings and isn't 
  13.     -- editable by the interface user. 
  14.     type Label is new Widget with private; 
  15.     type A_Label is access all Label'Class; 
  16.  
  17.     -- Creates a new Label within 'view' with id 'id'. Both 'text' and 'icon' 
  18.     -- are optional. 'icon' is the name of a frame in the Theme's tile library. 
  19.     -- The icon image can have an alpha channel for transparency. 
  20.     function Create_Label( view : not null access Game_Views.Game_View'Class; 
  21.                            id   : String; 
  22.                            text : String := ""; 
  23.                            icon : String := "" ) return A_Label; 
  24.     pragma Precondition( id'Length > 0 ); 
  25.     pragma Postcondition( Create_Label'Result /= null ); 
  26.  
  27.     -- Returns the label's text. 
  28.     function Get_Text( this : not null access Label'Class ) return String; 
  29.  
  30.     -- Sets the label's text alignment. Both the text and icon will be aligned 
  31.     -- according to 'align'. 
  32.     procedure Set_Align( this : not null access Label'Class; align : Align_Type ); 
  33.  
  34.     -- Sets the color for a particular purpose when drawing the label. To remove 
  35.     -- the color behind the icon text, set the Foreground color to transparent. 
  36.     procedure Set_Color( this    : access Label; 
  37.                          purpose : Color_Purpose; 
  38.                          color   : Color_Type ); 
  39.  
  40.     -- Sets the label's icon. Pass an empty string to remove it. 
  41.     procedure Set_Icon( this : not null access Label'Class; icon : String ); 
  42.  
  43.     -- Sets the label's text. 
  44.     procedure Set_Text( this : not null access Label'Class; text : String ); 
  45.  
  46. private 
  47.  
  48.     type Label is new Widget with 
  49.         record 
  50.             align    : Align_Type := Align_Left; 
  51.             text     : Unbounded_String; 
  52.             icon     : Natural := 0; 
  53.         end record; 
  54.  
  55.     procedure Construct( this : access Label; 
  56.                          view : not null access Game_Views.Game_View'Class; 
  57.                          id   : String; 
  58.                          text : String; 
  59.                          icon : String ); 
  60.  
  61.     procedure Draw_Content( this : access Label; dc : Drawing_Context ); 
  62.  
  63.     -- Returns the label's minimum height. 
  64.     function Get_Min_Height( this : access Label ) return Natural; 
  65.  
  66.     -- Returns the label's minimum width. 
  67.     function Get_Min_Width( this : access Label ) return Natural; 
  68.  
  69. end Widgets.Labels;