ComboBox.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /******************************************************************************/
  2. enum COMBOBOX_FLAG // Combobox Flag
  3. {
  4. COMBOBOX_MOUSE_WHEEL=0x1, // if mouse wheel can change selection
  5. COMBOBOX_CONST_TEXT =0x2, // if don't change text value
  6. COMBOBOX_SET_CLAMP =0x4, // if calling 'set' with a value bigger than allowed, then clamp it to last value
  7. };
  8. /******************************************************************************/
  9. const_mem_addr STRUCT(ComboBox , Button) // Gui ComboBox !! must be stored in constant memory address !!
  10. //{
  11. Byte flag ; // COMBOBOX_FLAG, default=COMBOBOX_MOUSE_WHEEL
  12. Flt menu_align; // menu horizontal alignment (-1 .. 1), default=1, this value specifies on which side (left or right) the menu should be activated
  13. Menu menu ; // menu
  14. // manage
  15. ComboBox& del ( ); // delete
  16. ComboBox& create( ); // create empty
  17. ComboBox& create(C Rect &rect ) {return create(). rect(rect);} // create empty and set rectangle
  18. ComboBox& create( CChar8 *data[], Int elms) {return create().setData(data, elms) ;} // create from text array
  19. ComboBox& create(C Rect &rect, CChar8 *data[], Int elms) {return create().setData(data, elms).rect(rect);} // create from text array and set rectangle
  20. ComboBox& create( CChar *data[], Int elms) {return create().setData(data, elms) ;} // create from text array
  21. ComboBox& create(C Rect &rect, CChar *data[], Int elms) {return create().setData(data, elms).rect(rect);} // create from text array and set rectangle
  22. ComboBox& create( Node<MenuElm> &node) {return create().setData(node ) ;} // create from node of menu elements
  23. ComboBox& create(C Rect &rect, Node<MenuElm> &node) {return create().setData(node ).rect(rect);} // create from node of menu elements and set rectangle
  24. ComboBox& create(C ComboBox &src ); // create from 'src'
  25. // data
  26. ComboBox& clear(); // clear data
  27. ComboBox& setData(CChar8 *data[], Int elms, C MemPtr<Bool> &visible=null, Bool keep_cur=false) {menu.setData(data, elms, visible, keep_cur); return T;} // set columns and data from text array
  28. ComboBox& setData(CChar *data[], Int elms, C MemPtr<Bool> &visible=null, Bool keep_cur=false) {menu.setData(data, elms, visible, keep_cur); return T;} // set columns and data from text array
  29. ComboBox& setData(C Node<MenuElm> &node ) {menu.setData(node ); return T;} // set columns and data from node of menu elements
  30. ComboBox& setColumns(ListColumn *column, Int columns, Bool columns_hidden=true ) {menu.setColumns(column, columns, columns_hidden); return T;} // set list columns
  31. T1(TYPE) ComboBox& setData ( TYPE *data , Int elms , C MemPtr<Bool> &visible=null, Bool keep_cur=false) {menu.setData (data, elms, visible, keep_cur ); return T;} // set data from continuous memory
  32. T1(TYPE) ComboBox& setData ( Mems<TYPE> &mems , C MemPtr<Bool> &visible=null, Bool keep_cur=false) {menu.setData (mems, visible, keep_cur ); return T;} // set data from Mems
  33. ComboBox& setData (_Memc &memc , C MemPtr<Bool> &visible=null, Bool keep_cur=false) {menu.setData (memc, visible, keep_cur ); return T;} // set data from Memc
  34. ComboBox& setData (_Memb &memb , C MemPtr<Bool> &visible=null, Bool keep_cur=false) {menu.setData (memb, visible, keep_cur ); return T;} // set data from Memb
  35. ComboBox& setData (_Memx &memx , C MemPtr<Bool> &visible=null, Bool keep_cur=false) {menu.setData (memx, visible, keep_cur ); return T;} // set data from Memx
  36. ComboBox& setData (_Meml &meml , C MemPtr<Bool> &visible=null, Bool keep_cur=false) {menu.setData (meml, visible, keep_cur ); return T;} // set data from Meml
  37. ComboBox& setData (_Map &map , C MemPtr<Bool> &visible=null, Bool keep_cur=false) {menu.setData (map , visible, keep_cur ); return T;} // set data from Map
  38. // set / get
  39. Int visSel()C {return menu.list.absToVis(_abs_sel);} // get active visible selection
  40. Int absSel()C {return _abs_sel ;} // get active absolute selection
  41. ComboBox& set ( Int abs_sel , SET_MODE mode=SET_DEFAULT); Int operator()()C {return _abs_sel ;} // set/get active absolute selection, -1=none
  42. ComboBox& setText(C Str &text, Bool force, SET_MODE mode=SET_DEFAULT); // set active selection from text, if 'text' not found : -1 is set and text is set depending on 'force' (false: set(""), true: set(text))
  43. ComboBox& resetText( ); // reset text from active selection
  44. #if EE_PRIVATE
  45. ComboBox& setPath(C Str &start, C Str &end );
  46. #endif
  47. virtual ComboBox& rect (C Rect &rect ); C Rect& rect()C {return super::rect();} // set/get rectangle
  48. ComboBox& skin (C GuiSkinPtr &skin, Bool sub_objects=true ); C GuiSkinPtr& skin()C {return super::skin ;} // set/get skin override, default=null (if set to null then current value of 'Gui.skin' is used), 'sub_objects'=if additionally change the skin of sub-menus
  49. ComboBox& func(void (*func)(Ptr user), Ptr user=null, Bool immediate=false); // set function called when selection 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)
  50. T1(TYPE) ComboBox& func(void (*func)(TYPE *user), TYPE *user , Bool immediate=false) {return T.func((void(*)(Ptr))func, user, immediate);} // set function called when selection 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)
  51. T1(TYPE) ComboBox& func(void (*func)(TYPE &user), TYPE &user , Bool immediate=false) {return T.func((void(*)(Ptr))func, &user, immediate);} // set function called when selection 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)
  52. // main
  53. 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
  54. virtual void update(C GuiPC &gpc); // update object
  55. #if EE_PRIVATE
  56. void zero ();
  57. void call ();
  58. void setMenu ();
  59. void setParams();
  60. #endif
  61. ~ComboBox() {del();}
  62. ComboBox();
  63. #if !EE_PRIVATE
  64. private:
  65. #endif
  66. Bool _func_immediate;
  67. Int _abs_sel;
  68. Ptr _func_user;
  69. void (*_func)(Ptr user);
  70. protected:
  71. virtual Bool save(File &f, CChar *path=null)C;
  72. virtual Bool load(File &f, CChar *path=null) ;
  73. };
  74. /******************************************************************************/
  75. inline Int Elms(C ComboBox &combobox) {return Elms(combobox.menu);}
  76. /******************************************************************************/