Skip to content

Commit

Permalink
Fixed mouse wheel handling in vertical drum picker without animation.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Oct 31, 2023
1 parent 1cfda38 commit 6493cb9
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Telegram/SourceFiles/ui/widgets/vertical_drum_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ For license and copyright information please follow this link:
#include "styles/style_basic.h"

namespace Ui {
namespace {

constexpr auto kAlmostIndex = float64(.99);

} // namespace

PickerAnimation::PickerAnimation() = default;

Expand All @@ -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.,
Expand Down Expand Up @@ -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.) {
Expand Down

0 comments on commit 6493cb9

Please sign in to comment.