feat: Improved Log Settings Window Appearance (#1885)

* setting window min size

* using Layout scopes

* adding scroll bar

* setting label and field widths
This commit is contained in:
James Frowen 2020-05-12 16:34:24 +01:00 committed by GitHub
parent 5726d3b84a
commit 69b845183c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 25 deletions

View File

@ -7,8 +7,10 @@ namespace Mirror.EditorScripts.Logging
public class LogLevelWindow : EditorWindow
{
[SerializeField] LogSettings settings = null;
SerializedObject serializedObject;
SerializedProperty settingsProp;
Vector2 dictionaryScrollPosition;
void OnEnable()
{
@ -25,40 +27,49 @@ void OnEnable()
void OnGUI()
{
EditorGUILayout.BeginVertical();
EditorGUILayout.Space();
EditorGUILayout.LabelField(new GUIContent("Mirror Log Levels"), EditorStyles.boldLabel);
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.EndVertical();
EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
serializedObject.Update();
EditorGUILayout.PropertyField(settingsProp);
serializedObject.ApplyModifiedProperties();
if (settings == null)
using (EditorGUILayout.ScrollViewScope scrollScope = new EditorGUILayout.ScrollViewScope(dictionaryScrollPosition, GUIStyle.none, GUI.skin.verticalScrollbar))
{
LogSettings newSettings = LogLevelsGUI.DrawCreateNewButton();
if (newSettings != null)
dictionaryScrollPosition = scrollScope.scrollPosition;
using (new EditorGUILayout.VerticalScope())
{
settingsProp.objectReferenceValue = newSettings;
serializedObject.ApplyModifiedProperties();
using (new EditorGUILayout.VerticalScope())
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(new GUIContent("Mirror Log Levels"), EditorStyles.boldLabel);
EditorGUILayout.Space();
EditorGUILayout.Space();
}
using (new EditorGUILayout.VerticalScope())
{
serializedObject.Update();
EditorGUILayout.PropertyField(settingsProp);
serializedObject.ApplyModifiedProperties();
if (settings == null)
{
LogSettings newSettings = LogLevelsGUI.DrawCreateNewButton();
if (newSettings != null)
{
settingsProp.objectReferenceValue = newSettings;
serializedObject.ApplyModifiedProperties();
}
}
else
{
LogLevelsGUI.DrawLogFactoryDictionary(settings);
}
}
}
}
else
{
LogLevelsGUI.DrawLogFactoryDictionary(settings);
}
EditorGUILayout.EndVertical();
}
[MenuItem("Window/Analysis/Mirror Log Levels", priority = 20002)]
public static void ShowWindow()
{
LogLevelWindow window = GetWindow<LogLevelWindow>();
window.minSize = new Vector2(200, 100);
window.titleContent = new GUIContent("Mirror Log levels");
window.Show();
}

View File

@ -45,7 +45,14 @@ static void DrawLoggerField(KeyValuePair<string, ILogger> item)
ILogger logger = item.Value;
string name = item.Key;
logger.filterLogType = (LogType)EditorGUILayout.EnumPopup(new GUIContent(name), logger.filterLogType);
const float fieldWidth = 100f;
const float inspectorMargin = 25f;
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.LabelField(new GUIContent(name), GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth - fieldWidth - inspectorMargin));
logger.filterLogType = (LogType)EditorGUILayout.EnumPopup(logger.filterLogType, GUILayout.Width(fieldWidth));
}
}
}
}