Fixed mouse wheel handling in vertical drum picker without animation.

This commit is contained in:
23rd 2023-10-31 13:05:51 +03:00
parent 1cfda38345
commit 6493cb9ed8
1 changed files with 22 additions and 6 deletions

View File

@ -11,6 +11,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_basic.h"
namespace Ui {
namespace {
constexpr auto kAlmostIndex = float64(.99);
} // namespace
PickerAnimation::PickerAnimation() = default;
@ -26,6 +31,23 @@ void PickerAnimation::jumpToOffset(int offset) {
value);
_updates.fire(_result.current - was);
};
if (anim::Disabled()) {
auto value = float64(0.);
const auto diff = _result.to - _result.from;
const auto step = std::min(
kAlmostIndex,
1. / (std::max(1. - kAlmostIndex, std::abs(diff) + 1)));
while (true) {
value += step;
if (value >= 1.) {
callback(1.);
break;
} else {
callback(value);
}
}
return;
}
_animation.start(
std::move(callback),
0.,
@ -94,20 +116,14 @@ VerticalDrumPicker::VerticalDrumPicker(
}, lifetime());
_animation.updates(
) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](PickerAnimation::Shift shift) {
increaseShift(shift);
if (anim::Disabled()) {
animationDataFromIndex();
_animation.jumpToOffset(0);
}
}, lifetime());
}
void VerticalDrumPicker::increaseShift(float64 by) {
{
// Guard input.
constexpr auto kAlmostIndex = .99;
if (by >= 1.) {
by = kAlmostIndex;
} else if (by <= -1.) {