Repository navigation
Replace Scroll dropdown with an Auto Scroll toggle in the scrollbar corner #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ed573be
041fc52
3af8aa0
b141790
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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) | ||
| { | ||
|
|
@@ -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() | ||
|
|
@@ -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 | ||
| // 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)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| { | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: repaint