TextBox.h 6.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /******************************************************************************/
  2. const_mem_addr STRUCT(TextBox , GuiObj) // Gui TextBox !! must be stored in constant memory address !!
  3. //{
  4. Bool kb_lit ; // if highlight when has keyboard focus , default=true
  5. Str hint ; // hint displayed when there's no text entered, default=""
  6. Button view ; // view button
  7. SlideBar slidebar[2]; // 2 SlideBars (0=horizontal, 1=vertical)
  8. // manage
  9. TextBox& del ( ); // delete
  10. TextBox& create( C Str &text=S); // create
  11. TextBox& create(C Rect &rect, C Str &text=S) {create(text).rect(rect); return T;} // create
  12. TextBox& create(C TextBox &src ); // create from 'src'
  13. // get / set
  14. Int maxLength ()C {return _max_length ;} TextBox& maxLength ( Int max_length ); // get/set maximum allowed text length (-1=no limit), default=-1
  15. Int cursor ()C {return _edit.cur ;} TextBox& cursor ( Int position ); // get/set cursor position
  16. Bool wordWrap ()C {return _word_wrap ;} TextBox& wordWrap ( Bool wrap ); // get/set word wrapping, default=true
  17. C Str& operator()()C {return _text ;} TextBox& set (C Str &text, SET_MODE mode=SET_DEFAULT ); // get/set text
  18. TextBox& clear ( SET_MODE mode=SET_DEFAULT ); // clear text
  19. Flt slidebarSize()C {return _slidebar_size;} TextBox& slidebarSize( Flt size ); // set/get slidebar size, default=0.05
  20. C GuiSkinPtr& skin()C {return _skin ;} TextBox& skin (C GuiSkinPtr &skin, Bool sub_objects=true); // get/set skin override, default=null (if set to null then current value of 'Gui.skin' is used), 'sub_objects'=if additionally change the skin of slidebars and view button
  21. GuiSkin* getSkin()C {return _skin ? _skin() : Gui.skin();} // get actual skin
  22. TextBox& func(void (*func)(Ptr user), Ptr user=null, Bool immediate=false); // set function called when text 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)
  23. T1(TYPE) TextBox& func(void (*func)(TYPE *user), TYPE *user , Bool immediate=false) {return T.func((void(*)(Ptr))func, user, immediate);} // set function called when text 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)
  24. T1(TYPE) TextBox& func(void (*func)(TYPE &user), TYPE &user , Bool immediate=false) {return T.func((void(*)(Ptr))func, &user, immediate);} // set function called when text 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)
  25. virtual TextBox& rect(C Rect &rect ); C Rect& rect()C {return super::rect();} // set/get rectangle
  26. virtual TextBox& move(C Vec2 &delta); // move by delta
  27. // operations
  28. TextBox& selectNone(); // select no text
  29. TextBox& selectAll (); // select all text
  30. TextBox& scrollX (Flt delta , Bool immediate=false) {slidebar[0].scroll (delta , immediate); return T;} // horizontal scroll by delta
  31. TextBox& scrollToX (Flt pos , Bool immediate=false) {slidebar[0].scrollTo (pos , immediate); return T;} // horizontal scroll to pos
  32. TextBox& scrollFitX(Flt min, Flt max, Bool immediate=false) {slidebar[0].scrollFit(min, max, immediate); return T;} // horizontal scroll to fit min..max range
  33. TextBox& scrollY (Flt delta , Bool immediate=false) {slidebar[1].scroll (delta , immediate); return T;} // vertical scroll by delta
  34. TextBox& scrollToY (Flt pos , Bool immediate=false) {slidebar[1].scrollTo (pos , immediate); return T;} // vertical scroll to pos
  35. TextBox& scrollFitY(Flt min, Flt max, Bool immediate=false) {slidebar[1].scrollFit(min, max, immediate); return T;} // vertical scroll to fit min..max range
  36. // main
  37. 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
  38. virtual void update(C GuiPC &gpc); // update object
  39. virtual void draw (C GuiPC &gpc); // draw object
  40. #if EE_PRIVATE
  41. void zero();
  42. void call();
  43. void setButtons();
  44. void setParent();
  45. void setParams();
  46. Bool setChanged(C Str &text, SET_MODE mode=SET_DEFAULT);
  47. Bool cursorChanged(Int position);
  48. void moveCursor(Int lines, Int pages);
  49. void setVirtualSize();
  50. void setTextInput ()C;
  51. Flt clientWidth ()C {return _crect.w () ;} // get client width
  52. Flt clientHeight()C {return _crect.h () ;} // get client height
  53. Vec2 clientSize ()C {return _crect.size () ;} // get client size
  54. C Rect& clientRect ()C {return _crect ;} // get client rectangle
  55. Flt virtualWidth ()C {return slidebar[0].lengthTotal() ;} // get virtual width
  56. Flt virtualHeight()C {return slidebar[1].lengthTotal() ;} // get virtual height
  57. Vec2 virtualSize ()C {return Vec2(virtualWidth(), virtualHeight());} // get virtual size
  58. #endif
  59. ~TextBox() {del();}
  60. TextBox();
  61. #if !EE_PRIVATE
  62. private:
  63. #endif
  64. Bool _word_wrap, _can_select, _func_immediate;
  65. Int _max_length;
  66. Flt _slidebar_size;
  67. Str _text;
  68. TextEdit _edit;
  69. Ptr _func_user;
  70. void (*_func)(Ptr user);
  71. Rect _crect;
  72. GuiSkinPtr _skin;
  73. protected:
  74. virtual Bool save(File &f, CChar *path=null)C;
  75. virtual Bool load(File &f, CChar *path=null) ;
  76. NO_COPY_CONSTRUCTOR(TextBox);
  77. };
  78. /******************************************************************************/