GUITextField.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// Editor GUI element that displays a textual input field and an optional label.
  8. /// </summary>
  9. public sealed class GUITextField : GUIElement
  10. {
  11. public delegate void OnChangedDelegate(String newValue);
  12. /// <summary>
  13. /// Triggered when the value in the field changes.
  14. /// </summary>
  15. public event OnChangedDelegate OnChanged;
  16. /// <summary>
  17. /// Value displayed by the field input box.
  18. /// </summary>
  19. public String Value
  20. {
  21. get
  22. {
  23. String value;
  24. Internal_GetValue(mCachedPtr, out value);
  25. return value;
  26. }
  27. set { Internal_SetValue(mCachedPtr, value); }
  28. }
  29. /// <summary>
  30. /// Creates a new text field element with a label.
  31. /// </summary>
  32. /// <param name="title">Content to display on the label.</param>
  33. /// <param name="titleWidth">Width of the title label in pixels.</param>
  34. /// <param name="multiline">Determines should the input field accept multiple lines of text.</param>
  35. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  36. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  37. /// default element style is used.</param>
  38. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  39. /// override any similar options set by style.</param>
  40. public GUITextField(GUIContent title, int titleWidth = 100, bool multiline = false, string style = "", params GUIOption[] options)
  41. {
  42. Internal_CreateInstance(this, multiline, title, titleWidth, style, options, true);
  43. }
  44. /// <summary>
  45. /// Creates a new text field element without a label.
  46. /// </summary>
  47. /// <param name="multiline">Determines should the input field accept multiple lines of text.</param>
  48. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  49. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  50. /// default element style is used.</param>
  51. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  52. /// override any similar options set by style.</param>
  53. public GUITextField(bool multiline = false, string style = "", params GUIOption[] options)
  54. {
  55. Internal_CreateInstance(this, multiline, null, 0, style, options, false);
  56. }
  57. /// <summary>
  58. /// Checks does the element currently has input focus. Input focus means the element has an input caret displayed
  59. /// and will accept input from the keyboard.
  60. /// </summary>
  61. /// <returns>True if the element has input focus.</returns>
  62. public bool HasInputFocus()
  63. {
  64. bool value;
  65. Internal_HasInputFocus(mCachedPtr, out value);
  66. return value;
  67. }
  68. /// <summary>
  69. /// Colors the element with a specific tint.
  70. /// </summary>
  71. /// <param name="color">Tint to apply to the element.</param>
  72. public void SetTint(Color color)
  73. {
  74. Internal_SetTint(mCachedPtr, color);
  75. }
  76. /// <summary>
  77. /// Triggered by the runtime when the value of the text field changes.
  78. /// </summary>
  79. /// <param name="newValue">New value of the text field.</param>
  80. private void DoOnChanged(String newValue)
  81. {
  82. if (OnChanged != null)
  83. OnChanged(newValue);
  84. }
  85. [MethodImpl(MethodImplOptions.InternalCall)]
  86. private static extern void Internal_CreateInstance(GUITextField instance, bool multiline, GUIContent title, int titleWidth,
  87. string style, GUIOption[] options, bool withTitle);
  88. [MethodImpl(MethodImplOptions.InternalCall)]
  89. private static extern void Internal_GetValue(IntPtr nativeInstance, out String value);
  90. [MethodImpl(MethodImplOptions.InternalCall)]
  91. private static extern void Internal_SetValue(IntPtr nativeInstance, String value);
  92. [MethodImpl(MethodImplOptions.InternalCall)]
  93. private static extern void Internal_HasInputFocus(IntPtr nativeInstance, out bool value);
  94. [MethodImpl(MethodImplOptions.InternalCall)]
  95. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  96. }
  97. }