x


Horizontal Line

Is there a way to draw an horizontal line using EditorGUI / EditorGUILayout?

alt text

more ▼

asked Feb 12 '12 at 09:15 PM

Veehmot gravatar image

Veehmot
542 14 20 26

As in a seperator?

Feb 12 '12 at 09:20 PM unluckyBastard

Yes, as in a separator.

Feb 12 '12 at 09:21 PM Veehmot

EditorGUILayout.Seperator(); try that

Feb 12 '12 at 09:22 PM unluckyBastard

That's behaves exactly like EditorGUILayout.Space()

Feb 12 '12 at 09:24 PM Veehmot
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Here is the solution that I use in my editor scripts:

static class CustomGUI {

    public static readonly GUIStyle splitter;

    static CustomGUI() {
        GUISkin skin = GUI.skin;

        splitter = new GUIStyle();
        splitter.normal.background = EditorGUIUtility.whiteTexture;
        splitter.stretchWidth = true;
        splitter.margin = new RectOffset(0, 0, 7, 7);
    }

    private static readonly Color splitterColor = EditorGUIUtility.isProSkin ? new Color(0.157f, 0.157f, 0.157f) : new Color(0.5f, 0.5f, 0.5f);

    // GUILayout Style
    public static void Splitter(Color rgb, float thickness = 1) {
        Rect position = GUILayoutUtility.GetRect(GUIContent.none, splitter, GUILayout.Height(thickness));

        if (Event.current.type == EventType.Repaint) {
            Color restoreColor = GUI.color;
            GUI.color = rgb;
            splitter.Draw(position, false, false, false, false);
            GUI.color = restoreColor;
        }
    }

    public static void Splitter(float thickness, GUIStyle splitterStyle) {
        Rect position = GUILayoutUtility.GetRect(GUIContent.none, splitterStyle, GUILayout.Height(thickness));

        if (Event.current.type == EventType.Repaint) {
            Color restoreColor = GUI.color;
            GUI.color = splitterColor;
            splitterStyle.Draw(position, false, false, false, false);
            GUI.color = restoreColor;
        }
    }

    public static void Splitter(float thickness = 1) {
        Splitter(thickness, splitter);
    }

    // GUI Style
    public static void Splitter(Rect position) {
        if (Event.current.type == EventType.Repaint) {
            Color restoreColor = GUI.color;
            GUI.color = splitterColor;
            splitter.Draw(position, false, false, false, false);
            GUI.color = restoreColor;
        }
    }

}
more ▼

answered Apr 13 '12 at 03:09 AM

numberkruncher gravatar image

numberkruncher
2.2k 37 46 59

Doesn't work for editor stuff (EditorGUILayout.Box() doesn't exist), which is what he asked, and what I'm looking for :s

Jan 09 at 03:37 PM Steven 1

@Steven-1 You can use GUILayout.Box for editor GUI's or alternatively GUI.skin.box.Draw :-)

Jan 09 at 03:52 PM numberkruncher

oh, really? didn't know :s thanks

Jan 09 at 04:05 PM Steven 1

how about just:

    GUILayout.Box("", new GUILayoutOption[]{GUILayout.ExpandWidth(true), GUILayout.Height(1)});

that works best for me

Jan 09 at 04:40 PM Steven 1

@Steven-1 You can simplify this to GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));. The most efficient approach is to use the GUI.skin.box.Draw method purely for render events however.

Jan 09 at 04:45 PM numberkruncher
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1732
x351
x175
x71

asked: Feb 12 '12 at 09:15 PM

Seen: 2398 times

Last Updated: Jan 09 at 04:58 PM