Tabs.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /******************************************************************************/
  2. enum TABS_LAYOUT : Byte
  3. {
  4. TABS_AUTO , // tabs will be set using auto-detection
  5. TABS_HORIZONTAL, // tabs will be set horizontally
  6. TABS_VERTICAL , // tabs will be set vertically
  7. TABS_NUM , // number of TABS_LAYOUT modes
  8. };
  9. /******************************************************************************/
  10. STRUCT(Tab , Button) // single Tab
  11. //{
  12. Tab& del( );
  13. Tab& create(C Str &text);
  14. Tab& create(C Tab &src ); // create from 'src'
  15. Tab& setCornerTab(Bool right, Bool top);
  16. Tab& text(C Str &text); C Str& text()C {return super::text;} // set/get Tab text
  17. #if EE_PRIVATE
  18. void addChild(GuiObj &child);
  19. void removeChild(GuiObj &child);
  20. friend struct Tabs;
  21. #endif
  22. #if !EE_PRIVATE
  23. private:
  24. #endif
  25. GuiObjChildren _children;
  26. protected:
  27. virtual void parentClientRectChanged(C Rect *old_client, C Rect *new_client);
  28. virtual Bool load(File &f, CChar *path=null);
  29. };
  30. /******************************************************************************/
  31. const_mem_addr STRUCT(Tabs , GuiObj) // Gui Tabs !! must be stored in constant memory address !!
  32. //{
  33. // manage
  34. Tabs& del ( ); // delete
  35. Tabs& create( CChar8 **text, Int num, Bool auto_size=false); // create
  36. Tabs& create( CChar **text, Int num, Bool auto_size=false); // create
  37. Tabs& create(C Rect &rect, Flt space, CChar8 **text, Int num, Bool auto_size=false) {return create(text, num).rect(rect, space, auto_size);} // create and set rectangle and space between tabs, 'auto_size'=if set tab sizes according to their name length
  38. Tabs& create(C Rect &rect, Flt space, CChar **text, Int num, Bool auto_size=false) {return create(text, num).rect(rect, space, auto_size);} // create and set rectangle and space between tabs, 'auto_size'=if set tab sizes according to their name length
  39. Tabs& create(C Tabs &src ); // create from 'src'
  40. // get / set
  41. Int tabs ( )C {return _tabs.elms( );} // get number of tabs
  42. Tab& tab (Int i) {return _tabs[i] ;} // get i-th tab
  43. C Tab& tab (Int i)C {return _tabs[i] ;} // get i-th tab
  44. Tabs& set (Int i, SET_MODE mode=SET_DEFAULT); Int operator()( )C {return _sel ;} // set/get active tab
  45. Tabs& toggle(Int i, SET_MODE mode=SET_DEFAULT); // toggle i-th tab
  46. Tabs& valid (Bool on ); Bool valid ( )C {return _valid ;} // set/get if one tab must be selected, if false then no tab can be selected as well, default=false
  47. Tabs& layout(TABS_LAYOUT layout ); TABS_LAYOUT layout ( )C {return _layout ;} // set/get tabs layout mode, default=TABS_AUTO
  48. virtual Tabs& desc (C Str &desc ); C Str& desc ( )C {return super::desc() ;} // set/get tabs description
  49. Flt space ( )C {return _space ;} // get tabs spacing
  50. Bool autoSize ( )C {return _auto_size ;} // get tabs auto size
  51. Tabs& skin (C GuiSkinPtr &skin ); C GuiSkinPtr& skin( )C {return _skin ;} // set/get skin override, default=null (if set to null then current value of 'Gui.skin' is used), changing this value will automatically change the skin of each tab
  52. GuiSkin* getSkin( )C {return _skin ? _skin() : Gui.skin();} // get actual skin
  53. Tabs& func(void (*func)(Ptr user), Ptr user=null, Bool immediate=false); // set function called when tab has changed, with 'user' as its parameter, 'immediate'=if call the function immediately when a change occurs (this will happen inside object update function where you cannot delete any objects) if set to false then the function will get called after all objects finished updating (there you can delete objects)
  54. T1(TYPE) Tabs& func(void (*func)(TYPE *user), TYPE *user , Bool immediate=false) {return T.func((void(*)(Ptr))func, user, immediate);} // set function called when tab has changed, with 'user' as its parameter, 'immediate'=if call the function immediately when a change occurs (this will happen inside object update function where you cannot delete any objects) if set to false then the function will get called after all objects finished updating (there you can delete objects)
  55. T1(TYPE) Tabs& func(void (*func)(TYPE &user), TYPE &user , Bool immediate=false) {return T.func((void(*)(Ptr))func, &user, immediate);} // set function called when tab has changed, with 'user' as its parameter, 'immediate'=if call the function immediately when a change occurs (this will happen inside object update function where you cannot delete any objects) if set to false then the function will get called after all objects finished updating (there you can delete objects)
  56. // operations
  57. T1(TYPE) Tabs& replaceClass() {_tabs.replaceClass<TYPE>(); return T;} // replace class of 'Tab'
  58. Tabs& rect(C Rect &rect, Flt space, Bool auto_size=false); // set rectangle and spacing between buttons, 'auto_size'=if set tab sizes according to their name length
  59. virtual Tabs& rect(C Rect &rect ); C Rect& rect()C {return super::rect();} // set/get rectangle
  60. virtual Tabs& move(C Vec2 &delta ); // move by delta
  61. Tab & New (C Str &text, Int i=-1); // add new tab at i-th position (-1=last)
  62. Tabs& remove( Int i ); // remove i-th tab
  63. // main
  64. virtual GuiObj* test (C GuiPC &gpc, C Vec2 &pos, GuiObj* &mouse_wheel); // test if 'pos' screen position intersects with the object, by returning pointer to object or its children upon intersection and null in case no intersection, 'mouse_wheel' may be modified upon intersection either to the object or its children or null
  65. virtual void update(C GuiPC &gpc); // update object
  66. virtual void draw (C GuiPC &gpc); // draw object
  67. #if EE_PRIVATE
  68. TABS_LAYOUT actualLayout()C;
  69. void setButtonSubType();
  70. void setParams();
  71. void setRect();
  72. void zero();
  73. void call(Bool sound);
  74. void removeChild(GuiObj &child);
  75. #endif
  76. ~Tabs() {del();}
  77. Tabs();
  78. #if !EE_PRIVATE
  79. private:
  80. #endif
  81. Bool _valid, _auto_size, _func_immediate;
  82. TABS_LAYOUT _layout, _actual_layout;
  83. Int _sel;
  84. Flt _space;
  85. Ptr _func_user;
  86. void (*_func)(Ptr user);
  87. GuiSkinPtr _skin;
  88. Memx<Tab> _tabs;
  89. protected:
  90. virtual Bool save(File &f, CChar *path=null)C;
  91. virtual Bool load(File &f, CChar *path=null) ;
  92. virtual void parentClientRectChanged(C Rect *old_client, C Rect *new_client);
  93. NO_COPY_CONSTRUCTOR(Tabs);
  94. };
  95. /******************************************************************************/
  96. inline Int Elms(C Tabs &tabs) {return tabs.tabs();}
  97. /******************************************************************************/