From 13cdea389eb4405ba08769f9c3646100738c5bff Mon Sep 17 00:00:00 2001 From: Tomas Date: Tue, 17 Nov 2026 10:04:24 +0200 Subject: [PATCH] Fix auto scroll not re-enabling at certain window heights The check for "scrolled to the last message" compared rounded item counts, with the visible item count taken from the full messages area height. The horizontal scrollbar is always shown, so the real viewport is shorter, and whenever the fractional part of visible rows exceeded the scrollbar's share of a row the check failed even at the maximum scroll position. Compare in pixels instead. Also show the window size in the developer mode debug toolbar. Co-Authored-By: Claude Opus 5.5 --- com.unity.mobile.android-logcat/CHANGELOG.md | 1 + .../Editor/AndroidLogcatConsoleWindow.cs | 1 + .../Editor/AndroidLogcatMessagesViews.cs | 21 ++++++-- .../Editor/AndroidLogcatAutoScrollTests.cs | 51 +++++++++++++++++++ .../AndroidLogcatAutoScrollTests.cs.meta | 11 ++++ 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatAutoScrollTests.cs create mode 100644 com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatAutoScrollTests.cs.meta diff --git a/com.unity.mobile.android-logcat/CHANGELOG.md b/com.unity.mobile.android-logcat/CHANGELOG.md index 9758b2f6..039c0fd6 100644 --- a/com.unity.mobile.android-logcat/CHANGELOG.md +++ b/com.unity.mobile.android-logcat/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Recordings can be played in the Screen Capture window, with play/pause, a time slider and buttons that step one frame back or forward. - Tools->Open Terminal is now supported on Linux Editor. - Fixed Tools->Open Terminal not opening a window on Windows Editor when running on CoreCLR. + - 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 06ed7020..cd0d7880 100644 --- a/com.unity.mobile.android-logcat/Editor/AndroidLogcatConsoleWindow.cs +++ b/com.unity.mobile.android-logcat/Editor/AndroidLogcatConsoleWindow.cs @@ -485,6 +485,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: