Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions com.unity.mobile.android-logcat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixes & Improvements
- Replaced the Scroll dropdown (Disabled / Scroll To End / Auto) below the message log with an Auto Scroll toggle button in the corner between the message log's scrollbars. Turning it on scrolls to the last message and keeps following new ones. Scrolling up or selecting messages with the Up and Down keys turns it off, and scrolling back to the last message turns it back on.

## [1.5.0] - 2026-11-18
### Fixes & Improvements
- Unity 6.0 or later is required.
Expand Down
20 changes: 0 additions & 20 deletions com.unity.mobile.android-logcat/Editor/AndroidLogcatAutoScroll.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,8 @@ internal void OnGUI()
break;
}

EditorGUILayout.BeginHorizontal();
if (m_StatusBar != null)
m_StatusBar.DoGUI();
DoScrollOptionsGUI();
EditorGUILayout.EndHorizontal();

EditorGUILayout.EndVertical();
}
Expand Down Expand Up @@ -478,8 +475,6 @@ private void DoDebuggingGUI()
}

m_Logcat?.DoDebuggingGUI();
if (m_Runtime.UserSettings.AutoScroll == AutoScroll.Auto)
GUILayout.Label($"Auto Scrolling: {m_ScrollData.PerformScrollWhileInAuto}");
// Have a sane number which represents that we cannot keep up with async items in queue
// Usually this indicates a bug, since async operations starts being more and more delayed
const int kMaxAsyncItemsInQueue = 100;
Expand Down
124 changes: 56 additions & 68 deletions com.unity.mobile.android-logcat/Editor/AndroidLogcatMessagesViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ namespace Unity.Android.Logcat
{
internal partial class AndroidLogcatConsoleWindow
{
private GUIContent kScroll = new GUIContent(L10n.Tr("Scroll:"), L10n.Tr("Disabled - No scrolling\nScroll To End - Always scroll to end\nAuto - switch to 'scroll to end' when scrolling to the last message"));
class ScrollData
{
public int ScrollToItemWhileInDisabled { set; get; }
public bool PerformScrollWhileInAuto { set; get; }

public ScrollData()
{
Reset();
}

public void Reset()
{
ScrollToItemWhileInDisabled = -1;
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;
Expand All @@ -37,7 +19,7 @@ public void Reset()
/// 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.
/// Note: if visibleHeight includes the horizontal scrollbar, the entry might be hidden behind the scrollbar.
/// </summary>
internal static bool IsLastEntryVisible(float scrollY, float visibleHeight, int entryCount, int rowHeight)
{
Expand Down Expand Up @@ -83,7 +65,7 @@ public IReadOnlyList<LogcatEntry> GetSelectedFilteredEntries(out int minIndex, o

public IReadOnlyList<LogcatEntry> SelectedFilteredEntries => GetSelectedFilteredEntries(out var minIndex, out var maxIndex);

private ScrollData m_ScrollData = new ScrollData();
private int m_ScrollToItem = -1;
private float doubleClickStart = -1;

void CollectTagPrioritiesFromDevice()
Expand Down Expand Up @@ -398,54 +380,49 @@ private bool DoGUIEntries()
totalWindowRect.height = AndroidLogcatStyles.kLogEntryFixedHeight * (FilteredEntries.Count + kExtraMessageCount);
totalWindowRect.width = Mathf.Max(totalWindowRect.width, m_MaxLogEntryWidth);

// Before the scroll view, so turning auto scroll on scrolls to the end in this same event
DoAutoScrollToggle(visibleWindowRect);

var controlId = GUIUtility.GetControlID(FocusType.Keyboard);

var scalar = (float)(kExtraMessageCount + FilteredEntries.Count) / totalWindowRect.height;
switch (m_Runtime.UserSettings.AutoScroll)
var scrollToItem = m_ScrollToItem;
if (scrollToItem >= 0)
{
case AutoScroll.Disabled:
var scrollToItem = m_ScrollData.ScrollToItemWhileInDisabled;
if (scrollToItem >= 0)
{
// Do the scrolling in repain event since maxVisibleItems depends on visibleWindowRect
// And that one is calculated correctly only in Repaint event
if (e.type != EventType.Repaint)
break;

int minVisible = (int)(m_ScrollPosition.y * scalar);
int maxVisible = minVisible + maxVisibleItems;
// Do the scrolling in repain event since maxVisibleItems depends on visibleWindowRect

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: repaint

// And that one is calculated correctly only in Repaint event
if (e.type == EventType.Repaint)
{
int minVisible = (int)(m_ScrollPosition.y * scalar);
int maxVisible = minVisible + maxVisibleItems;

// Only adjust scroll if our selected items is not among visible items
if (scrollToItem < minVisible)
m_ScrollPosition.y = scrollToItem / scalar;
if (scrollToItem > maxVisible - kExtraMessageCount)
m_ScrollPosition.y = (scrollToItem - maxVisibleItems + kExtraMessageCount) / scalar;
// Only adjust scroll if our selected items is not among visible items
if (scrollToItem < minVisible)
m_ScrollPosition.y = scrollToItem / scalar;
if (scrollToItem > maxVisible - kExtraMessageCount)
m_ScrollPosition.y = (scrollToItem - maxVisibleItems + kExtraMessageCount) / scalar;

m_ScrollData.Reset();
}
break;
case AutoScroll.ScrollToEnd:
m_ScrollPosition.y = totalWindowRect.height;
break;
case AutoScroll.Auto:
if (m_ScrollData.PerformScrollWhileInAuto)
m_ScrollPosition.y = totalWindowRect.height;
break;
m_ScrollToItem = -1;
}
}
else if (m_Runtime.UserSettings.AutoScroll)
{
m_ScrollPosition.y = totalWindowRect.height;
}

EditorGUI.BeginChangeCheck();
m_ScrollPosition = GUI.BeginScrollView(visibleWindowRect, m_ScrollPosition, totalWindowRect, true, false);
// Vertical scrollbar is always shown, so the auto scroll toggle always has the corner between the scrollbars
m_ScrollPosition = GUI.BeginScrollView(visibleWindowRect, m_ScrollPosition, totalWindowRect, true, true);
var horizontalBar = GUI.skin.horizontalScrollbar;
var horizontalBarHeight = horizontalBar.fixedHeight + horizontalBar.margin.top;
var startItem = (int)(m_ScrollPosition.y * scalar);

// Check if we need to enable autoscrolling
// Scrolling manually turns auto scroll off, unless it ends at the last message
var scrollChanged = EditorGUI.EndChangeCheck();
if (m_Runtime.UserSettings.AutoScroll == AutoScroll.Auto)
{
if (scrollChanged || (e.type == EventType.ScrollWheel && e.delta.y > 0.0f))
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;
}
if (scrollChanged || (e.type == EventType.ScrollWheel && e.delta.y > 0.0f))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is scrollChanged true, when scrolling horizontally? If yes, there can be some unexpected effect when user turns scrolling off being at the end of the logcat messages, then scrolls horizontally and this turns scrolling back on.

m_Runtime.UserSettings.AutoScroll = IsLastEntryVisible(m_ScrollPosition.y, visibleWindowRect.height - horizontalBarHeight, FilteredEntries.Count, AndroidLogcatStyles.kLogEntryFixedHeight);
else if (e.type == EventType.ScrollWheel && e.delta.y < 0.0f)
m_Runtime.UserSettings.AutoScroll = false;

if (e.type == EventType.Repaint)
{
Expand Down Expand Up @@ -495,8 +472,7 @@ private bool DoGUIEntries()
GUI.EndScrollView();

Rect rc = GUILayoutUtility.GetLastRect();
// Decrement horizontal scrollbar height
rc.height -= 15.0f;
rc.height -= horizontalBarHeight;
DoColumnBorders(rc, Color.black, 1);

return requestRepaint;
Expand Down Expand Up @@ -752,19 +728,31 @@ private void DoNavigation(int direction, bool shiftPressed)
}

m_Logcat.FilteredEntries[selectedItem].Selected = true;
m_Runtime.UserSettings.AutoScroll = AutoScroll.Disabled;
m_ScrollData.ScrollToItemWhileInDisabled = selectedItem;
m_Runtime.UserSettings.AutoScroll = false;
m_ScrollToItem = selectedItem;
}

private void DoScrollOptionsGUI()
private void DoAutoScrollToggle(Rect scrollViewRect)
{
GUILayout.Label(kScroll, GUILayout.ExpandWidth(false));
EditorGUI.BeginChangeCheck();
var scroll = (AutoScroll)EditorGUILayout.EnumPopup(m_Runtime.UserSettings.AutoScroll, GUILayout.ExpandWidth(false));
if (EditorGUI.EndChangeCheck())
{
m_ScrollData.Reset();
m_Runtime.UserSettings.AutoScroll = scroll;
var horizontalBar = GUI.skin.horizontalScrollbar;
var verticalBar = GUI.skin.verticalScrollbar;
var corner = Rect.MinMaxRect(
scrollViewRect.xMax - verticalBar.fixedWidth - verticalBar.margin.left,
scrollViewRect.yMax - horizontalBar.fixedHeight - horizontalBar.margin.top,
scrollViewRect.xMax,
scrollViewRect.yMax);
// The icon is white, tinted like the scrollbar arrows of the current skin, and faded while off
var orgContentColor = GUI.contentColor;
var iconColor = EditorGUIUtility.isProSkin ? new Color(0.77f, 0.77f, 0.77f) : new Color(0.33f, 0.33f, 0.33f);
if (!m_Runtime.UserSettings.AutoScroll)
iconColor.a = 0.35f;
GUI.contentColor = iconColor;
var autoScroll = GUI.Toggle(corner, m_Runtime.UserSettings.AutoScroll, AndroidLogcatStyles.kIconAutoScroll, AndroidLogcatStyles.scrollCornerToggle);
GUI.contentColor = orgContentColor;
if (autoScroll != m_Runtime.UserSettings.AutoScroll)
{
m_ScrollToItem = -1;
m_Runtime.UserSettings.AutoScroll = autoScroll;
}
}

Expand Down
2 changes: 2 additions & 0 deletions com.unity.mobile.android-logcat/Editor/AndroidLogcatStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static class AndroidLogcatStyles
public static readonly GUIStyle toolbarLabelLeft = new GUIStyle("toolbarButton") { fontSize = kFontSize, fixedHeight = kFixedHeight, alignment = TextAnchor.MiddleLeft };

public static readonly GUIStyle columnHeader = new GUIStyle("OL TITLE");
public static readonly GUIStyle scrollCornerToggle = new GUIStyle("toolbarButton") { padding = new RectOffset(), margin = new RectOffset(), fixedWidth = 0, fixedHeight = 0 };

public static int kLogEntryFontSize = 11;
public static int kLogEntryFixedHeight = kLogEntryFontSize + 5;
Expand Down Expand Up @@ -154,6 +155,7 @@ public static Texture2D LoadIcon(string name)
internal static readonly GUIContent kIconToolbarDown = new GUIContent(LoadIcon("DownArrow"));
internal static readonly GUIContent kIconToolbarUp = new GUIContent(LoadIcon("UpArrow"));
internal static readonly GUIContent kIconReset = new GUIContent(LoadIcon("Reset"), "Reset");
internal static readonly GUIContent kIconAutoScroll = new GUIContent(LoadIcon("DownArrowToLine"), "Auto Scroll: scroll to the last message and follow new ones. Turns off when you scroll up, and back on when you scroll to the last message.");
internal static readonly GUIContent[] kIconPlay = new[] {
new GUIContent(LoadIcon("PlayOn")),
new GUIContent(LoadIcon("PlayOff"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ internal class CommandsSettingsData
[SerializeField]
private CommandsSettingsData m_CommandsSettings;

// Not m_AutoScroll, which held the former Disabled/ScrollToEnd/Auto enum, so older saved settings aren't misread as a bool
[SerializeField]
private AutoScroll m_AutoScroll;
private bool m_AutoScrollEnabled;

public string LastSelectedDeviceId
{
Expand Down Expand Up @@ -164,7 +165,7 @@ public Priority SelectedPriority
public InputSettings DeviceInputSettings { set => m_InputSettings = value; get => m_InputSettings; }
public CommandsSettingsData CommandsSettings { set => m_CommandsSettings = value; get => m_CommandsSettings; }

public AutoScroll AutoScroll { set => m_AutoScroll = value; get => m_AutoScroll; }
public bool AutoScroll { set => m_AutoScrollEnabled = value; get => m_AutoScrollEnabled; }

private void RefreshProcessesForSerialization()
{
Expand Down Expand Up @@ -333,7 +334,7 @@ internal void Reset()
m_MemoryViewerState = new AndroidLogcatMemoryViewerState();
m_SymbolPaths = new List<ReordableListItem>();
m_FilterOptions = new FilterOptions();
m_AutoScroll = AutoScroll.Auto;
m_AutoScrollEnabled = true;

ResetScreenCaptureSettings();

Expand Down

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude says that the icon might be too big, so it's being scaled down and it may look not really nice.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading