Inspector Class
Inspector allows to create a list of widgets easily, it also provides methods to create the widgets automatically.
Every widget is created calling the function add followed by the widget name, p.e. addSlider or addVector3 or addNumber.
Widgets always receive three parameters:
- name: String that defines the name at that it will be shown in the left side of the widget.
- value: the value that will be displayed in the widget.
- options: Object containing all the values .
Constructor
Inspector
-
options
Parameters:
-
optionsObjectobject with a set of options {
width: total width
height: total height
widgets_width: width of every widget (used mostly in horizontal inspectors)
name_width: width of the name part of widgets
full: set to true if you want the inspector to use all the parent width and height
widgets_per_row: number of widgets per row, default is 1 but you can change it if you want to pack several widgets in a row (useful for small widgets like checkboxes)
one_line: widgets are place one next to the other horizontaly
onchange: callback to call when something changes
}Dependencies: - jscolor.js
Item Index
Methods
add
-
type -
name -
value -
options:
Adds a widgete to the inspector, its a way to provide the widget type from a string
Parameters:
-
typeStringstring specifying the name of the widget to use (check Inspector.widget_constructors for a complete list)
-
nameStringthe string to show at the left side of the widget, if null this element wont be created and the value part will use the full width
-
valueStringthe value to assign to the widget
-
options:Objectsome generic options that any widget could have:
- type: overwrites the type
- callback: function to call when the user interacts with the widget and changes the value [For a bigger list check createWidget and every widget in particular]
Returns:
the widget in the form of the DOM element that contains it
addArray
-
name -
value -
options,
Widget to edit an array of values of a certain type
Parameters:
-
nameString -
valueArray -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- data_type: the type of every value inside the array
- data_options: options for the widgets of every item in the array
- max_items: max number of items to show from the array, default is 100
- callback: function to call once an items inside the array has changed
Returns:
the widget in the form of the DOM element that contains it
addCheckbox
-
name -
value -
options,
Widget to edit a boolean value using a checkbox
Parameters:
-
nameString -
valueBoolean -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- label: text to show, otherwise it shows on/off
- label_on: text to show when on
- label_off: text to show when off
- callback: function to call once the value changes
Returns:
the widget in the form of the DOM element that contains it
addCombo
-
name -
value -
options,
Widget to edit an enumeration using a combobox
Parameters:
-
nameString -
value -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- values: a list with all the possible values, it could be an array, or an object, in case of an object, the key is the string to show, the value is the value to assign
- disabled: true to disable
- callback: function to call once an items is clicked
Returns:
the widget in the form of the DOM element that contains it
addFlags
-
value -
optional
Widget to edit a set of boolean values using checkboxes
Parameters:
-
valueObjectobject that contains all the booleans
-
optionalObjectobject with extra flags to insert
Returns:
the widget in the form of the DOM element that contains it
addInfo
-
name -
value -
options,
Widget to show plain information in HTML (not interactive)
Parameters:
-
nameString -
valueStringHTML code
-
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- className: to specify a classname of the content
- height: to specify a height
Returns:
the widget in the form of the DOM element that contains it
addList
-
name -
value -
options,
Widget to select from a list of items
Parameters:
-
nameString -
value[Array or Object]
-
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- multiselection: allow multiple selection
- callback: function to call once an items is clicked
- selected: the item selected
Returns:
the widget in the form of the DOM element that contains it
addNumber
-
name -
value -
options,
Widget to edit numbers (it adds a dragging mini widget in the right side)
Parameters:
-
nameString -
valueNumber -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- disabled: shows the widget disabled
- callback: function to call when the string is edited
- precision: number of digits after the colon
- units: string to show after the number
- min: minimum value accepted
- max: maximum value accepted
- step: increments when draggin the mouse (default is 0.1)
Returns:
the widget in the form of the DOM element that contains it
addPad
-
name -
value -
options,
Widget to edit two numbers using a rectangular pad where you can drag horizontaly and verticaly a handler
Parameters:
-
nameString -
valueVec2 -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- callback: function to call once the value changes
- disabled: shows the widget disabled
- callback: function to call when the string is edited
- precision: number of digits after the colon
- units: string to show after the number
- min: minimum value accepted
- minx: minimum x value accepted
- miny: minimum y value accepted
- max: maximum value accepted
- maxx: maximum x value accepted
- maxy: maximum y value accepted
- step: increments when draggin the mouse (default is 0.1)
- background: url of image to use as background (it will be streched)
Returns:
the widget in the form of the DOM element that contains it
addSeparator
()
HTMLElement
Creates a line
Returns:
the widget in the form of the DOM element that contains it
addSlider
-
name -
value -
options,
Widget to edit a number using a slider
Parameters:
-
nameString -
valueNumber -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- min: min value
- max: max value
- step: increments when dragging
- callback: function to call once the value changes
Returns:
the widget in the form of the DOM element that contains it
addString
-
name -
value -
options,
Widget to edit strings
Parameters:
-
nameString -
valueString -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- focus: true if you want the cursor to be here
- password: true if you want to hide the string
- immediate: calls the callback once every keystroke
- disabled: shows the widget disabled
- callback: function to call when the widget changes
Returns:
the widget in the form of the DOM element that contains it
addStringButton
-
name -
value -
options,
Widget to edit strings, but it adds a button behind (useful to search values somewhere in case the user do not remember the name)
Parameters:
-
nameString -
valueStringthe string to show
-
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- disabled: shows the widget disabled
- button: string to show inside the button, default is "..."
- callback: function to call when the string is edited
- callback_button: function to call when the button is pressed
Returns:
the widget in the form of the DOM element that contains it
addTextarea
-
name -
value -
options,
Widget to edit strings with multiline support
Parameters:
-
nameString -
valueString -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- focus: true if you want the cursor to be here
- password: true if you want to hide the string
- immediate: calls the callback once every keystroke
- disabled: shows the widget disabled
- callback: function to call when the widget changes
Returns:
the widget in the form of the DOM element that contains it
addTitle
-
title -
options
Creates a title bar in the widgets list to help separate widgets
Parameters:
-
titleString -
optionsObject
Returns:
the widget in the form of the DOM element that contains it
addVector2
-
name -
value -
options,
Widget to edit two numbers (it adds a dragging mini widget in the right side)
Parameters:
-
nameString -
valueVec2 -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- callback: function to call once the value changes
- disabled: shows the widget disabled
- callback: function to call when the string is edited
- precision: number of digits after the colon
- units: string to show after the number
- min: minimum value accepted
- max: maximum value accepted
- step: increments when draggin the mouse (default is 0.1)
Returns:
the widget in the form of the DOM element that contains it
addVector3
-
name -
value -
options,
Widget to edit two numbers (it adds a dragging mini widget in the right side)
Parameters:
-
nameString -
valueVec3 -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- callback: function to call once the value changes
- disabled: shows the widget disabled
- callback: function to call when the string is edited
- precision: number of digits after the colon
- units: string to show after the number
- min: minimum value accepted
- max: maximum value accepted
- step: increments when draggin the mouse (default is 0.1)
Returns:
the widget in the form of the DOM element that contains it
addVector4
-
name -
value -
options,
Widget to edit two numbers (it adds a dragging mini widget in the right side)
Parameters:
-
nameString -
valueVec4 -
options,Objecthere is a list for this widget (check createWidget for a list of generic options):
- callback: function to call once the value changes
- disabled: shows the widget disabled
- callback: function to call when the string is edited
- precision: number of digits after the colon
- units: string to show after the number
- min: minimum value accepted
- max: maximum value accepted
- step: increments when draggin the mouse (default is 0.1)
Returns:
the widget in the form of the DOM element that contains it
assignValue
()
Tryes to assigns a value to the instance stored in this.instance
clear
()
Removes all the widgets inside the inspector
collectPropertier
-
instance
Parameters:
-
instanceObjectextract enumerable and public (name do not start with '_' ) properties from an object return {Object} object with "name" : value for every property
createWidget
-
name -
content -
options
Used by all widgets to create the container of one widget
Parameters:
-
nameStringthe string to show at the left side of the widget, if null this element wont be created and the value part will use the full width
-
contentStringthe string with the html of the elements that conform the interactive part of the widget
-
optionsObjectsome generic options that any widget could have:
- widget_name: the name used to store this widget in the widgets_by_name container, if omited the parameter name is used
- width: the width of the widget (if omited it will use the Inspector widgets_width, otherwise 100%
- name_width: the width of the name part of the widget, if not specified it will use Inspector name_width, otherwise css default
- content_width: the width of the widget content area
- pre_title: string to append to the left side of the name, this is helpful if you want to add icons with behaviour when clicked
- title: string to replace the name, sometimes you want to supply a different name than the one you want to show (this is helpful to retrieve values from an inspector)
getWidget
-
name
Parameters:
-
nameStringthe name of the widget supplied when creating it or the number of the widget
Returns:
widget object
inspectInstance
-
instance -
properties -
properties_info_example -
properties_to_skip
Parameters:
-
instanceObjectthe instance that you want to inspect, attributes will be collected from this object
-
propertiesArrayan array with all the names of the properties you want to inspect, if not specified then it calls getProperties, othewise collect them and tries to guess the type
-
properties_info_exampleObjectit overwrites the info about properties found in the object (in case the automaticaly guessed type is wrong)
-
properties_to_skipArraythis properties will be ignored
refresh
()
Tryes to refresh (calls on_refresh)
showProperties
-
instance -
properties_info -
properties_to_skip
Parameters:
-
instanceObjectthe instance that you want to inspect
-
properties_infoObjectobject containing "property_name" :{ type: value, widget:..., min:..., max:... } or just "property":"type"
-
properties_to_skipArraythis properties will be ignored
