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/14 08:13]
pierrox [Animation]
bindings [2015/06/21 19:21] (current)
pierrox [Bindings (variables)]
Line 1: Line 1:
 ====== Bindings (variables) ====== ====== Bindings (variables) ======
-For Lighting 12.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 timecpu 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.
  
 A binding associates a value with a property. The value can be a single variable, or it can be an expression (with arithmetic computations for instance), or a complex script (with loops, functions and access to Lightning APIs). The property is an item's attribute to be set with the value. A binding associates a value with a property. The value can be a single variable, or it can be an expression (with arithmetic computations for instance), or a complex script (with loops, functions and access to Lightning APIs). The property is an item's attribute to be set with the value.
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 97: Line 99:
 |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 =====
 +Variables can be set from several places: from a Lightning Action "Set a variable",​ from a script or from Tasker.
 +
 +==== The Lightning Action "Set a variable"​ ====
 +This is an easy to use action that can be used as a shortcut or with events such as tap, long tap, swipe, etc.
 +This action is configured with two fields: the variable name (without $), and the value to assign to the variable.
 +Starting at Lightning v12.5b5 the value is evaluated as a JavaScript expression like in bindings, for more flexibility and reduced need of additional scripts when toggling states. If the expression is not a valid JavaScript expression, it is used as is.
 +Sample values with their result:
 +^ Value ^ Result^
 +|hello|The text '​hello'​|
 +|t+1|The text '​t+1'​|
 +|$t+1|Assuming the variable '​t'​ has no value yet, the numerical value 1, then 2 if set again, then 3, 4, 5...|
 +|hello+goodbye|The text "​hello+goodbye"​|
 +|"​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)|
 +|$t==400 ? 100 : 400|Toggle between 100 and 400 (if the variable '​t'​ has a numerical value or no value)|
 +|Math.cos($a)+Math.sin($b)|Computation using several variables and JavaScript math functions|
 +|var s="";​ for(var i=0; i<$t; i++) s+"​*";​ return s;|Build a text made of '​t'​ times the * character. Notice the use of '​return'​ in a multi statement expression|
 +
 +==== Setting a variable from script ====
 +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;>​
 +var editor = LL.getVariables().edit();​
 +editor.setBoolean("​a",​ true);
 +editor.setInteger("​b",​ 3);
 +editor.setFloat("​c",​ "​4.57"​);​
 +editor.commit();​
 +</​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 ====
 +Please refer to [[working_with_tasker#​setting_variables_inside_lightning_from_a_tasker_task|this link]].
bindings.1431591188.txt.gz ยท Last modified: 2015/05/14 08:13 by pierrox