public static RectOffset Draw(this RectOffset current, string name = "RectOffset", bool compact = false, string key = null)
 {
     if (compact)
     {
         EditorGUILayout.BeginHorizontal();
         EditorUI.SetFieldSize(26);
         current.left = current.left.DrawInt(name);
         EditorUI.SetLayout(26);
         current.right  = current.right.DrawInt(null, null, false);
         current.top    = current.top.DrawInt(null, null, false);
         current.bottom = current.bottom.DrawInt(null, null, false);
         EditorUI.SetLayout(0);
         GUILayout.FlexibleSpace();
         EditorGUILayout.EndHorizontal();
         return(current);
     }
     if (name.ToTitleCase().ToLabel().DrawFoldout(key))
     {
         EditorGUI.indentLevel += 1;
         current.left           = current.left.DrawInt("Left");
         current.right          = current.right.DrawInt("Right");
         current.top            = current.top.DrawInt("Top");
         current.bottom         = current.bottom.DrawInt("Bottom");
         EditorGUI.indentLevel -= 1;
     }
     return(current);
 }
Example #2
0
        public static Type Draw <Type>(Func <Type> method, bool indention = true)
        {
            int indentValue = EditorGUI.indentLevel;

            indention = EditorUI.allowIndention && indention;
            if (EditorUI.space != 0)
            {
                GUILayout.Space(EditorUI.space);
            }
            if (!indention)
            {
                EditorGUI.indentLevel = 0;
            }
            bool wasChanged = GUI.changed;

            GUI.changed = false;
            Type value = (Type)method();

            EditorUI.lastChanged  = GUI.changed;
            EditorUI.anyChanged   = GUI.changed = GUI.changed || wasChanged;
            EditorGUI.indentLevel = indentValue;
            if (EditorUI.resetField)
            {
                EditorUI.SetFieldSize(EditorUI.resetFieldSize, false);
            }
            if (EditorUI.resetLayout)
            {
                EditorUI.ResetLayout();
            }
            return(value);
        }
        public static void Draw(this GUIStyle current, string key, bool compact = false, bool grouped = false, bool headers = false)
        {
            EditorGUILayout.BeginVertical();
            var styleKey     = key + "." + current.name;
            var styleFoldout = current.name.ToLabel().DrawFoldout(styleKey);

            if (styleFoldout)
            {
                var labelWidth = compact ? 140 : 0;
                EditorGUI.indentLevel += 1;
                EditorUI.SetFieldSize(-1, labelWidth, false);
                current.name = current.name.Draw("Name".ToLabel());
                Utility.SetPref <bool>(key + "." + current.name, true);
                if (compact && headers)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(140);
                    EditorUI.SetLayout(120);
                    "Text".ToLabel().DrawLabel(EditorStyles.boldLabel, false);
                    "Background".ToLabel().DrawLabel(EditorStyles.boldLabel, false);
                    EditorGUILayout.EndHorizontal();
                }
                foreach (var state in current.GetNamedStates())
                {
                    state.Value.Draw(state.Key, compact, styleKey + "." + state.Key);
                }
                current.border.Draw("Border", compact, key + ".Border");
                current.margin.Draw("Margin", compact, key + ".Margin");
                current.padding.Draw("Padding", compact, key + ".Padding");
                current.overflow.Draw("Overflow", compact, key + ".Overflow");
                if (!grouped || "Text".ToTitleCase().ToLabel().DrawFoldout(key + "Text"))
                {
                    current.DrawTextSettings(compact);
                }
                if (!grouped || "Position & Size".ToTitleCase().ToLabel().DrawFoldout(key + "Area"))
                {
                    current.imagePosition = current.imagePosition.Draw("Image Position").As <ImagePosition>();
                    current.contentOffset = current.contentOffset.DrawVector2("Content Offset");
                    current.fixedWidth    = current.fixedWidth.Draw("Fixed Width");
                    current.fixedHeight   = current.fixedHeight.Draw("Fixed Height");
                    current.stretchWidth  = current.stretchWidth.Draw("Stretch Width");
                    current.stretchHeight = current.stretchHeight.Draw("Stretch Height");
                }
                EditorUI.ResetFieldSize();
                EditorGUI.indentLevel -= 1;
            }
            EditorGUILayout.EndVertical();
        }