textfield.adoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. = textfield
  2. :revnumber: 2.0
  3. :revdate: 2020/07/25
  4. == TextField Class
  5. Textfields are single line text input fields, that provide the following functionality:
  6. * Caret & Text Range
  7. * Mouse select
  8. * Keyboard nav using:
  9. ** arrows (nav by letter)
  10. ** SHIFT+arrows (text range by latter)
  11. ** CTRL+arrows (nav by word)
  12. ** SHIFT+CTRL+arrows (text range by word)
  13. ** etc.
  14. * Cut & Paste
  15. [NOTE]
  16. ====
  17. This control is still a work in progress and will be updated as either time permits or issues arise. There is a known issue with the Cut & Paste function as of right now and it has been disabled.
  18. ====
  19. TextFields provide the standard 3 constructors as shown in the xref:gui/tonegodgui/quickstart.adoc[Quick Start Guide].
  20. *Constructor 1:*
  21. [source,java]
  22. ----
  23. /** Parameters:
  24. * Screen screen,
  25. * String UID,
  26. * Vector2f position
  27. */
  28. TextField text = new TextField(screen, "text", new Vector2f(15, 15));
  29. ----
  30. *Constructor 2:*
  31. [source,java]
  32. ----
  33. /** Additional Parameter:
  34. * Vector2f dimensions */
  35. TextField text = new TextField(screen, "text", new Vector2f(15, 15),
  36. new Vector2f(150, 25)
  37. );
  38. ----
  39. *Constructor 3:*
  40. [source,java]
  41. ----
  42. /** Additional Parameters:
  43. * Vector4f resizeBorders,
  44. * String defaultImg
  45. */
  46. TextField text = new TextField(screen, "text", new Vector2f(15, 15), new Vector2f(150, 25),
  47. new Vector4f(3,3,3,3),
  48. "tonegod/gui/style/def/TextField/text_field_x.png"
  49. );
  50. ----
  51. === Validations & Rules
  52. TextFields can be set to a specific Type using:
  53. [source,java]
  54. ----
  55. text.setType(TextField.Type type);
  56. ----
  57. [cols="2", options="header"]
  58. |===
  59. a| Rule
  60. a| Description
  61. a| Type.DEFAULT
  62. a| Accept all characters
  63. a| Type.ALPHA
  64. a| Accept only lower case, uppercase alpha character + spacebar
  65. a| Type.ALPHA_NOSPACE
  66. a| Accept only lower case, uppercase alpha character - no spacebar
  67. a| Type.NUMERIC
  68. a| Accept only numeric values + decimal
  69. a| Type.ALPHANUMERIC
  70. a| Apply both ALPHA and NUMERIC rules
  71. a| Type.ALPHANUMERIC_NOSPACE
  72. a| Apply both ALPHA_NOSPACE and NUMERIC rules
  73. a| Type.EXCLUDE_SPECIAL
  74. a| Exclude all spacial characters
  75. a| Type.EXCLUDE_CUSTOM
  76. a| Exclude all user defined character (see below)
  77. a| Type.INCLUDE_CUSTOM
  78. a| Accept only user defined characters (see below)
  79. |===
  80. To define a custom validation for Type.EXCLUDE_CUSTOM or Type.INCLUDE_CUSTOM, use the following method:
  81. [source,java]
  82. ----
  83. text.setCustomValidation("Character List to include/exclude");
  84. ----
  85. You can also limit the number of characters the TextField will accept using:
  86. [source,java]
  87. ----
  88. text.setMaxLimit(int maxLimit);
  89. ----
  90. You can force upper and lower case by using:
  91. [source,java]
  92. ----
  93. text.setForceUpperCase(boolean forceUpperCase);
  94. text.setForceLowerCase(boolean forceLowerCase);
  95. ----
  96. === Methods specific to the TextField class:
  97. [source,java]
  98. ----
  99. // Get the TextField text
  100. text.getText();
  101. // Set the TextField text !IMPORTANT! setTextFieldText is now @Deprecated, use the following instead:
  102. text.setText(String s);
  103. // Retrieve numeric values (all numeric parsers throw NumberFormatException
  104. text.parseInt();
  105. text.parseFloat();
  106. text.parseShort();
  107. text.parseDouble();
  108. text.parseLong();
  109. ----
  110. === Hooks:
  111. [source,java]
  112. ----
  113. public void controlKeyPressHook(KeyInputEvent evt, String text) { }
  114. ----