//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Runtime.CompilerServices; using bs; namespace bs.Editor { /** @addtogroup GUI-Editor * @{ */ /// /// Editor GUI element that displays a textual input field and an optional label. /// public sealed class GUITextField : GUIElement { /// /// Triggered when the value in the field changes. /// public event Action OnChanged; /// /// Triggered whenever user confirms input. /// public event Action OnConfirmed; /// /// Value displayed by the field input box. /// public string Value { get { String value; Internal_GetValue(mCachedPtr, out value); return value; } set { Internal_SetValue(mCachedPtr, value); } } /// /// Checks does the element currently has input focus. Input focus means the element has an input caret displayed /// and will accept input from the keyboard. /// public bool HasInputFocus { get { bool value; Internal_HasInputFocus(mCachedPtr, out value); return value; } } /// /// Creates a new text field element with a label. /// /// Content to display on the label. /// Width of the title label in pixels. /// Determines should the input field accept multiple lines of text. /// Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUITextField(GUIContent title, int titleWidth = 100, bool multiline = false, string style = "", params GUIOption[] options) { Internal_CreateInstance(this, multiline, ref title, titleWidth, style, options, true); } /// /// Creates a new text field element without a label. /// /// Determines should the input field accept multiple lines of text. /// Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUITextField(bool multiline = false, string style = "", params GUIOption[] options) { GUIContent emptyContent = new GUIContent(); Internal_CreateInstance(this, multiline, ref emptyContent, 0, style, options, false); } /// /// Colors the element with a specific tint. /// /// Tint to apply to the element. public void SetTint(Color color) { Internal_SetTint(mCachedPtr, ref color); } /// /// Triggered by the runtime when the value of the text field changes. /// /// New value of the text field. private void Internal_DoOnChanged(String newValue) { if (OnChanged != null) OnChanged(newValue); } /// /// Triggered by the native interop object when the user confirms the input. /// private void Internal_DoOnConfirmed() { if (OnConfirmed != null) OnConfirmed(); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(GUITextField instance, bool multiline, ref GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetValue(IntPtr nativeInstance, out String value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetValue(IntPtr nativeInstance, String value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_HasInputFocus(IntPtr nativeInstance, out bool value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color); } /** @} */ }