Материал из for iRidium developers
Перейти к: навигация, поиск
Эта страница является переводом страницы List API. Перевод выполнен на 100%.

Other languages:
English • ‎русский


IR.ITEM_LISTBOX

Methods used when working with dynamic lists: graphic items with the List type.

IR.CreateItem

сreate a List graphic item on the current page of the project. The page can be determined with the help of the IR.CurrentPage method. To create an item on some page you are required to apply the CreateItem method to the link to the Page or Popup object. The link is received with the help of the IR.GetItem method.

Синтаксис

IR.CreateItem(IR.ITEM_LISTBOX, name, X, Y, width, height);

на входе значение описание
name "Button 1" type: String
the item name, unique for the page
X 30 type: Number
the X coordinate
Y 40 type: Number
the Y coordinate
width 200 type: Number
the item width
height 500 type: Number
the item height
на выходе
Object [Object DialogItemPrototype] type: Object
the graphic item instance


Пример

IR.AddListener(IR.EVENT_START,0, function()
{
    var src = IR.CreateItem(IR.ITEM_LISTBOX,"List 1",30,40,200,500); 
    IR.Log(src) // [Object DialogItemPrototype]
});

To create a dialog item on a particular page apply .CreateItem to the link to the page or popup:

    var list_1 = IR.GetItem("Page 1").CreateItem(IR.ITEM_LISTBOX,"List 1",30,40,200,500); 
    IR.Log(list_1) // [Object DialogItemPrototype]  // create a list and get the link in one action

In the constructor you can see only basic item properties without which the item cannot be created. All items also have a set of additional properties and a set of properties characteristic for the selected item type. See the section Properties.


.CreateItem

create a new item of the List item. To create a list item you need to get the link to the List object with the help of the IR.GetItem method.

Синтаксис

list.CreateItem(item, subitem, {property: value, ...});

на входе значение описание
list IR.GetItem("Page 1").GetItem("Item 1") type: Object
the link to the list
item 0 type: Number
the list item beginning with 0
subitem 1 type: Number
the list subitem number (item in the list item); 0 - the item, 1...n - subitems by the order of creation in the editor
property Text type: String
the subitem property, the list is identical to the graphic item properties
value 'text' type: String, Number
the value to be written in the indicated property
на выходе
Object [Object DialogItemPrototype] type: Object
the graphic object instance


Пример

IR.AddListener(IR.EVENT_START, 0, function()
{
  var List_1 = IR.GetItem("Page 1").GetItem("List 1");
  List_1.CreateItem(0, 1, {Text: "Hello"}); 
});

You can use this method to edit item in List. Send the new property to the item that already exist to change this property


.DeleteItem

delete an item of the List item. In order to do that yoг need to receive the link to the List object with the help of the IR.GetItem method.

Syntax

list.DeleteItem(item);

input value description
list IR.GetItem("Page 1").GetItem("Item 1") type: Object
The link to the list
item 0 type: Number
the list item number beginning with 0
output

-


Sample

IR.AddListener(IR.EVENT_START, 0, function()
{
  var List = IR.GetItem("Page 1").GetItem("List 1");
  List.DeleteItem(0); // delete first point of list
});





.Clear

delete all items of the List item. In order to do that you need to get the link to the List object with the help of the IR.GetItem method.

Синтаксис

list.Clear();

на входе значение описание
list IR.GetItem("Page 1").GetItem("Item 1") type: Object
the link to the list
на выходе

-


Пример

IR.AddListener(IR.EVENT_START, 0, function()
{
  var List = IR.GetItem("Page 1").GetItem("List 1");
  List.Clear(); // clear list
});





.SetPosition

scroll the list to the indicated position. In order to do that you need to get the link to the List object with the help of the IR.GetItem method.

Синтаксис

list.SetPosition(item);

на входе значение описание
list IR.GetItem("Page 1").GetItem("Item 1") type: Object
the link to the list
item 0 type: Number
the item number beginning with 0
на выходе

-


