code_uilistview.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //UIListView application source code
  2. 'use strict';
  3. var utils = require("Scripts/utils");
  4. exports.init = function(mylayout,mylogger) {
  5. var mlvw = mylayout.getWidget("UIListViewDemo"); // get the container
  6. if (mlvw !== null) {
  7. mylogger.setText( "UIListView : already initialized");
  8. return; // already initialized.
  9. }
  10. // note : the UIListView widget does not have a corresponding Turbobadger widget, its ALL Atomic.
  11. // so we have to build it in source code / scripting
  12. //
  13. // action functions
  14. //
  15. var myListview = new Atomic.UIListView(); // make a List...view
  16. myListview.id = "UIListViewDemo"; // tag it, in case we want to get it again later
  17. var lpx = new Atomic.UILayoutParams(); // size it just right
  18. lpx.width = 256;
  19. lpx.height = 256;
  20. lpx.minWidth = 256;
  21. lpx.minHeight = 256;
  22. lpx.maxWidth = 256;
  23. lpx.maxHeight = 256;
  24. myListview.layoutParams = lpx;
  25. var lower = mylayout.getWidget("uilistviewlower");
  26. var mylvc = mylayout.getWidget("listviewcontainer"); // get the container layout
  27. mylvc.addChildBefore(myListview, lower); // drop it in
  28. // OMG what the heck was he thinking!
  29. // there is no external way of converting a name to an itemLookup_ ???
  30. var rootsids = []; // now fill it up
  31. var id1 = myListview.addRootItem("root1", "", "root1");
  32. rootsids.push(id1);
  33. var id2 = myListview.addChildItem(id1, "rootish2", "", "root2");
  34. rootsids.push(id2);
  35. var id3 = myListview.addChildItem(id1, "rootish3", "", "root3");
  36. rootsids.push(id3);
  37. var id4 = myListview.addChildItem(id1, "rootish4", "", "root4");
  38. rootsids.push(id4);
  39. var id5 = myListview.addChildItem(id1, "rootish5", "", "root5");
  40. rootsids.push(id5);
  41. var nn;
  42. for ( nn=7; nn<55; nn++)
  43. rootsids.push( myListview.addChildItem(id2, "child " + nn, "", "child " + nn ) );
  44. myListview.setExpanded(id1,true);
  45. myListview.setExpanded(id2,false);
  46. //
  47. // widget event functions
  48. //
  49. myListview.subscribeToEvent("UIListViewSelectionChanged", function (ev) {
  50. var selectedId = myListview.selectedItemID; /// hmmm same as the refid...
  51. mylogger.setText( "UIListView event : " + myListview.id + " refid=" + ev.refid + " selected=" + ev.selected + " sid=" + selectedId );
  52. });
  53. //
  54. // support functions
  55. //
  56. var button1 = mylayout.getWidget("uilistviewcode");
  57. button1.onClick = function () {
  58. mylogger.setText( "UIListView support : " + button1.id + " was pressed ");
  59. utils.viewCode ( "Components/code_uilistview.js", mylayout );
  60. };
  61. var button2 = mylayout.getWidget("uilistviewlayout");
  62. button2.onClick = function () {
  63. mylogger.setText( "UIListView support : " + button2.id + " was pressed ");
  64. utils.viewCode ( "Scenes/layout_uilistview.ui.txt", mylayout );
  65. };
  66. };