Skip to content

Commit

Permalink
feat: Improved Log Settings Window Appearance (#1885)
Browse files Browse the repository at this point in the history
* setting window min size

* using Layout scopes

* adding scroll bar

* setting label and field widths
  • Loading branch information
James-Frowen committed May 12, 2020
1 parent 5726d3b commit 69b8451
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
57 changes: 34 additions & 23 deletions Assets/Mirror/Editor/Logging/LogLevelWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace Mirror.EditorScripts.Logging
public class LogLevelWindow : EditorWindow
{
[SerializeField] LogSettings settings = null;

SerializedObject serializedObject;
SerializedProperty settingsProp;
Vector2 dictionaryScrollPosition;

void OnEnable()
{
Expand All @@ -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();
using (EditorGUILayout.ScrollViewScope scrollScope = new EditorGUILayout.ScrollViewScope(dictionaryScrollPosition, GUIStyle.none, GUI.skin.verticalScrollbar))
{
dictionaryScrollPosition = scrollScope.scrollPosition;

EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
using (new EditorGUILayout.VerticalScope())
{
using (new EditorGUILayout.VerticalScope())
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(new GUIContent("Mirror Log Levels"), EditorStyles.boldLabel);
EditorGUILayout.Space();
EditorGUILayout.Space();
}

serializedObject.Update();
EditorGUILayout.PropertyField(settingsProp);
serializedObject.ApplyModifiedProperties();
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();
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();
}
Expand Down
9 changes: 8 additions & 1 deletion Assets/Mirror/Editor/Logging/LogLevelsGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
}

0 comments on commit 69b8451

Please sign in to comment.