Пример

IR.AddListener(IR.EVENT_START, 0, function()
{
  var List = IR.GetItem("Page 1").GetItem("List 1");
  List.SetPosition(12); // go to point
});

for scrolling the list to the indicated item:

  • the item had to exist
  • at the moment of command execution the list has to be seen - the page/popup containing the list has to be opened
  • it should be not less than 100 ms after creating a new list item - the command for scrolling will not be executed right after the command for creating a new list item.




Events

An event - a process forwarded to scripts with an identifier for monitoring.

A listener - it is a function which is executed if the event set for it is activated

Add a listener using the method IR.AddListener

IR.AddListener(event, input, action);
  • event - the identifier of the event monitored by the listener
  • input - the input parameter required for creating the listener. If there is not such parameter indicate 0
  • action - the unnamed function or the link to the named function in which the actions are performed



IR.EVENT_ITEM_SELECT

the identifier of the event which is activated when clicking on a list item. Get the link to the List object with the help of the IR.GetItem method.

Синтаксис

IR.AddListener(IR.EVENT_ITEM_SELECT, list, function, [pointer]);

на входе значение описание
list IR.GetItem("Page 1").GetItem("List 1") type: object
the link to the item - list
function function(item, subitem) {} type: function
the unnamed function or referring to the function
pointer - type: object
the pointer to the object which serves the function (optional)
на выходе
item 2 type: number
the list item which is clicked, beginning with 0
subitem 1 type: number
the list subitem which is clicked
  • 0 - the subitem
  • 1...n - the item on the subitem, in the order of displaying in the editor


Пример

IR.AddListener(IR.EVENT_ITEM_SELECT, IR.GetItem("Page 1").GetItem("List 1"), function(item, subitem) {
IR.Log("pressed "+item+" / "+subitem);
});





IR.EVENT_LIST_ITEM_CHANGE

the identifier of the event which is activated when pressing on the list, releasing or moving it (Press, Release и Move). The event provides access for reading and writing to all subitem properties. It considerably expands functions of lists. Get the link to the List with the method IR.GetItem;

Syntax

IR.AddListener(IR.EVENT_LIST_ITEM_CHANGE, list, function, [pointer]);

input value description
list IR.GetItem("Page 1").GetItem("List 1") type: object
the link to the item - list
function function(item, subitem, event_type, object) {} type: function
the unnamed function or referring to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output
item 2 type: number
the list item which is pressed beginning with 0
subitem 1 type: number
the list subitem which is pressed:
  • 0 - the subitem
  • 1...n - the item on the subitem, in the order of displaying in the editor
event_type 11 type: number
the type of the occurred event:
  • 11 - Press
  • 12 - Release
  • 13 - Move
object [Object DialogItemPrototype] type: object
the link to the list subitem which is changed. It provides access to subitem properties for reading and writing


Sample

var list = IR.GetItem("Page 1").GetItem("List 1");
IR.AddListener(IR.EVENT_LIST_ITEM_CHANGE, list, function(item, subitem, event_type, object) {
    if (event_type == 11)
    switch(object.Name)
    {
        case "Item 1":
            IR.Log("List Item: "+item+" Subitem: "+subitem+" Pressed");
        break;
        case "Item 2":
            IR.Log("List Item: "+item+" Subitem: "+subitem+" Pressed");
        break;
    }
});

the list of possible subitem properties (object) see in API iRidium. Pages and items
the tree of items parentage:

  • Page / Popup - the page/popup
    • List - the list
      • Item - the list item
        • Subitem - the list subitem




Properties

Properties of graphic items with the List type:

IR.GetItem(page/popup).GetItem(list).property

Template "Popup 1" type: string
enables you to set up or request a template for list subitems (the template is one of the project popups)
Direction 0 type: number
enables you to set up or request the direction of list scrolling:
  • 0 - vertical list
  • 1 - horizontal list
