//********************************** 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 floating point input field and an optional label. /// public sealed class GUIFloatField : 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 float Value { get { return Internal_GetValue(mCachedPtr); } set { Internal_SetValue(mCachedPtr, value); } } /// /// Minimum change of the field. /// public float Step { get { return Internal_GetStep(mCachedPtr); } set { Internal_SetStep(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 { return Internal_HasInputFocus(mCachedPtr); } } /// /// Creates a new float field element with a label. /// /// Content to display on the label. /// Width of the title label in pixels. /// 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 GUIFloatField(GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options) { Internal_CreateInstance(this, ref title, titleWidth, style, options, true); } /// /// Creates a new float field element without a label. /// /// 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 GUIFloatField(string style = "", params GUIOption[] options) { GUIContent emptyContent = new GUIContent(); Internal_CreateInstance(this, 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); } /// /// Sets a range that will input field values will be clamped to. Set to large negative/positive values if clamping /// is not required. /// /// Minimum boundary of the range to clamp values to. /// Maximum boundary of the range to clamp values to. public void SetRange(float min, float max) { Internal_SetRange(mCachedPtr, min, max); } /// /// Triggered by the runtime when the value of the float field changes. /// /// New value of the float field. private void Internal_DoOnChanged(float 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(GUIFloatField instance, ref GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle); [MethodImpl(MethodImplOptions.InternalCall)] private static extern float Internal_GetValue(IntPtr nativeInstance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern float Internal_SetValue(IntPtr nativeInstance, float value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Internal_HasInputFocus(IntPtr nativeInstance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetRange(IntPtr nativeInstance, float min, float max); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetStep(IntPtr nativeInstance, float step); [MethodImpl(MethodImplOptions.InternalCall)] private static extern float Internal_GetStep(IntPtr nativeInstance); } /** @} */ }