code_uitabcontainer.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // UITabContainer application source code
  2. 'use strict';
  3. var utils = require("Scripts/utils");
  4. exports.init = function(mylayout,mylogger) {
  5. var tb = mylayout.getWidget("UITabContainerDemo");
  6. tb.setCurrentPage(0); // fix or it looks like crap
  7. //
  8. // widget event functions
  9. //
  10. tb.subscribeToEvent( "WidgetEvent", function (ev) {
  11. if ( ev.type == Atomic.UI_EVENT_TYPE_TAB_CHANGED && tb == ev.target ) {
  12. mylogger.setText( "UITabContainer event : " + tb.id + " UI_EVENT_TYPE_TAB_CHANGED to " + tb.getCurrentPage() + " id: " + tb.getCurrentPageWidget().id);
  13. }
  14. });
  15. //
  16. // action functions
  17. //
  18. var button1 = mylayout.getWidget("uitabcontainerremove");
  19. button1.onClick = function () {
  20. mylogger.setText( "UITabContainer action : " + button1.id + " was pressed ");
  21. var current = tb.getCurrentPage();
  22. tb.deletePage(current);
  23. };
  24. var button2 = mylayout.getWidget("uitabcontaineradd");
  25. button2.onClick = function () {
  26. mylogger.setText( "UITabContainer action : " + button2.id + " was pressed ");
  27. tb.addTabPageFile("New File", "Scenes/sheet.ui.txt" );
  28. };
  29. var button3 = mylayout.getWidget("uitabcontainermake");
  30. button3.onClick = function () {
  31. mylogger.setText( "UITabContainer action : " + button3.id + " was pressed ");
  32. var lo = new Atomic.UILayout();
  33. lo.setLayoutConfig ( "YAGAC" ); // YACAC!
  34. var myeditfield = new Atomic.UIEditField();
  35. myeditfield.setGravity( Atomic.UI_GRAVITY_ALL);
  36. myeditfield.setMultiline(true);
  37. var filex = Atomic.cache.getFile("Components/code_uitabcontainer.js");
  38. var textx = filex.readText();
  39. filex.close();
  40. myeditfield.text = textx;
  41. var myfont = new Atomic.UIFontDescription(); // put in a coder font
  42. myfont.setSize(16);
  43. myfont.setId("Vera");
  44. myeditfield.setFontDescription (myfont);
  45. lo.addChild (myeditfield);
  46. tb.addTabPageWidget("New Code", lo);
  47. };
  48. var button0 = mylayout.getWidget("uitabcontainerundock");
  49. button0.onClick = function () {
  50. mylogger.setText( "UITabContainer action : " + button0.id + " was pressed ");
  51. var current = tb.getCurrentPage();
  52. tb.undockPage(current);
  53. };
  54. var button00 = mylayout.getWidget("uitabcontainerredock");
  55. button00.onClick = function () {
  56. mylogger.setText( "UITabContainer action : " + button00.id + " was pressed ");
  57. if ( !tb.dockWindow ( "tab1" ) )
  58. if ( !tb.dockWindow ( "tab2" ) )
  59. if ( !tb.dockWindow ( "tab3" ) )
  60. if ( !tb.dockWindow ( "New File" ) )
  61. if ( !tb.dockWindow ( "New Code" ) )
  62. mylogger.setText( "UITabContainer action : no more windows to dock.");
  63. };
  64. //
  65. // support functions
  66. //
  67. var button4 = mylayout.getWidget("uitabcontainercode");
  68. button4.onClick = function () {
  69. mylogger.setText( "UITabContainer support : " + button4.id + " was pressed ");
  70. utils.viewCode ( "Components/code_uitabcontainer.js", mylayout );
  71. };
  72. var button5 = mylayout.getWidget("uitabcontainerlayout");
  73. button5.onClick = function () {
  74. mylogger.setText( "UITabContainer support : " + button5.id + " was pressed ");
  75. utils.viewCode ( "Scenes/layout_uitabcontainer.ui.txt", mylayout );
  76. };
  77. };