Adobe 65007312 Programming Guide - Page 173
Transforming data, Create multiple bindings to one key
UPC - 883919154398
View all Adobe 65007312 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 173 highlights
CHAPTER 9: Getting Started: A Tutorial Example Transforming data 173 Transforming data The very simple binding we created for the checkbox allows you to set and clear a data value by selected or deselecting the checkbox button. To show a more complex relationship between the UI and the data, we will add two radio buttons and a static text field. All three are bound to the same data key, but with transformations such that when you select one radio button, it deselects the other, and updates the text to show which is selected. Create multiple bindings to one key Use these step to populate a custom dialog with this new set of controls and create the data transformation. 1. Edit the LibraryMenuItem.lua file to create a new function, showCustomDialogWithTranform(): function MyHWLibraryItem.showCustomDialogWithTransform() -- body of function end 2. Within this function, make the function-context call you need for the property table: LrFunctionContext.callWithContext( "showCustomDialogWithTransform", function( context ) -- body of function end ) 3. In this context, create the observable table, and add a property named selectedButton, with an initial value: -- body of function local props = LrBinding.makePropertyTable( context ) props.selectedButton = "one" -- new property with initial value -- create view hierarchy 4. Now we will create a new view hierarchy for the dialog, whose controls are bound to this table. This is a slightly more complex hierarchy, where the root node is a column container, which has two rows. The rows contain the controls, two radio buttons and a text box: -- create view hierarchy local f = LrView.osFactory() -- get the view factory object local c = f:column { bind_to_object = props, -- all controls bound to our table spacing = f:control_spacing(), -- default spacing for the child rows f:row { -- first row contains radio buttons spacing = f:control_spacing(), -- use default spacing f:column { f:radio_button { title = "Button one", checked_value = "one", -- when control value matches this, -- the button is checked -- add value binding in next step },