From 3ea70cdeaf6f5875001f995ecdc7b95b0c45cbe2 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Sat, 28 May 2022 22:55:42 +0200 Subject: [PATCH] Fix: shortcut key highlight remains when cursor leaves list --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/ShortcutKeys.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index b393394513..1f5313eabe 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -29,6 +29,7 @@ - Fix: [#17221] Object ghosts and tooltips follow invisible cursor when moving the viewport by right-click dragging. - Fix: [#17255] Cursor position is incorrect when adjusting terrain and water height. - Fix: [#17261] Hand cursor position is incorrect when dragging items in the Inventions List window. +- Fix: [#17292] Rows in shortcut key list stay highlighted when cursor leaves list. - Fix: [#17295] Pause status not cleared when loading a scenario made from a converted paused save. 0.4.0 (2022-04-25) diff --git a/src/openrct2-ui/windows/ShortcutKeys.cpp b/src/openrct2-ui/windows/ShortcutKeys.cpp index 1ab1953552..79ddc33140 100644 --- a/src/openrct2-ui/windows/ShortcutKeys.cpp +++ b/src/openrct2-ui/windows/ShortcutKeys.cpp @@ -175,7 +175,7 @@ private: std::vector _tabs; std::vector _widgets; std::vector _list; - std::optional _highlightedItem; + int_fast16_t _highlightedItem; size_t _currentTabIndex{}; uint32_t _tabAnimationIndex{}; @@ -199,6 +199,13 @@ public: void OnUpdate() override { + // Remove highlight when the mouse is not hovering over the list + if (_highlightedItem != -1 && !WidgetIsHighlighted(this, WIDX_SCROLL)) + { + _highlightedItem = -1; + InvalidateWidget(WIDX_SCROLL); + } + _tabAnimationIndex++; InvalidateWidget(static_cast(WIDX_TAB_0 + _currentTabIndex)); } @@ -267,12 +274,16 @@ public: void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - auto index = static_cast((screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT); - if (index < _list.size()) + auto index = static_cast((screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT); + if (static_cast(index) < _list.size()) { _highlightedItem = index; Invalidate(); } + else + { + _highlightedItem = -1; + } } void OnScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override @@ -319,7 +330,7 @@ public: } else { - auto isHighlighted = _highlightedItem == i; + auto isHighlighted = _highlightedItem == static_cast(i); DrawItem(dpi, y, scrollWidth, _list[i], isHighlighted); } }