OLPCities/Label: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
(3 intermediate revisions by 3 users not shown)
Line 4: Line 4:




To use this library (this Class) add this line to the <HEAD> section of the web page of the Lot:
To use this library (this Class) add one line to the <HEAD> section of the web page of the Lot.
<pre>
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:
<script language="Javascript" src="http://www.dmu.com/olpc/gamelib_interface.js"></script>
</pre>

Better 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:


[http://www.dmu.com/olpc/gamelib_interface.js gamelib_interface.js ]
[http://www.dmu.com/olpc/gamelib_interface.js gamelib_interface.js ]
Line 41: Line 38:


<pre>
<pre>
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
add(Object) Adds an element to this interface. By example an object of the Class 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,
hide() Hides the elements contained by the interface
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
makeDraggable() Makes the interface draggable. When dragged, all the elements
the interface contains will move along with it.
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
makeUndraggable() Stops the interface from being draggable.
the parameter, then the font will become "Arial,Helvetica,sans-serif" which
moveTo(n,n) Moves the interface to position x,y. This means all the elements contained
is an ideal font for a label.
setFontSize(n) Sets the size of the font. The range is 1 to 7.
by this interface will also be moved as an elements position is relative
to the position of the interface that contains it.


setText(String) Sets the text for the label. So you can change a label at any time.
setBackground(URL of image) Sets a background image in the interface itself.


setBgColor(Color) Sets the background color of the interface itself. By default, interfaces
are invisible.

setZ(n) Sets the Z index of the interface.

show() Shows the elements contained by the interface
</pre>
</pre>


[[Category:OLPCities_JavaScript_Libraries]]
==Properties==
<pre>

bgColor The current background color of the interface.

visible If true, the interface and its elements are visible.

x The x position of the interface.
y The y position of the interface.
z The z position of the interface.

</pre>
[[Category:OLPCities]]

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.