I was just wondering if there is a simple way to label a GUILayout horizontal slider dynamically as such (shown in the image below):
I want the ‘100’ to appear at the right end of the slider and I want it to be dynamic so that whenever I resize the whole menu, the ‘100’ remains at the desired position.
Using EditorGUI instead of GUILayout, Scribe’s solution didn’t work for me as such. I made it through tweaking it that way :
Rect position = EditorGUILayout.GetControlRect (false, 2*EditorGUIUtility.singleLineHeight); // Get two lines for the control
position.height *= 0.5f;
tgt.FitOrFill = EditorGUI.Slider (position,"Fit or Fill", tgt.FitOrFill, 0, 1);
// Set the rect for the sub-labels
position.y += position.height;
position.x += EditorGUIUtility.labelWidth;
position.width -= EditorGUIUtility.labelWidth + 54; //54 seems to be the width of the slider's float field
//sub-labels
GUIStyle style = GUI.skin.label;
style.alignment = TextAnchor.UpperLeft; EditorGUI.LabelField (position, "Fit", style);
style.alignment = TextAnchor.UpperRight; EditorGUI.LabelField (position, "Fill", style);