LS.GUI Class
GUI is a static class used to create two kinds of GUIs: HTML GUIs on top of the 3D Canvas (in a safe way) or Immediate GUI using a Canvas2D (fast gui) For HTML GUIs check the getHTMLRoot function. For Immediate GUIs check the Box,Button,Toggle,Textfield,HorizontalSlider,VerticalSlider and Toolbar. To change colors of the immediate GUI check the LS.GUI.GUIStyle
Constructor
LS.GUI
()
Item Index
Methods
attach
-
element
-
anchor
attach HTMLElement to HTML GUI Root in the anchor position specified
Parameters:
-
element
HTMLElement -
anchor
String"top-left", "top-right", "bottom-left", "bottom-right" or "none"
Box
-
area
-
color
Renders an immediate gui BOX, used as background
Parameters:
-
area
Array[x,y,width,height]
-
color
Stringa color in string format "#AFAFAF"
Button
-
area
-
content
-
content_over
Renders a Button and returns if the button was pressed
Parameters:
-
area
Array[x,y,width,height]
-
content
String | GL.Texturecould be a string or a GL.Texture (if null the button will be invisible)
-
content_over
String | GL.Texturesame as before but in case the mouse is over
Returns:
true if the button was pressed
createElement
-
tag_type
-
anchor
Creates a HTMLElement of the tag_type and adds it to the DOM on top of the canvas
Parameters:
-
tag_type
Stringthe tag type "div"
-
anchor
String"top-left", "top-right", "bottom-left", "bottom-right" or "none"
Returns:
detach
-
element
Removes an element from the GUI (same as element.parentNode.removeChild( element ); )
Parameters:
-
element
HTMLElementHTML element to detach from the GUI
getHTMLRoot
()
HTMLElement
Returns the DOM element responsible for the HTML GUI of the app. This is helpful because this GUI will be automatically removed if the app finishes. Any HTML must be attached to this element, otherwise it may have problems with the editor.
Returns:
hideHTML
()
hides the HTML GUI (but it is still existing)
HorizontalSlider
-
area
-
value
-
left_value
-
right_value
-
show_value
Renders an horizontal slider widget, returns the current value Remember: you must pass as value the same value returned by this function in order to work propertly
Parameters:
-
area
Array[x,y,width,height]
-
value
Numberthe value to show in the slider
-
left_value
Numberthe minimum value for the slider
-
right_value
Numberthe maximum value for the slider
-
show_value
Booleanif you want to see a caption in text format with the value
Returns:
the current value of the slider (will be different from value if it was clicked)
Knob
-
area
-
value
-
bottom_value
-
top_value
-
steps
-
content
Renders an knob slider widget, returns the current value Remember: you must pass as value the same value returned by this function in order to work propertly
Parameters:
-
area
Array[x,y,width,height]
-
value
Numberthe value to show in the slider
-
bottom_value
Numberthe minimum value for the slider
-
top_value
Numberthe maximum value for the slider
-
steps
Number[optional] the numeber of steps (if 0 then infinite)
-
content
Image | GL.Texture[optional] a texture or image to use as the knob
Returns:
the current value of the slider (will be different from value if it was clicked)
Label
-
area
-
content
Renders a text (or a texture)
Parameters:
-
area
Array[x,y,width,height]
-
content
String | GL.Texturecould be a string or a GL.Texture
loadHTML
-
url
-
on_complete
Loads resource containing the HTML code for the GUI and attachs it inside a div to the hud
Parameters:
-
url
Stringthe url of the resource containing all the HTML code
-
on_complete
Functioncallback that will be called once the HTML has been loaded and attached to the doom, it receives the HTMLElement containing all the HTML
reset
()
Removes all the GUI elements from the DOM
ResetImmediateGUI
()
Called by the LS.Renderer to clear intermediate stuff
showHTML
()
shows the HTML GUI
TextField
-
area
-
text
-
max_length
-
is_password
Renders a textfield widget and returns the current text value Remember: you must pass as text the same text returned by this function in order to work propertly
Parameters:
-
area
Array[x,y,width,height]
-
text
Stringthe text to show in the textfield
-
max_length
Numberto limit the text, otherwise leave blank
-
is_password
Booleanset to true to show as password
Returns:
the current state of the checkbox (will be different from value if it was pressed)
Toggle
-
area
-
value
-
content
-
content_off
Renders a checkbox widget, and returns the current state Remember: you must pass as value the same value returned by this function in order to work propertly
Parameters:
-
area
Array[x,y,width,height]
-
value
Booleanif the checkbox is on or off
-
content
String | GL.Texturean string or image in case the checkbox is on
-
content_off
String | GL.Texturean string or image in case the checkbox is off
Returns:
the current state of the checkbox (will be different from value if it was pressed)
Toolbar
-
area
-
selected
-
options
Renders a Toolbar (list of buttons) and returns the active one
Parameters:
-
area
Array[x,y,width,height]
-
selected
Numberthe index of the selected option
-
options
ArrayString | GL.Texturean array containing either strings or GL.Texture
Returns:
the selected index
VerticalSlider
-
area
-
value
-
bottom_value
-
top_value
Renders an vertical slider widget, returns the current value Remember: you must pass as value the same value returned by this function in order to work propertly
Parameters:
-
area
Array[x,y,width,height]
-
value
Numberthe value to show in the slider
-
bottom_value
Numberthe minimum value for the slider
-
top_value
Numberthe maximum value for the slider
Returns:
the current value of the slider (will be different from value if it was clicked)