ItemsCount 24 type: number
enables you to request the number of list items
Filter "A" type: string
enables you to filter list items by their names (part of the name)
Enable true type: boolean
enables you to disable the possibility of scrolling the list manually, from the interface. At that the .SetPosition method will still work.
var list = IR.GetItem("Page 1").GetItem("List 1");
//** Template **//
IR.Log(list.Template); // "Popup 1"
list.Template = "Popup 2"; // change template if exist
//** Direction **//
IR.Log(list.Direction); // 1
list.Direction = 0;  // change direction
//** ItemsCount **//
IR.Log(list.ItemsCount); // 24
//** Filter **//
list.CreateItem(0, 0, {Text: "Curriculum", Name:"Curriculum"});
list.CreateItem(1, 0, {Text: "Privacy", Name: "Privacy"});  
list.Filter = "C"; // "Privacy" will be filtered out, "Curriculum" showed
IR.Log(list.Filter); // "C"
//** Enable **//
list.Enable = true; // list can be flipped manually
list.Enable = false; // list cannot be flipped manually


IR.ITEM_GOOD_LIST (beta)

Methods used when working with dynamic lists: graphic items with the "Good List" type. Good List is the new version of Listbox with the better possibilities for displaying of big number of items

IR.CreateItem

сreate a List graphic item on the current page of the project. The page can be determined with the help of the IR.CurrentPage method. To create an item on some page you are required to apply the CreateItem method to the link to the Page or Popup object. The link is received with the help of the IR.GetItem method.

Syntax

IR.CreateItem(IR.ITEM_GOOD_LIST, name, X, Y, width, height, infinity);

input value description
name "GList 1" type: String
the item name, unique for the page
X 30 type: Number
the X coordinate
Y 40 type: Number
the Y coordinate
width 200 type: Number
the item width
height 500 type: Number
the item height
infinity false type: Boolean
Whether the list is closed. If true, after the last item in the list, the list's starting items will be displayed
output
Object [Object DialogItemPrototype] type: Object
the graphic item instance


Sample

IR.AddListener(IR.EVENT_START,0, function()
{
    var GList = IR.CreateItem(IR.ITEM_GOOD_LIST, "GList 1", 20, 20, 250, 600, false); 
    IR.Log(GList) // [Object DialogItemPrototype]
});

To create a dialog item on a particular page apply .CreateItem to the link to the page or popup:

    var list_1 = IR.GetItem("Page 1").CreateItem(IR.ITEM_GOOD_LIST, "GList 1", 20, 20, 250, 600); 
    IR.Log(list_1) // [Object DialogItemPrototype]  // create list and get the link in one action

In the constructor you can see only basic item properties without which the item cannot be created. All items also have a set of additional properties and a set of properties characteristic for the selected item type. See the section Properties.


.Adapter

An object that allows you to work with individual list items to fill them, monitor the activity, modify properties, etc.

Syntax

GList.Adapter = {}

input value description

-

output

-


Sample

GList.Adapter = {
   total       :  8,  // total number of states after the list creation
   GetCount    :  function () {return this.total}, //makes "total" property available for external functions
   GetItem     :  function (in_nPos) {},  // function will be called separately for each created item of list. Here you can select template of item, change their properties. in_nPos - index of list item
   SetSelected :  function (in_oItem, in_bSelected) {} //  function will be called separately for each created item of list. It returns the link to list item as an object (popup) and the state of activity of this item - is it selected in list or not
}

An example of implementation, the list of methods and properties:

