code_uitabcontainer.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // UITabContainer application source code
  2. using System;
  3. using AtomicEngine;
  4. public class code_uitabcontainer : CSComponent {
  5. public void Setup( UIWidget layout )
  6. {
  7. var dest = new AtomicEngine.Vector<AtomicEngine.UIWidget>();
  8. layout.SearchWidgetClass( "TBButton", dest );
  9. for (var ii = 0; ii < dest.Size; ii++) {
  10. dest[ii].SubscribeToEvent<WidgetEvent> (dest [ii], HandleUitabcontainerEvent );
  11. }
  12. UITabContainer demo = (UITabContainer)layout.GetWidget ("UITabContainerDemo");
  13. if ( !demo.Equals(null)) {
  14. demo.SetCurrentPage(0);
  15. //spammy demo.SubscribeToEvent<WidgetEvent>( HandleAllTabcontainerEvent );
  16. }
  17. }
  18. private static void HandleAllTabcontainerEvent ( WidgetEvent ev )
  19. {
  20. UIWidget widget = (UIWidget)ev.Target;
  21. if ( widget.Equals(null)) return;
  22. if (widget.GetId() == "UITabContainerDemo" && ev.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_TAB_CHANGED ) {
  23. UITabContainer tcx = (UITabContainer)widget; // check the focus & stuff, or it gets a little spammy
  24. AtomicMain.AppLog( "UITabContainer event : " + widget.GetId() + " UI_EVENT_TYPE_TAB_CHANGED to " + tcx.GetCurrentPage().ToString()
  25. + " id: " + tcx.GetCurrentPageWidget().GetId() );
  26. }
  27. }
  28. private static void HandleUitabcontainerEvent ( WidgetEvent ev )
  29. {
  30. UIWidget widget = (UIWidget)ev.Target;
  31. string refid = (string)ev.RefID;
  32. if ( widget.Equals(null)) return;
  33. if ( ev.Type == UI_EVENT_TYPE.UI_EVENT_TYPE_CLICK) {
  34. if (widget.GetId() == "uitabcontainercode" ) {
  35. AtomicMain.AppLog( "UITabContainer support : " + widget.GetId() + " was pressed " );
  36. AtomicMain.ViewCode ( "Components/code_uitabcontainer.cs", widget.GetParent() );
  37. }
  38. if (widget.GetId() == "uitabcontainerlayout" ) {
  39. AtomicMain.AppLog( "UITabContainer support : " + widget.GetId() + " was pressed ");
  40. AtomicMain.ViewCode ( "Scenes/layout_uitabcontainer.ui.txt", widget.GetParent() );
  41. }
  42. if (widget.GetId() == "uitabcontainerremove" ) {
  43. AtomicMain.AppLog( "UITabContainer action : " + widget.GetId() + " was pressed ");
  44. UITabContainer tcx = (UITabContainer)widget.FindWidget("UITabContainerDemo");
  45. int current = tcx.GetCurrentPage();
  46. tcx.DeletePage(current);
  47. }
  48. if (widget.GetId() == "uitabcontaineradd" ) {
  49. AtomicMain.AppLog( "UITabContainer action : " + widget.GetId() + " was pressed ");
  50. UITabContainer tcx = (UITabContainer)widget.FindWidget("UITabContainerDemo");
  51. tcx.AddTabPageFile("New File", "Scenes/sheet.ui.txt" );
  52. }
  53. if (widget.GetId() == "uitabcontainermake" ) {
  54. AtomicMain.AppLog( "UITabContainer action : " + widget.GetId() + " was pressed ");
  55. var cache = GetSubsystem<ResourceCache>();
  56. UITabContainer tcx = (UITabContainer)widget.FindWidget("UITabContainerDemo");
  57. UILayout lo = new UILayout();
  58. lo.SetLayoutConfig ( "YAGAC" ); // YACAC!
  59. UIEditField myeditfield = new UIEditField();
  60. myeditfield.SetGravity( UI_GRAVITY.UI_GRAVITY_ALL);
  61. myeditfield.SetMultiline(true);
  62. File filex = cache.GetFile("Components/code_uitabcontainer.cs");
  63. String textx = filex.ReadText();
  64. filex.Close();
  65. myeditfield.SetText(textx);
  66. UIFontDescription myfont = new UIFontDescription(); // put in a coder font
  67. myfont.SetSize(16);
  68. myfont.SetId("Vera");
  69. myeditfield.SetFontDescription (myfont);
  70. lo.AddChild (myeditfield);
  71. tcx.AddTabPageWidget("New Code", lo);
  72. }
  73. if (widget.GetId() == "uitabcontainerundock" ) {
  74. AtomicMain.AppLog( "UITabContainer action : " + widget.GetId() + " was pressed ");
  75. UITabContainer tcx = (UITabContainer)widget.FindWidget("UITabContainerDemo");
  76. int current = tcx.GetCurrentPage();
  77. tcx.UndockPage(current);
  78. }
  79. if (widget.GetId() == "uitabcontainerredock" ) {
  80. AtomicMain.AppLog( "UITabContainer action : " + widget.GetId() + " was pressed ");
  81. UITabContainer tcx = (UITabContainer)widget.FindWidget("UITabContainerDemo");
  82. if ( !tcx.DockWindow ( "tab1" ) )
  83. if ( !tcx.DockWindow ( "tab2" ) )
  84. if ( !tcx.DockWindow ( "tab3" ) )
  85. if ( !tcx.DockWindow ( "New File" ) )
  86. if ( !tcx.DockWindow ( "New Code" ) )
  87. AtomicMain.AppLog( "UITabContainer action : no more windows to dock.");
  88. }
  89. }
  90. }
  91. }