示例#1
0
        public static bool FoldoutEx(EditorDataEntry state, GUIStyle buttonStyle, GUIContent label, GUIStyle labelStyle, Action <bool> onStateChanged = null)
        {
            GUILayout.BeginHorizontal();
            {
                var  buttonSize    = labelStyle.CalcHeight(label, Screen.width);
                bool expandPressed = GUILayout.Button(MakeLabel(state.Bool ? "-" : "+"), buttonStyle, GUILayout.Width(20.0f), GUILayout.Height(buttonSize));
                GUILayout.Label(label, labelStyle, GUILayout.ExpandWidth(true));
                if (expandPressed ||
                    (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) &&
                     Event.current.type == EventType.MouseDown &&
                     Event.current.button == 0))
                {
                    state.Bool = !state.Bool;

                    if (onStateChanged != null)
                    {
                        onStateChanged.Invoke(state.Bool);
                    }

                    if (!expandPressed)
                    {
                        GUIUtility.ExitGUI();
                    }
                }
            }
            GUILayout.EndHorizontal();

            return(state.Bool);
        }
示例#2
0
文件: GUI.cs 项目: Hengle/AGXUnity
        public static bool FoldoutEx(EditorDataEntry state, GUIStyle buttonStyle, GUIContent label, GUIStyle labelStyle, Action <bool> onStateChanged = null)
        {
            GUILayout.BeginHorizontal();
            {
                var  buttonSize    = labelStyle.CalcHeight(label, Screen.width);
                bool expandPressed = GUILayout.Button(MakeLabel(state.Bool ? "-" : "+"),
                                                      buttonStyle,
                                                      GUILayout.Width(20.0f),
                                                      GUILayout.Height(buttonSize));
                GUILayout.Label(label, labelStyle, GUILayout.ExpandWidth(true));
                bool labelPressed = (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) &&
                                     Event.current.type == EventType.MouseDown &&
                                     Event.current.button == 0);
                if (expandPressed || labelPressed)
                {
                    state.Bool = !state.Bool;

                    // Clicked label - flag used event for the GUI to respond. When
                    // the user presses the button it seems like the button implementation
                    // handles the event.
                    if (labelPressed)
                    {
                        Event.current.Use();
                    }

                    if (onStateChanged != null)
                    {
                        onStateChanged.Invoke(state.Bool);
                    }

                    if (!expandPressed)
                    {
                        GUIUtility.ExitGUI();
                    }
                }
            }
            GUILayout.EndHorizontal();

            return(state.Bool);
        }
示例#3
0
文件: GUI.cs 项目: Hengle/AGXUnity
 public static bool Foldout(EditorDataEntry state, GUIContent label, GUISkin skin, Action <bool> onStateChanged = null)
 {
     return(FoldoutEx(state, skin.button, label, skin.label, onStateChanged));
 }