User Tools

Site Tools


bindings

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
bindings [2015/05/20 09:06]
pierrox Setting a variable
bindings [2015/06/21 19:21] (current)
pierrox [Bindings (variables)]
Line 2: Line 2:
 For Lighting 12.5b1 and above. For Lighting 12.5b1 and above.
  
 +**Need to set "​Expert mode" to on**
 ===== Purpose ===== ===== Purpose =====
 Bindings are an easy way to animate items. Usually items properties are set with fixed values through the configuration screens. With bindings it is possible to use dynamic values for properties. Some use cases for bindings are: set the label of a shortcut with the time or cpu usage, set the position of an item according to the orientation,​ set an icon color using the battery level, move an item upon a swipe gesture, etc. Bindings are an easy way to animate items. Usually items properties are set with fixed values through the configuration screens. With bindings it is possible to use dynamic values for properties. Some use cases for bindings are: set the label of a shortcut with the time or cpu usage, set the position of an item according to the orientation,​ set an icon color using the battery level, move an item upon a swipe gesture, etc.
Line 20: Line 21:
   * Position on the grid: cell position and dimension for the item on the grid   * Position on the grid: cell position and dimension for the item on the grid
   * Position detached from the grid: free positioning and transformation (rotation, scale, etc.)   * Position detached from the grid: free positioning and transformation (rotation, scale, etc.)
-  * Item properties: generic properties for all item types (transparency,​ visibility)+  * Item properties: generic properties for all item types (transparency,​ visibility, [[bindings_box|box]])
   * Text: properties for items displaying some text (apps, shortcuts, folders, etc.). This can be the label, the font size, color, etc.   * Text: properties for items displaying some text (apps, shortcuts, folders, etc.). This can be the label, the font size, color, etc.
   * Icon: properties for items displaying an icon, such as icon scale, colorize filter.   * Icon: properties for items displaying an icon, such as icon scale, colorize filter.
Line 26: Line 27:
  
 Not all attributes supported by Lightning are available as properties in bindings. The list of properties mainly includes visual attributes. Feel free to ask for more properties if needed! Not all attributes supported by Lightning are available as properties in bindings. The list of properties mainly includes visual attributes. Feel free to ask for more properties if needed!
 +
 +The box property, available from V12.5b7, is made of many "sub properties":​ margin, padding, border color and size, background color, for left/​top/​right/​bottom side or normal/​selected/​focused states. Please refer to the [[bindings_box|box]] page for the box property syntax and how to use it.
  
 Things to be aware of: Things to be aware of:
Line 84: Line 87:
  
 **Important note #3:** keep in mind that animations have a cost and can drain the battery if animations are running all the time. **Important note #3:** keep in mind that animations have a cost and can drain the battery if animations are running all the time.
- 
  
 Examples: Examples:
Line 96: Line 98:
 |<​del>​animate('​$alpha/​2'​)</​del>​|Invalid expression, the first argument must be a variable name only, use the result of animate for further computation| |<​del>​animate('​$alpha/​2'​)</​del>​|Invalid expression, the first argument must be a variable name only, use the result of animate for further computation|
 |255*(animate('​$ll_second'​)%1)|Make the item blink every second| |255*(animate('​$ll_second'​)%1)|Make the item blink every second|
 +
 +==== Implicit variables ====
 +When evaluating a binding formula, the following variables are available for use in scripts:
 +  * item : the object being processed ([[http://​www.pierrox.net/​android/​applications/​lightning_launcher/​script/​reference/​net/​pierrox/​lightning_launcher/​script/​api/​Item.html|as defined here]])
 +  * field : the internal property name, which list can be found in the [[http://​www.pierrox.net/​android/​applications/​lightning_launcher/​script/​reference/​net/​pierrox/​lightning_launcher/​script/​api/​PropertySet.html|PropertySet]] documentation.
  
 ===== Setting variables ===== ===== Setting variables =====
Line 111: Line 118:
 |hello+goodbye|The text "​hello+goodbye"​| |hello+goodbye|The text "​hello+goodbye"​|
 |"​hello"​+"​goodbye"​|The text "​hellogoodbye",​ notice the difference with the expression above| |"​hello"​+"​goodbye"​|The text "​hellogoodbye",​ notice the difference with the expression above|
 +|1+2|The value '​3'​ (it is evaluated as a JavaScript expression)|
 +|"​1+2"​|The value '​1+2'​ (enforce textual evaluation)|
 +|abcd"​efgh|The text '​abcd"​efgh'​|
 +|"​abcd\"​efgh"​|The text '​abcd"​efgh'​ (escaped double quote in a JavaScript expression, notice the difference with the example above)|
 |1-$t|A handy way to toggle between 0 and 1 (if the variable '​t'​ has a numerical value or no value)| |1-$t|A handy way to toggle between 0 and 1 (if the variable '​t'​ has a numerical value or no value)|
 |$t==400 ? 100 : 400|Toggle between 100 and 400 (if the variable '​t'​ has a numerical value or no value)| |$t==400 ? 100 : 400|Toggle between 100 and 400 (if the variable '​t'​ has a numerical value or no value)|
Line 117: Line 128:
  
 ==== Setting a variable from script ==== ==== Setting a variable from script ====
-Use one of the LL.setVariable//​Type//​ method to set a single variable. When setting several variables at once it may be more efficient to group updates this way:+Use one of the LL.setVariable//​Type//​ method to set a single variable, where //Type// is Boolean, Integer, Float or String. When setting several variables at once it is more efficient to group updates this way:
 <sxh javascript;>​ <sxh javascript;>​
 var editor = LL.getVariables().edit();​ var editor = LL.getVariables().edit();​
Line 125: Line 136:
 editor.commit();​ editor.commit();​
 </​sxh>​ </​sxh>​
 +Reference: see [[http://​www.pierrox.net/​android/​applications/​lightning_launcher/​script/​reference/​net/​pierrox/​lightning_launcher/​script/​api/​LL.html||API documentation]]
 ==== Setting a variable from Tasker ==== ==== Setting a variable from Tasker ====
 Please refer to [[working_with_tasker#​setting_variables_inside_lightning_from_a_tasker_task|this link]]. Please refer to [[working_with_tasker#​setting_variables_inside_lightning_from_a_tasker_task|this link]].
bindings.1432112811.txt.gz ยท Last modified: 2015/05/20 09:06 by pierrox