function good_list (list_item, template) 
{
   var l_list = list_item;
   var l_oTemp = IR.GetItem(template);
 
   l_list.Color = 0xFFFFFFFF;
   l_list.SelectMode = 1; // 0 - cannot select, 1 - one selected item, 1 - any number of items can be marked as selected  
   l_list.Direction = 1;  // 0 - horisontal from left to right, 1 - vertical from up to down
 
   l_list.Adapter = {
      //number of list items at start
      total: 8,   
 
      //function to count the number of list items
      GetCount : function ()  
      {   
   			return this.total;    
            //use as: IR.Log("Total number of items in list = " + l_oGList.Adapter.GetCount())
      }, 
 
      //function to work with list items    
      GetItem: function(in_nPos)  
      {   
         var l_oItem = l_oTemp.Clone("" + in_nPos);   // use popup as template of List item
         l_oItem.GetItem("Item_name").Text = in_nPos; // display the popup position at each list item
 
         // when press to popup in list
         IR.AddListener(IR.EVENT_ITEM_RELEASE, l_oItem, function () 
         {
            l_list.SetSelected(l_oItem);   // mark item as selected 	
   		}); 
 
         // when press to some item of popup in list
         IR.AddListener(IR.EVENT_ITEM_RELEASE, l_oItem.GetItem("Add"), function () 
         {
   		   l_list.Adapter.total += 1;   //add one more list item
            //l_list.Adapter.total -= 1;   //delete the last item of list
            l_list.Position = l_list.Adapter.total+1; // go to the last position of list         
            l_list.Update();   //update list when change the number of items in list from inside or outside
   		});
 
         return l_oItem;   //get object item
   	},
 
      //function to work with selected items
      SetSelected : function (in_oItem, in_bSelected)  
      {   
         if (in_bSelected == true) 
         {
            //IR.Log("selected > "+in_oItem.Name);
            in_oItem.GetItem("Selector").Value = 1;
         } else  in_oItem.GetItem("Selector").Value = 0;
      }     
   };
   return l_list;
}
 
var l_oGList1 = new good_list(IR.GetPage("Page 1").CreateItem(IR.ITEM_GOOD_LIST, "ConList", 16, 16, 320, 600), "Popup 1");
var l_oGList2 = new good_list(IR.GetPage("Page 1").CreateItem(IR.ITEM_GOOD_LIST, "ConList_2", 352, 16, 320, 600), "Popup 1");  
 
/***** List Of Methods
*
*  l_oGList1.SetSelected(l_oItem)                               // mark list position as selected
*  l_oGList1.Update()                                           // update list when change the number of items
*  IR.DeleteItem(l_oGList1)                                     // remove List object
*
*  l_oGList1.Adapter.GetCount()                                 // get total number of list positions
*  l_oGList1.Adapter.GetItem(4).GetItem("Item_name").Text       // get list position by index
*  l_oGList1.Adapter.GetItem("4").GetItem("Item_name").Text     // get list position by name
*  l_oGList1.Adapter.total                                      // get or change total number of list positions
*
*  l_oGList1.SelectMode                                         // 0 - cannot select, 1- one selected item, 1 - any number of items can be marked as selected
*  l_oGList1.Color                                              // color of List substate
*  l_oGList1.Direction                                          // 0 - horisontal from left to right, 1 - vertical from up to down
*  l_oGList1.Position                                           // set or get the current list position
*
*****/

SAMPLE


.SetSelected

mark the list item as a selected. The possibility of marking of items depends on .SelectMode property

Syntax

list.SetSelected(item-object);

input value description
list IR.GetItem("Page 1").GetItem("GList 1") type: Object
the link to list
item-object [Object DialogItemPrototype] type: object
the list item
output

-


Sample

var l_oTemp = IR.GetItem("Popup 1");
l_list.Adapter = {
      GetItem: function(in_nPos)  
      {   
         var l_oItem = l_oTemp.Clone("" + in_nPos);   // use popup as template of List item
         IR.AddListener(IR.EVENT_ITEM_RELEASE, l_oItem, function () 
         {
            l_list.SetSelected(l_oItem);   // mark item as selected on Release 	
   		}); 
      }   
}





.Update

to update the list. Used after changing the number of items in the list

Syntax

list.Update();

input value description

-

output

-


Sample

var l_oTemp = IR.GetItem("Popup 1");
l_list.Adapter = {
      GetItem: function(in_nPos)  
      {   
         var l_oItem = l_oTemp.Clone("" + in_nPos);   // use popup as template of List item
         IR.AddListener(IR.EVENT_ITEM_RELEASE, l_oItem, function () 
         {
            l_list.Adapter.total += 1;
            l_list.Update();  // update list if number of items has been changed
   		}); 
      }   
}





