diff options
author | aalbert <aalbert@google.com> | 2022-07-06 19:48:27 -0700 |
---|---|---|
committer | TreeHugger Robot <treehugger-gerrit@google.com> | 2022-07-07 18:47:14 +0000 |
commit | 86f785656fd4f1d17918ef8a3e06ccca0bd02d50 (patch) | |
tree | 834bc2a525084d7dd6b64a222a1484c51b5fe88d /logcat | |
parent | fba8b7265730b93ae69a01527b13682ac649fbcf (diff) | |
download | idea-86f785656fd4f1d17918ef8a3e06ccca0bd02d50.tar.gz |
Change Dropdown Favorite Icon on Hover
https://screenshot.googleplex.com/5b4PmCzFiTCMDiU.png
https://screenshot.googleplex.com/8GoubbgSy33JiD8.png
https://screenshot.googleplex.com/7e9VU6rhXa5UkrD.png
https://screenshot.googleplex.com/BuojYGkXRWAkWMg.png
Bug: 238228752
Bug: 238308373
Test: Manually
Change-Id: I01e3593d65817622b14742ee0e0cc3c5629ee570
Diffstat (limited to 'logcat')
-rw-r--r-- | logcat/src/com/android/tools/idea/logcat/filters/FilterTextField.kt | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/logcat/src/com/android/tools/idea/logcat/filters/FilterTextField.kt b/logcat/src/com/android/tools/idea/logcat/filters/FilterTextField.kt index 2fb8a6e2b49..369c815a3de 100644 --- a/logcat/src/com/android/tools/idea/logcat/filters/FilterTextField.kt +++ b/logcat/src/com/android/tools/idea/logcat/filters/FilterTextField.kt @@ -96,6 +96,8 @@ private val FAVORITE_ICON = StudioIcons.Logcat.Input.FAVORITE_OUTLINE private val FAVORITE_ON_ICON = StudioIcons.Logcat.Input.FAVORITE_FILLED private val FAVORITE_FOCUSED_ICON = StudioIcons.Logcat.Input.FAVORITE_OUTLINE_HOVER private val FAVORITE_FOCUSED_ON_ICON = StudioIcons.Logcat.Input.FAVORITE_FILLED_HOVER +private val FAVORITE_POPUP_HOVER_ICON = StudioIcons.Logcat.Input.FAVORITE_POPUP_HOVER +private val FAVORITE_FILLED_POPUP_HOVER_ICON = StudioIcons.Logcat.Input.FAVORITE_FILLED_POPUP_HOVER private val FAVORITE_BLANK_ICON = EmptyIcon.create(FAVORITE_ON_ICON.iconWidth, FAVORITE_ON_ICON.iconHeight) // The text of the history dropdown item needs a little horizontal padding @@ -409,7 +411,9 @@ internal class FilterTextField( } } - addMouseListener(MouseListener()) + val listener = MouseListener() + addMouseListener(listener) + addMouseMotionListener(listener) } /** @@ -452,6 +456,8 @@ internal class FilterTextField( * the item. This works because the item corresponding to the mouse event must be the selected item since the mouse is hovering on it. */ inner class MouseListener : MouseAdapter() { + var hoveredFavoriteIndex: Int? = null + override fun mouseReleased(event: MouseEvent) { if (event.button == BUTTON1 && event.modifiersEx == 0) { val index = selectedIndex @@ -463,6 +469,31 @@ internal class FilterTextField( } } } + + override fun mouseMoved(event: MouseEvent) { + val index = selectedIndex + if (model.getElementAt(index) !is Item) { + hoveredFavoriteIndex?.setIsHoveredFavorite(false) + } + val cellLocation = getCellBounds(index, index).location + val favoriteIconBounds = Item.getFavoriteIconBounds(cellLocation) + val hoveredIndex = when { + favoriteIconBounds.contains(event.point) -> index + else -> null + } + + if (hoveredIndex != hoveredFavoriteIndex) { + hoveredFavoriteIndex?.setIsHoveredFavorite(false) + hoveredIndex?.setIsHoveredFavorite(true) + hoveredFavoriteIndex = hoveredIndex + paintImmediately(favoriteIconBounds) + } + } + + private fun Int.setIsHoveredFavorite(value: Boolean) { + val item = model.getElementAt(this) as? Item ?: return + item.isFavoriteHovered = value + } } } @@ -483,8 +514,13 @@ internal class FilterTextField( */ @VisibleForTesting internal sealed class FilterHistoryItem { - class Item(val filter: String, var isFavorite: Boolean, val count: Int?, private val filterParser: LogcatFilterParser) - : FilterHistoryItem() { + class Item( + val filter: String, + var isFavorite: Boolean, + val count: Int?, + private val filterParser: LogcatFilterParser, + var isFavoriteHovered: Boolean = false, + ) : FilterHistoryItem() { private val filterName = filterParser.parse(filter)?.getFilterName() @@ -501,7 +537,14 @@ internal class FilterTextField( else { filterLabel.append(filter) } - favoriteLabel.icon = if (isFavorite) FAVORITE_ON_ICON else FAVORITE_BLANK_ICON + // This can be mico optimized, but it's more readable like this + favoriteLabel.icon = when { + isFavoriteHovered && isFavorite -> FAVORITE_FILLED_POPUP_HOVER_ICON + isFavoriteHovered && !isFavorite -> FAVORITE_POPUP_HOVER_ICON + !isFavoriteHovered && isFavorite -> FAVORITE_ON_ICON + else -> FAVORITE_BLANK_ICON + } + countLabel.text = when (count) { null -> " ".repeat(3) in 0..99 -> "% 2d ".format(count) |