OLPCities/Label: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 62: Line 62:
</pre>
</pre>


[[Category:OLPCities]]
[[Category:OLPCities_JavaScript_Libraries]]

Latest revision as of 23:40, 13 February 2007

This library is part of the Gamelib, created by Scott Porter and updated by Brent Silby. Gamelib is available under the terms of the GNU Library General Public Licence.

This element adds a text label to an interface. The font, size, color, border and background colours can all be customized, before or after adding the label to an interface.


To use this library (this Class) add one line to the <HEAD> section of the web page of the Lot.

You need to click this link and "save" the library at the same folder of the web page or put it at another folder at the same server and make a reference:

gamelib_interface.js

If you put it at the same folder, the line would be:

<script language="Javascript" src="gamelib_interface.js"></script> 

To create an object of the Class:

 myLabel=new In_Label(10,20,200,50,'Some text!','center','#000000',3,'Arial','#0000ff','#aaaaaa');
  myInterface.add(myLabel); 

There are 11 parameters passed to this object. These are:

(1,2) x,y (position relative to interface top left corner)
(3,4) width,height
(5) text for the label,
(6) alignment of the text ('center'|'left'|'right') or if null, it will default to left
(7) color of label text
(8) font size for label (1-7)
(9) font face for label (if null, then Arial,Helvetica,sans-serif is used)
(10) border color (if null, there is no border OR background color)
(11) background color (if null, there is no background or border color) 

Any of the properties for a label (excluding position) may be changed at any time.

Methods

setAlignment(String)      String is: 'left', 'right' or 'center'. Sets the horizontal alignment 
                            of the label inside its own box (set by the x,y position and width,
                          height dimensions.)  

setBackgroundColor(Color)  Sets the background color for the label. This will fill the box the label
                            occupies in the interface. Note: The border color must also be set for this 
                           to display. If you don't want a border of a different color to the background,
                           just set the border to the same color! If the boolean value false is sent 
                           as the parameter to this method, the background color will disappear.  

setBorderColor(Color)      Sets the border color for the label. If the parameter passed is the 
                           boolean value false, then there will be no border.
  
setFontColor(Color)        Sets the color of the label text.  

setFontFace(String)       Sets the font face for the label. If the boolean value false is passed as 
                         the parameter, then the font will become "Arial,Helvetica,sans-serif" which 
                         is an ideal font for a label.  
setFontSize(n)            Sets the size of the font. The range is 1 to 7.  

setText(String)           Sets the text for the label. So you can change a label at any time.