- Home /
Horizontal Line
Is there a way to draw an horizontal line using EditorGUI / EditorGUILayout?
It worked for me! that little extra space is just fine!
Answer by sirjoan620 · Jan 12, 2017 at 01:32 PM
Simple and better solution:
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
Update 20.01.2020: Also you can use NaughtyAttributes' updated version(v2.0.0). That library has an HorizontalLine
attribute like in the example.
Do you have something similarly simple for a vertical line?
Answer by Glurth · Sep 30, 2015 at 05:16 AM
I like using EditorGUILayout, this worked well...
EditorGUILayout.TextArea("",GUI.skin.horizontalSlider);
This is actually the simplest way to go i feel. I also like that it is a visually strong separation.
You can prevent the cursor from being able to select the line by using LabelField ins$$anonymous$$d of TextArea :)
Answer by numberkruncher · Apr 13, 2012 at 03:09 AM
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;
}
}
}
Doesn't work for editor stuff (EditorGUILayout.Box() doesn't exist), which is what he asked, and what I'm looking for :s
@Steven-1 You can use GUILayout.Box
for editor GUI's or alternatively GUI.skin.box.Draw
:-)
how about just:
GUILayout.Box("", new GUILayoutOption[]{GUILayout.ExpandWidth(true), GUILayout.Height(1)});
that works best for me
@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.
Answer by scadapop · Nov 26, 2014 at 03:48 PM
Ok so it might be a bit ugly but :
public void displaySeparator()
{
GUILayout.Label("_________________________________________________________________________________________________________________________________________________________________________");
}
Ultimately this is what I picked, but added a \n to the end of the text. Works like a charm.
Used this but added this to center the line a bit:
GUIStyle st = new GUIStyle(GUI.skin.label);
Vector2 coff = st.contentOffset;
coff.y -= 5;
st.contentOffset = coff;
GUILayout.Label("_________________________________________", st);
Answer by skalev · Oct 19, 2013 at 06:28 AM
I just found the full solution to this.
Using @Steven 1 method, but creating a custom gui skin, that setts all paddings to 1.
So first create a class that holds the custom style
//Class to hold custom gui styles
public static class MyGUIStyles
{
private static GUIStyle m_line = null;
//constructor
static LOGDGUIStyles()
{
m_line = new GUIStyle("box");
m_line.border.top = m_line.border.bottom = 1;
m_line.margin.top = m_line.margin.bottom = 1;
m_line.padding.top = m_line.padding.bottom = 1;
}
public static GUIStyle EditorLine
{
get { return m_line; }
}
}
Then just call:
GUILayout.Box(GUIContent.none, GUIStyles.EditorLine , GUILayout.ExpandWidth(true), GUILayout.Height(1f));
make sure you use EditorGUIUtility.LookLikeInspector(); before hand
I took this. But you may want to set the left&right to 0, since there's 1 pixel space on both side of the line.
Your answer
Follow this Question
Related Questions
Any way to attach a bit of code to individual UI Windows [Editor] 1 Answer
Custom Prfab Editor Window 0 Answers
What is the best way to draw icons in Unity's Hierarchy window? 1 Answer
How do I code my own custom built blend tree node as seen in the Animation Controller Editor Window? 1 Answer
Editor Window Views 0 Answers