TextLine.h 5.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /******************************************************************************/
  2. const_mem_addr STRUCT(TextLine , GuiObj) // Gui TextLine !! must be stored in constant memory address !!
  3. //{
  4. Bool kb_lit , // if highlight when has keyboard focus , default=true
  5. show_find; // if show find image when there's no text entered, default=false
  6. Str hint ; // hint displayed when there's no text entered, default=""
  7. Button reset ; // reset/clear button , default=created but hidden
  8. // manage
  9. TextLine& del ( ); // delete
  10. TextLine& create( C Str &text=S); // create
  11. TextLine& create(C Rect &rect, C Str &text=S) {create(text).rect(rect); return T;} // create
  12. TextLine& create(C TextLine &src ); // create from 'src'
  13. // get / set
  14. Bool password ()C; TextLine& password ( Bool on ); // get/set password mode, in password mode text characters will be displayed as '*' (the character can be changed using 'Gui.passwordChar' method), password mode additionally prevents copying text to the clipboard
  15. Int maxLength ()C {return _max_length;} TextLine& maxLength( Int max_length ); // get/set maximum allowed text length (-1=no limit), default=-1
  16. Int cursor ()C {return _edit.cur ;} TextLine& cursor ( Int position ); // get/set cursor position
  17. C Str& operator()()C {return _text ;} TextLine& set (C Str &text, SET_MODE mode=SET_DEFAULT); // get/set text
  18. TextLine& clear ( SET_MODE mode=SET_DEFAULT); // clear text
  19. Flt offset ()C {return _offset ;} // get horizontal offset currently used for displaying text
  20. C GuiSkinPtr& skin()C {return _skin ;} TextLine& 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 'reset' button
  21. GuiSkin* getSkin()C {return _skin ? _skin() : Gui.skin();} // get actual skin
  22. TextLine& 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) TextLine& 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) TextLine& 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 TextLine& rect(C Rect &rect ); C Rect& rect()C {return super::rect();} // set/get rectangle
  26. virtual TextLine& move(C Vec2 &delta); // move by delta
  27. // operations
  28. TextLine& selectNone (); // select no text
  29. TextLine& selectAll (); // select all text
  30. TextLine& selectExtNot(); // select all but extension
  31. // main
  32. 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
  33. virtual void update(C GuiPC &gpc); // update object
  34. virtual void draw (C GuiPC &gpc); // draw object
  35. #if EE_PRIVATE
  36. void adjustOffset() ;
  37. Bool showClear()C;
  38. Flt clientWidth()C;
  39. C Str& displayText()C; // returns "***" when in password mode, Warning: this is not thread-safe
  40. void zero() ;
  41. void call() ;
  42. void createReset() ;
  43. Bool setChanged(C Str &text, SET_MODE mode=SET_DEFAULT);
  44. Bool cursorChanged(Int position);
  45. void setTextInput()C;
  46. #endif
  47. ~TextLine() {del();}
  48. TextLine();
  49. #if !EE_PRIVATE
  50. private:
  51. #endif
  52. Bool _can_select, _func_immediate;
  53. Int _max_length;
  54. Flt _offset;
  55. Str _text;
  56. TextEdit _edit;
  57. GuiSkinPtr _skin;
  58. Ptr _func_user;
  59. void (*_func)(Ptr user);
  60. protected:
  61. virtual Bool save(File &f, CChar *path=null)C;
  62. virtual Bool load(File &f, CChar *path=null) ;
  63. NO_COPY_CONSTRUCTOR(TextLine);
  64. #if EE_PRIVATE
  65. friend struct ComboBox;
  66. #endif
  67. };
  68. /******************************************************************************/