diff --git a/com.unity.mobile.android-logcat/CHANGELOG.md b/com.unity.mobile.android-logcat/CHANGELOG.md index 8150b597..22f545e0 100644 --- a/com.unity.mobile.android-logcat/CHANGELOG.md +++ b/com.unity.mobile.android-logcat/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed Tools->Open Terminal not opening a window on Windows Editor when running on CoreCLR. - Added a Commands window, accessible via the Tools menu in the Android Logcat window. It lets you save, organize, search and run adb commands which don't have a dedicated UI in this package, such as package management, permissions, dumpsys, settings and Meta Quest properties. Commands run asynchronously so the Editor stays responsive, support `` substitution with per-token examples and suggestions, and can be imported and exported as JSON. Catalog commands display a description of what they do when you hover over them. Edit Mode supports selecting several commands and deleting them in one step. - Fixed log lines with an empty message not being parsed. They appeared as unformatted text with no tag, process ID or priority, and were hidden when filtering by tag. + - Fixed auto scrolling not turning back on after scrolling to the last message when Scroll is set to Auto. It happened only at certain Logcat window heights. (UUM-162014) ## [1.4.7] - 2025-12-12 ### Fixes & Improvements diff --git a/com.unity.mobile.android-logcat/Editor/AndroidLogcatConsoleWindow.cs b/com.unity.mobile.android-logcat/Editor/AndroidLogcatConsoleWindow.cs index 24cd7bb3..8ada6f48 100644 --- a/com.unity.mobile.android-logcat/Editor/AndroidLogcatConsoleWindow.cs +++ b/com.unity.mobile.android-logcat/Editor/AndroidLogcatConsoleWindow.cs @@ -489,6 +489,7 @@ private void DoDebuggingGUI() if (cannotKeepUp) message += " (CAN'T KEEP UP!!!!)"; GUILayout.Label(message, style); + GUILayout.Label($"Window: {position.width:F0}x{position.height:F0}"); EditorGUILayout.EndHorizontal(); } diff --git a/com.unity.mobile.android-logcat/Editor/AndroidLogcatMessagesViews.cs b/com.unity.mobile.android-logcat/Editor/AndroidLogcatMessagesViews.cs index 590949db..90044d57 100644 --- a/com.unity.mobile.android-logcat/Editor/AndroidLogcatMessagesViews.cs +++ b/com.unity.mobile.android-logcat/Editor/AndroidLogcatMessagesViews.cs @@ -28,6 +28,22 @@ public void Reset() PerformScrollWhileInAuto = true; } } + + // Extra message count ensures that there's an empty space below when we scrolling all the way down + // This way it's easier to see that there's no more messages + internal const int kExtraMessageCount = 5; + + /// + /// Whether the last log entry is visible for the given scroll position. + /// Compared in pixels, since comparing rounded item counts fails at certain window heights, + /// when the fractional part of visible rows is bigger than the horizontal scrollbar height. + /// Note: visibleHeight includes horizontal scrollbar, so the entry might be partially hidden behind the scrollbar. + /// + internal static bool IsLastEntryVisible(float scrollY, float visibleHeight, int entryCount, int rowHeight) + { + return scrollY + visibleHeight >= rowHeight * entryCount; + } + internal enum Column { Icon, @@ -379,9 +395,6 @@ private bool DoGUIEntries() var visibleWindowRect = GUILayoutUtility.GetRect(GUIContent.none, AndroidLogcatStyles.priorityDefaultStyle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); var totalWindowRect = visibleWindowRect; var maxVisibleItems = (int)(visibleWindowRect.height / AndroidLogcatStyles.kLogEntryFixedHeight); - // Extra message count ensures that there's an empty space below when we scrolling all the way down - // This way it's easier to see that there's no more messages - const int kExtraMessageCount = 5; totalWindowRect.height = AndroidLogcatStyles.kLogEntryFixedHeight * (FilteredEntries.Count + kExtraMessageCount); totalWindowRect.width = Mathf.Max(totalWindowRect.width, m_MaxLogEntryWidth); @@ -429,7 +442,7 @@ private bool DoGUIEntries() if (m_Runtime.UserSettings.AutoScroll == AutoScroll.Auto) { if (scrollChanged || (e.type == EventType.ScrollWheel && e.delta.y > 0.0f)) - m_ScrollData.PerformScrollWhileInAuto = startItem + maxVisibleItems - kExtraMessageCount >= FilteredEntries.Count; + m_ScrollData.PerformScrollWhileInAuto = IsLastEntryVisible(m_ScrollPosition.y, visibleWindowRect.height, FilteredEntries.Count, AndroidLogcatStyles.kLogEntryFixedHeight); else if (e.type == EventType.ScrollWheel && e.delta.y < 0.0f) m_ScrollData.PerformScrollWhileInAuto = false; } diff --git a/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatAutoScrollTests.cs b/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatAutoScrollTests.cs new file mode 100644 index 00000000..e84316df --- /dev/null +++ b/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatAutoScrollTests.cs @@ -0,0 +1,51 @@ +using NUnit.Framework; +using Unity.Android.Logcat; + +class AndroidLogcatAutoScrollTests +{ + const int kEntryCount = 1000; + + // Mirrors GUI.BeginScrollView: the content height includes the extra empty rows below the last entry, + // and the viewport is reduced by the always visible horizontal scrollbar + static float GetMaxScrollY(float visibleHeight, int entryCount, int rowHeight, float horizontalScrollbarHeight) + { + var totalHeight = rowHeight * (entryCount + AndroidLogcatConsoleWindow.kExtraMessageCount); + var viewportHeight = visibleHeight - horizontalScrollbarHeight; + return totalHeight - viewportHeight; + } + + [Test] + public void LastEntryIsVisibleWhenScrolledToBottom_ForAnyWindowHeight( + [Values(12, 16, 20, 25, 30)] int rowHeight, + [Values(0.0f, 13.0f, 15.0f)] float horizontalScrollbarHeight) + { + // Previously comparing rounded item counts failed when the fractional part of visible rows + // was bigger than horizontal scrollbar height, for ex., 350px height with 16px rows + for (float visibleHeight = 100.0f; visibleHeight <= 1500.0f; visibleHeight += 0.5f) + { + var maxScrollY = GetMaxScrollY(visibleHeight, kEntryCount, rowHeight, horizontalScrollbarHeight); + Assert.IsTrue(AndroidLogcatConsoleWindow.IsLastEntryVisible(maxScrollY, visibleHeight, kEntryCount, rowHeight), + $"Last entry should be visible at bottom, visible height {visibleHeight}, row height {rowHeight}, scrollbar height {horizontalScrollbarHeight}"); + } + } + + [Test] + public void LastEntryIsNotVisibleWhenScrolledAboveIt() + { + const int rowHeight = 16; + const float visibleHeight = 350.0f; + var lastEntryBottom = rowHeight * kEntryCount; + + Assert.IsFalse(AndroidLogcatConsoleWindow.IsLastEntryVisible(0.0f, visibleHeight, kEntryCount, rowHeight)); + Assert.IsFalse(AndroidLogcatConsoleWindow.IsLastEntryVisible(lastEntryBottom - visibleHeight - 1.0f, visibleHeight, kEntryCount, rowHeight)); + Assert.IsTrue(AndroidLogcatConsoleWindow.IsLastEntryVisible(lastEntryBottom - visibleHeight, visibleHeight, kEntryCount, rowHeight)); + } + + [Test] + public void LastEntryIsVisibleWhenAllEntriesFit() + { + const int rowHeight = 16; + Assert.IsTrue(AndroidLogcatConsoleWindow.IsLastEntryVisible(0.0f, 350.0f, 10, rowHeight)); + Assert.IsTrue(AndroidLogcatConsoleWindow.IsLastEntryVisible(0.0f, 350.0f, 0, rowHeight)); + } +} diff --git a/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatAutoScrollTests.cs.meta b/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatAutoScrollTests.cs.meta new file mode 100644 index 00000000..df88bfb3 --- /dev/null +++ b/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatAutoScrollTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 80edc7c16421435189f10a7f3018f41f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: