Ejemplo n.º 1
0
 /// <summary>
 /// Prefix label to show above control.
 /// </summary>
 /// <param name="text">Text for label.</param>
 /// <param name="style">Style for prefix label.</param>
 public static void AbovePrefixLabel(string text, GUIStyle style)
 {
     using (var labelContent = ControlContent.Basic(text)) {
         Rect position = GUILayoutUtility.GetRect(labelContent, style);
         EditorGUI.HandlePrefixLabel(position, position, labelContent, 0, style);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets basic control content with label text, an image and optional tip text.
        /// </summary>
        /// <example>
        /// <code language="csharp"><![CDATA[
        /// using (var content = ControlContent.Basic(labelText, image, tipText)) {
        ///     // Do something with the content...
        /// }
        /// ]]></code>
        /// </example>
        /// <param name="labelText">Label text.</param>
        /// <param name="image">Image texture.</param>
        /// <param name="tipText">Tip text.</param>
        /// <returns>
        /// The control content.
        /// </returns>
        public static ControlContent Basic(string labelText, Texture image, string tipText = null)
        {
            ControlContent content = default(ControlContent);

            content.LabelContent    = SpawnGUIContent(labelText, image, tipText);
            content.TrailingTipText = !string.IsNullOrEmpty(tipText)
                ? tipText
                : null;

            return(content);
        }
Ejemplo n.º 3
0
        public static void TrailingTip(string tipText)
        {
            if (string.IsNullOrEmpty(tipText))
            {
                return;
            }

            using (var labelContent = ControlContent.Basic(tipText)) {
                Rect position = GUILayoutUtility.GetRect(labelContent, ExtraEditorStyles.Instance.TrailingTip);
                position.y -= 2;

                EditorGUI.LabelField(position, labelContent, ExtraEditorStyles.Instance.TrailingTip);
            }
        }
Ejemplo n.º 4
0
        public static bool IconButton(Rect position, bool visible, Texture2D iconNormal, Texture2D iconActive, GUIStyle style)
        {
            int  controlID = GUIUtility.GetControlID(s_IconButtonHint, FocusType.Passive);
            bool result    = false;

            position.height += 1;

            switch (Event.current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                // Do not allow button to be pressed using right mouse button since
                // context menu should be shown instead!
                if (GUI.enabled && Event.current.button != 1 && position.Contains(Event.current.mousePosition))
                {
                    GUIUtility.hotControl      = controlID;
                    GUIUtility.keyboardControl = 0;
                    Event.current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    result = position.Contains(Event.current.mousePosition);
                    Event.current.Use();
                }
                break;

            case EventType.Repaint:
                if (visible)
                {
                    bool isActive = GUIUtility.hotControl == controlID && position.Contains(Event.current.mousePosition);
                    using (var tempContent = ControlContent.Basic(isActive ? iconActive : iconNormal)) {
                        position.height -= 1;
                        style.Draw(position, tempContent, isActive, isActive, false, false);
                    }
                }
                break;
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets control content with label text, an image and trailing tip text that is
        /// either shown as a tooltip on the main content or as a trailing tip below the
        /// control content when <see cref="TrailingTipsVisible"/> is <c>true</c>.
        /// </summary>
        /// <example>
        /// <code language="csharp"><![CDATA[
        /// using (var content = ControlContent.WithTrailableTip(labelText, image, tipText)) {
        ///     // Do something with the content...
        ///     GUILayout.Label(content);
        ///
        ///     // The following will automatically display the trailing tip when the
        ///     // `ControlContent.TrailingTipsVisible` property is `true`.
        ///     ExtraEditorGUI.TrailingTip(content);
        /// }
        /// ]]></code>
        /// </example>
        /// <param name="labelText">Label text.</param>
        /// <param name="image">Image texture.</param>
        /// <param name="tipText">Tip text.</param>
        /// <returns>
        /// The control content.
        /// </returns>
        public static ControlContent WithTrailableTip(string labelText, Texture image, string tipText)
        {
            ControlContent content = default(ControlContent);

            if (TrailingTipsVisible)
            {
                content.LabelContent    = SpawnGUIContent(labelText, image, null);
                content.TrailingTipText = !string.IsNullOrEmpty(tipText)
                    ? tipText
                    : null;
            }
            else
            {
                content.LabelContent    = SpawnGUIContent(labelText, image, tipText);
                content.TrailingTipText = null;
            }

            return(content);
        }
Ejemplo n.º 6
0
 public static void TrailingTip(ControlContent content)
 {
     TrailingTip(content.TrailingTipText);
 }
Ejemplo n.º 7
0
 public static void ToggleLeft(SerializedProperty prop, string label)
 {
     using (var labelContent = ControlContent.Basic(label)) {
         ToggleLeft(prop, labelContent);
     }
 }