diff --git a/Editor/UberLoggerEditorWindow.cs b/Editor/UberLoggerEditorWindow.cs index bd67cb6..084228d 100755 --- a/Editor/UberLoggerEditorWindow.cs +++ b/Editor/UberLoggerEditorWindow.cs @@ -77,6 +77,8 @@ void OnEnable() WarningIcon = SmallWarningIcon; MessageIcon = SmallMessageIcon; Dirty = true; + FilterChanged = true; + NeedToUpdateStyles = true; Repaint(); } @@ -150,37 +152,16 @@ public void HandleCopyToClipboard() } Vector2 DrawPos; + bool NeedToUpdateStyles; + bool FilterChanged; + int NextIndexToAdd; public void OnGUI() { - //Set up the basic style, based on the Unity defaults - //A bit hacky, but means we don't have to ship an editor guistyle and can fit in to pro and free skins - Color defaultLineColor = GUI.backgroundColor; - GUIStyle unityLogLineEven = null; - GUIStyle unityLogLineOdd = null; - GUIStyle unitySmallLogLine = null; - - foreach(var style in GUI.skin.customStyles) + if (NeedToUpdateStyles) { - if (style.name=="CN EntryBackEven") unityLogLineEven = style; - else if(style.name=="CN EntryBackOdd") unityLogLineOdd = style; - else if(style.name=="CN StatusInfo") unitySmallLogLine = style; + UpdateStyles(); } - EntryStyleBackEven = new GUIStyle(unitySmallLogLine); - - EntryStyleBackEven.normal = unityLogLineEven.normal; - EntryStyleBackEven.margin = new RectOffset(0,0,0,0); - EntryStyleBackEven.border = new RectOffset(0,0,0,0); - EntryStyleBackEven.fixedHeight = 0; - - EntryStyleBackOdd = new GUIStyle(EntryStyleBackEven); - EntryStyleBackOdd.normal = unityLogLineOdd.normal; - // EntryStyleBackOdd = new GUIStyle(unityLogLine); - - - SizerLineColour = new Color(defaultLineColor.r*0.5f, defaultLineColor.g*0.5f, defaultLineColor.b*0.5f); - - // GUILayout.BeginVertical(GUILayout.Height(topPanelHeaderHeight), GUILayout.MinHeight(topPanelHeaderHeight)); ResizeTopPane(); DrawPos = Vector2.zero; DrawToolbar(); @@ -192,7 +173,8 @@ public void OnGUI() if(Dirty) { - CurrentLogList = EditorLogger.CopyLogInfo(); + CurrentLogList.Clear(); + EditorLogger.CopyLogInfoTo(CurrentLogList); } DrawLogList(logPanelHeight); @@ -210,6 +192,46 @@ public void OnGUI() MakeDirty = false; Repaint(); } + else + { + FilterChanged = false; + } + } + + private void UpdateStyles() + { + //Set up the basic style, based on the Unity defaults + //A bit hacky, but means we don't have to ship an editor guistyle and can fit in to pro and free skins + Color defaultLineColor = GUI.backgroundColor; + GUIStyle unityLogLineEven = null; + GUIStyle unityLogLineOdd = null; + GUIStyle unitySmallLogLine = null; + + foreach (var style in GUI.skin.customStyles) + { + if (style.name == "CN EntryBackEven") unityLogLineEven = style; + else if (style.name == "CN EntryBackOdd") unityLogLineOdd = style; + else if (style.name == "CN StatusInfo") unitySmallLogLine = style; + } + + EntryStyleBackEven = new GUIStyle(unitySmallLogLine); + + EntryStyleBackEven.normal = unityLogLineEven.normal; + EntryStyleBackEven.margin = new RectOffset(0, 0, 0, 0); + EntryStyleBackEven.border = new RectOffset(0, 0, 0, 0); + EntryStyleBackEven.fixedHeight = 0; + EntryStyleBackEven.fixedWidth = 0; + + EntryStyleBackEven.clipping = TextClipping.Overflow; + EntryStyleBackEven.stretchWidth = true; + + EntryStyleBackOdd = new GUIStyle(EntryStyleBackEven); + EntryStyleBackOdd.normal = unityLogLineOdd.normal; + + DetailsEntryStyleBackEven = new GUIStyle(EntryStyleBackEven); + DetailsEntryStyleBackOdd = new GUIStyle(EntryStyleBackOdd); + + SizerLineColour = new Color(defaultLineColor.r * 0.5f, defaultLineColor.g * 0.5f, defaultLineColor.b * 0.5f); } //Some helper functions to draw buttons that are only as big as their text @@ -253,6 +275,7 @@ void DrawToolbar() Vector2 elementSize; if(ButtonClamped("Clear", EditorStyles.toolbarButton, out elementSize)) { + FilterChanged = true; EditorLogger.Clear(); } DrawPos.x += elementSize.x; @@ -278,6 +301,7 @@ void DrawToolbar() if(collapse!=Collapse) { MakeDirty = true; + FilterChanged = true; Collapse = collapse; SelectedRenderLog = -1; } @@ -311,6 +335,7 @@ void DrawToolbar() //If the errors/warning to show has changed, clear the selected message if(showErrors!=ShowErrors || showWarnings!=ShowWarnings || showMessages!=ShowMessages) { + FilterChanged = true; ClearSelectedMessage(); MakeDirty = true; } @@ -344,6 +369,7 @@ void DrawChannels() CurrentChannel = channels[currentChannelIndex]; ClearSelectedMessage(); MakeDirty = true; + FilterChanged = true; } DrawPos.y+=size.y; } @@ -397,7 +423,7 @@ GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes, bool sho showMessage ); - var content = new GUIContent(showMessage, GetIconForLog(log)); + var content = new GUIContent(showMessage); return content; } @@ -407,7 +433,7 @@ GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes, bool sho public void DrawLogList(float height) { var oldColor = GUI.backgroundColor; - + GUI.SetNextControlName(LogListControlName); float buttonY = 0; @@ -424,87 +450,84 @@ public void DrawLogList(float height) // If we've been marked dirty, we need to recalculate the elements to be displayed if(Dirty) { - LogListMaxWidth = 0; - LogListLineHeight = 0; - CollapseBadgeMaxWidth = 0; - RenderLogs.Clear(); + if (FilterChanged) + { + CollapseBadgeMaxWidth = 0; + MaxCollapseCount = 0; + RenderLogs.Clear(); + NextIndexToAdd = 0; + + CollapsedLines.Clear(); + CollapsedLinesList.Clear(); + } //When collapsed, count up the unique elements and use those to display if(Collapse) { - var collapsedLines = new Dictionary(); - var collapsedLinesList = new List(); - - foreach(var log in CurrentLogList) + for (var i = NextIndexToAdd; i < CurrentLogList.Count; i++) { - if(ShouldShowLog(filterRegex, log)) + var log = CurrentLogList[i]; + if (ShouldShowLog(filterRegex, log)) { var matchString = log.Message + "!$" + log.Severity + "!$" + log.Channel; CountedLog countedLog; - if(collapsedLines.TryGetValue(matchString, out countedLog)) + if (CollapsedLines.TryGetValue(matchString, out countedLog)) { countedLog.Count++; } else { countedLog = new CountedLog(log, 1); - collapsedLines.Add(matchString, countedLog); - collapsedLinesList.Add(countedLog); + CollapsedLines.Add(matchString, countedLog); + CollapsedLinesList.Add(countedLog); + RenderLogs.Add(countedLog); + } + + if (MaxCollapseCount < countedLog.Count) + { + MaxCollapseCount = countedLog.Count; } } } - foreach(var countedLog in collapsedLinesList) - { - var content = GetLogLineGUIContent(countedLog.Log, ShowTimes, ShowChannels); - RenderLogs.Add(countedLog); - var logLineSize = logLineStyle.CalcSize(content); - LogListMaxWidth = Mathf.Max(LogListMaxWidth, logLineSize.x); - LogListLineHeight = Mathf.Max(LogListLineHeight, logLineSize.y); - - var collapseBadgeContent = new GUIContent(countedLog.Count.ToString()); - var collapseBadgeSize = collapseBadgeStyle.CalcSize(collapseBadgeContent); - CollapseBadgeMaxWidth = Mathf.Max(CollapseBadgeMaxWidth, collapseBadgeSize.x); - } + var collapseBadgeContent = new GUIContent(MaxCollapseCount.ToString()); + var collapseBadgeSize = collapseBadgeStyle.CalcSize(collapseBadgeContent); + CollapseBadgeMaxWidth = Mathf.Max(CollapseBadgeMaxWidth, collapseBadgeSize.x); } //If we're not collapsed, display everything in order else { - foreach(var log in CurrentLogList) + for (var i = NextIndexToAdd; i < CurrentLogList.Count; i++) { - if(ShouldShowLog(filterRegex, log)) + var log = CurrentLogList[i]; + if (ShouldShowLog(filterRegex, log)) { - var content = GetLogLineGUIContent(log, ShowTimes, ShowChannels); RenderLogs.Add(new CountedLog(log, 1)); - var logLineSize = logLineStyle.CalcSize(content); - LogListMaxWidth = Mathf.Max(LogListMaxWidth, logLineSize.x); - LogListLineHeight = Mathf.Max(LogListLineHeight, logLineSize.y); } } } - - LogListMaxWidth += CollapseBadgeMaxWidth; } var scrollRect = new Rect(DrawPos, new Vector2(position.width, height)); - float lineWidth = Mathf.Max(LogListMaxWidth, scrollRect.width); - var contentRect = new Rect(0, 0, lineWidth, RenderLogs.Count*LogListLineHeight); + var contentRect = new Rect(0, 0, scrollRect.width, RenderLogs.Count*LogListLineHeight); + var viewRect = contentRect; + viewRect.width -= 50; Vector2 lastScrollPosition = LogListScrollPosition; - LogListScrollPosition = GUI.BeginScrollView(scrollRect, LogListScrollPosition, contentRect); + LogListScrollPosition = GUI.BeginScrollView(scrollRect, LogListScrollPosition, viewRect, GUIStyle.none, GUI.skin.verticalScrollbar); //If we're following the messages but the user has moved, cancel following if(ScrollFollowMessages) { if(lastScrollPosition.y - LogListScrollPosition.y > LogListLineHeight) { - UberDebug.UnityLog(String.Format("{0} {1}", lastScrollPosition.y, LogListScrollPosition.y)); ScrollFollowMessages = false; } } - float logLineX = CollapseBadgeMaxWidth; + EntryStyleBackEven.padding.left = (int) (CollapseBadgeMaxWidth + LogListLineHeight + 4); + EntryStyleBackOdd.padding.left = EntryStyleBackEven.padding.left; //Render all the elements int firstRenderLogIndex = (int) (LogListScrollPosition.y/LogListLineHeight); @@ -513,13 +536,12 @@ public void DrawLogList(float height) firstRenderLogIndex = Mathf.Clamp(firstRenderLogIndex, 0, RenderLogs.Count); lastRenderLogIndex = Mathf.Clamp(lastRenderLogIndex, 0, RenderLogs.Count); buttonY = firstRenderLogIndex*LogListLineHeight; - - for(int renderLogIndex=firstRenderLogIndex; renderLogIndex0) { LogListScrollPosition.y = ((RenderLogs.Count+1)*LogListLineHeight)-scrollRect.height; } + NextIndexToAdd = CurrentLogList.Count; + GUI.EndScrollView(); DrawPos.y += height; DrawPos.x = 0; @@ -604,8 +636,8 @@ public void DrawLogDetails() { var countedLog = RenderLogs[SelectedRenderLog]; var log = countedLog.Log; - var logLineStyle = EntryStyleBackEven; - + var logLineStyle = DetailsEntryStyleBackEven; + logLineStyle.wordWrap = true; var sourceStyle = new GUIStyle(GUI.skin.textArea); sourceStyle.richText = true; @@ -616,9 +648,10 @@ public void DrawLogDetails() float contentHeight = 0; float contentWidth = 0; float lineHeight = 0; + var messageContent = new GUIContent(log.Message); + var messageHeight = logLineStyle.CalcHeight(messageContent, position.width) + LogListLineHeight; - - for(int c1=0; c1 RenderLogs = new List(); + Dictionary CollapsedLines = new Dictionary(); + List CollapsedLinesList = new List(); + int MaxCollapseCount = 0; + float CollapseBadgeMaxWidth = 0; + const string LogListControlName = "LogList"; class CountedLog { @@ -974,10 +1027,4 @@ public CountedLog(UberLogger.LogInfo log, Int32 count) Count = count; } } - - List RenderLogs = new List(); - float LogListMaxWidth = 0; - float LogListLineHeight = 0; - float CollapseBadgeMaxWidth = 0; - } diff --git a/UberLoggerEditor.cs b/UberLoggerEditor.cs index b357a80..e4eb043 100755 --- a/UberLoggerEditor.cs +++ b/UberLoggerEditor.cs @@ -144,11 +144,11 @@ public void Clear() } } - public List CopyLogInfo() + public void CopyLogInfoTo(List container) { lock(this) { - return new List(LogInfo); + container.AddRange(LogInfo); } }