Browse Source

Fix UI list double-click handling (#8272)

pull/8275/head
LP 4 months ago committed by GitHub
parent
commit
65c1076135
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 45
      Source/DiabloUI/diabloui.cpp

45
Source/DiabloUI/diabloui.cpp

@ -111,6 +111,10 @@ bool UiItemsWraps;
std::optional<TextInputState> UiTextInputState;
bool allowEmptyTextInput = false;
constexpr Uint32 ListDoubleClickTimeMs = 500;
std::size_t lastListClickIndex = static_cast<std::size_t>(-1);
Uint32 lastListClickTicks = 0;
struct ScrollBarState {
bool upArrowPressed;
bool downArrowPressed;
@ -992,10 +996,6 @@ bool HandleMouseEventArtTextButton(const SDL_Event &event, const UiArtTextButton
return true;
}
#ifdef USE_SDL1
Uint32 dbClickTimer;
#endif
bool HandleMouseEventList(const SDL_Event &event, UiList *uiList)
{
if (event.button.button != SDL_BUTTON_LEFT)
@ -1016,25 +1016,32 @@ bool HandleMouseEventList(const SDL_Event &event, UiList *uiList)
}
index += listOffset;
if (gfnListFocus != nullptr && SelectedItem != index) {
UiFocus(index, true, false);
#ifdef USE_SDL1
dbClickTimer = SDL_GetTicks();
} else if (gfnListFocus == NULL || dbClickTimer + 500 >= SDL_GetTicks()) {
const bool hasFocusCallback = gfnListFocus != nullptr;
const Uint32 ticksNow = SDL_GetTicks();
const bool recentlyClickedSameItem = hasFocusCallback && lastListClickIndex == index && ticksNow - lastListClickTicks <= ListDoubleClickTimeMs;
#ifndef USE_SDL1
const bool sdlReportedDoubleClick = event.button.clicks >= 2;
#else
} else if (gfnListFocus == nullptr || event.button.clicks >= 2) {
#endif
if (HasAnyOf(uiList->GetItem(index)->uiFlags, UiFlags::ElementHidden | UiFlags::ElementDisabled))
return false;
SelectedItem = index;
UiFocusNavigationSelect();
#ifdef USE_SDL1
} else {
dbClickTimer = SDL_GetTicks();
const bool sdlReportedDoubleClick = false;
#endif
const bool doubleClicked = recentlyClickedSameItem || sdlReportedDoubleClick;
lastListClickIndex = index;
lastListClickTicks = ticksNow;
if (hasFocusCallback && SelectedItem != index) {
UiFocus(index, true, false);
return true;
}
if (hasFocusCallback && !doubleClicked) {
return true;
}
if (HasAnyOf(uiList->GetItem(index)->uiFlags, UiFlags::ElementHidden | UiFlags::ElementDisabled))
return false;
SelectedItem = index;
UiFocusNavigationSelect();
return true;
}

Loading…
Cancel
Save