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

View file

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