User Tools

Site Tools


script_properties_orientation_handler

====== About the script ====== * Purpose : change items properties and data upon orientation changes * Author : Pierre Hébert ====== How to use the script ====== Firstly, adjust the "data" object to your need. Configure the items you want to modify as well as their properties values according to the orientation. Secondly assign this script to desktop Portrait and Landscape orientation events, possibly also on Resume. ====== Script code ====== <sxh javascript> // A script to change items properties and data upon orientation changes // Assign to desktop events Portrait and Landscape, possibly also on Resume (need to detect the current orientation) // Select which items to modify, which properties with their values. // Name your items and use their name in tjis array (in this sample: item_a, item_b, item_c). var data = { "item_a": { "s.labelVisibility": { type: "boolean", portrait:true, landscape: false }, "s.iconVisibility": { type: "boolean", portrait:false, landscape: true }, }, "item_b": { "s.labelFontSize": { type:"float", portrait:16, landscape: 12 }, "s.labelFontColor": { type:"integer", portrait:0xffff0000, landscape: 0xff0000ff }, "label": { portrait: "this is portrait", landscape: "this is landscape" }, }, "item_c": { "visibility": { portrait:false, landscape: true }, }, }; var container = LL.getEvent().getContainer(); var orientation = LL.getEvent().getSource() == "PORTRAIT" ? "portrait" : "landscape"; for(var name in data) { var item = container.getItemByName(name); if(item != null) { var item_data = data[name]; var editor = null; for(var property in item_data) { var value = item_data[property][orientation]; if(value != null) { if(property=="visibility") { // not a property item.setVisibility(value); } else if(property=="label") { // not a property neither item.setLabel(value, true); } else { if(editor == null) { editor = item.getProperties().edit(); } // no reflection yet, need to specify the data type var type = item_data[property]["type"]; if(type=="boolean") { editor.setBoolean(property, value); } else if(type=="integer") { editor.setInteger(property, value); } else if(type=="float") { editor.setFloat(property, value); } } } } if(editor != null) { editor.commit(); } } } </sxh>

script_properties_orientation_handler.txt · Last modified: 2015/03/11 13:23 by pierrox