Properties

The properties of graphic items with the Good List type:


IR.GetItem(page/popup).GetItem(good_list).property


.SelectMode 1 type: number
control of possibility to select the item of list:
  • 0 - not possible to select item
  • 1- only one item can be selected at a time
  • 2- several items can be selected at a time
.Direction 0 type: number
allows you to set the direction of the list scrolling:
  • 0 - a horizontal list (from left to right)
  • 1 - a vertical list (from top to bottom)
.Position 10 type: number
Allows to set of get the current list position
.Color 0xFFFFFFFF type: RGBA
allows to change the background color of the list
.Adapter.total 24 type: number
allows to query the number of items in the list
.Adapter.Item.Subitem.Property type:
allows to access the properties of items and sub-items of a list when referring to items by name or ID (from zero). The sub-items you can call by name. The list of properties, see in GUI API: Properties of graphic elements and their States
.infinity false type: Boolean
Allows you to query whether the list is looped


Static List

Static List is a graphic item inside which you can scroll popups. it is used for creating menus controlled with the help of gestures.

Static List cannot be crated from JS but it is possible to add and remove popups from it, turn over to the needed place. For the moment it is not possible to determinate the current position of a Static List.

JS methods of Static List:

// get a link to the Static List as an object
var st_list = IR.GetItem("Page 1").GetItem("Static List Item 1") 
 
// methods
st_list.AddPopup("Popup 1") // add a popup to the end of Static List (by name)
st_list.RemovePopup("Popup 1") // remove a popup from the Static List (by name)
st_list.SetPosition(0) // set the position of the Static List by the index from 0
st_list.Clear() // clear the Static List (romove all popups)


.AddPopup

add the popup at the end of the list Static List. It is needed to get a reference to the Static List as an object using the method IR.GetItem.

Синтаксис

st_list.AddPopup(popup_name);

на входе значение описание
st_list IR.GetItem("Page 1").GetItem("Item 1") type: Object
link to Static List
popup_name "Popup 1" type: string
the name popup that will be added to the end of the list
на выходе

-


Пример

IR.AddListener(IR.EVENT_START, 0, function()
{
  var st_list = IR.GetItem("Page 1").GetItem("Static List 1");
  st_list.AddPopup("Popup 1");
});





.RemovePopup

remove the popup from the Static List by name. Remove by index is not supported. It is needed to get a reference to the Static List as an object using the method IR.GetItem.

Синтаксис

st_list.RemovePopup(popup_name);

на входе значение описание
st_list IR.GetItem("Page 1").GetItem("Item 1") type: Object
link to Static List
popup_name "Popup 1" type: string
the name popup that you need to remove from the list
на выходе

-


Пример

IR.AddListener(IR.EVENT_START, 0, function()
{
  var st_list = IR.GetItem("Page 1").GetItem("Static List 1");
  st_list.RemovePopup("Popup 1");
});





.SetPosition

move the Static List on a specified position by index. The index starts from 0.

Синтаксис

st_list.SetPosition(position);

на входе значение описание
st_list IR.GetItem("Page 1").GetItem("Item 1") type: Object
link to Static List
position 0 type: number
позиция, на которую требуется переместить список
на выходе

-


Пример

IR.AddListener(IR.EVENT_START, 0, function()
{
  var st_list = IR.GetItem("Page 1").GetItem("Static List 1");
  st_list.SetPosition(1);
});





.Clear

remove all popups from the Static List

Синтаксис

st_list.Clear();

на входе значение описание
st_list IR.GetItem("Page 1").GetItem("Item 1") type: Object
link to Static List
на выходе

-


Пример

IR.AddListener(IR.EVENT_START, 0, function()
{
  var st_list = IR.GetItem("Page 1").GetItem("Static List 1");
  st_list.Clear();
});