mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Use new animations engine in all Basic-s.
This commit is contained in:
@@ -71,7 +71,9 @@ DialogsInner::DialogsInner(QWidget *parent, not_null<Window::Controller*> contro
|
||||
, _dialogs(std::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Date))
|
||||
, _contactsNoDialogs(std::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Name))
|
||||
, _contacts(std::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Name))
|
||||
, _a_pinnedShifting(animation(this, &DialogsInner::step_pinnedShifting))
|
||||
, _pinnedShiftAnimation([=](crl::time now) {
|
||||
return pinnedShiftAnimationCallback(now);
|
||||
})
|
||||
, _addContactLnk(this, lang(lng_add_contact_button))
|
||||
, _cancelSearchInChat(this, st::dialogsCancelSearchInPeer)
|
||||
, _cancelSearchFromUser(this, st::dialogsCancelSearchInPeer) {
|
||||
@@ -255,10 +257,6 @@ void DialogsInner::paintRegion(Painter &p, const QRegion ®ion, bool paintingO
|
||||
auto fullWidth = getFullWidth();
|
||||
auto ms = crl::now();
|
||||
if (_state == State::Default) {
|
||||
if (_a_pinnedShifting.animating()) {
|
||||
_a_pinnedShifting.step(ms, false);
|
||||
}
|
||||
|
||||
auto rows = shownDialogs();
|
||||
auto dialogsClip = r;
|
||||
if (_dialogsImportant) {
|
||||
@@ -855,7 +853,7 @@ void DialogsInner::mousePressEvent(QMouseEvent *e) {
|
||||
} else if (_pressed) {
|
||||
auto row = _pressed;
|
||||
row->addRipple(e->pos() - QPoint(0, dialogsOffset() + _pressed->pos() * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [this, row] {
|
||||
if (!_a_pinnedShifting.animating()) {
|
||||
if (!_pinnedShiftAnimation.animating()) {
|
||||
row->entry()->updateChatListEntry();
|
||||
}
|
||||
});
|
||||
@@ -901,7 +899,7 @@ void DialogsInner::checkReorderPinnedStart(QPoint localPosition) {
|
||||
_pinnedOrder = Auth().data().pinnedDialogsOrder();
|
||||
_pinnedRows[_draggingIndex].yadd = anim::value(0, localPosition.y() - _dragStart.y());
|
||||
_pinnedRows[_draggingIndex].animStartTime = crl::now();
|
||||
_a_pinnedShifting.start();
|
||||
_pinnedShiftAnimation.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -959,7 +957,7 @@ void DialogsInner::finishReorderPinned() {
|
||||
}
|
||||
|
||||
_draggingIndex = -1;
|
||||
if (!_a_pinnedShifting.animating()) {
|
||||
if (!_pinnedShiftAnimation.animating()) {
|
||||
_pinnedRows.clear();
|
||||
_aboveIndex = -1;
|
||||
}
|
||||
@@ -969,7 +967,7 @@ void DialogsInner::finishReorderPinned() {
|
||||
}
|
||||
|
||||
void DialogsInner::stopReorderPinned() {
|
||||
_a_pinnedShifting.stop();
|
||||
_pinnedShiftAnimation.stop();
|
||||
finishReorderPinned();
|
||||
}
|
||||
|
||||
@@ -990,7 +988,7 @@ int DialogsInner::updateReorderIndexGetCount() {
|
||||
_draggingIndex = index;
|
||||
_aboveIndex = _draggingIndex;
|
||||
while (count > _pinnedRows.size()) {
|
||||
_pinnedRows.push_back(PinnedRow());
|
||||
_pinnedRows.emplace_back();
|
||||
}
|
||||
while (count < _pinnedRows.size()) {
|
||||
_pinnedRows.pop_back();
|
||||
@@ -1007,7 +1005,7 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) {
|
||||
|
||||
auto yaddWas = _pinnedRows[_draggingIndex].yadd.current();
|
||||
auto shift = 0;
|
||||
auto ms = crl::now();
|
||||
auto now = crl::now();
|
||||
auto rowHeight = st::dialogsRowHeight;
|
||||
if (_dragStart.y() > localPosition.y() && _draggingIndex > 0) {
|
||||
shift = -floorclamp(_dragStart.y() - localPosition.y() + (rowHeight / 2), rowHeight, 0, _draggingIndex);
|
||||
@@ -1016,7 +1014,7 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) {
|
||||
shownDialogs()->movePinned(_dragging, -1);
|
||||
std::swap(_pinnedRows[from], _pinnedRows[from - 1]);
|
||||
_pinnedRows[from].yadd = anim::value(_pinnedRows[from].yadd.current() - rowHeight, 0);
|
||||
_pinnedRows[from].animStartTime = ms;
|
||||
_pinnedRows[from].animStartTime = now;
|
||||
}
|
||||
} else if (_dragStart.y() < localPosition.y() && _draggingIndex + 1 < pinnedCount) {
|
||||
shift = floorclamp(localPosition.y() - _dragStart.y() + (rowHeight / 2), rowHeight, 0, pinnedCount - _draggingIndex - 1);
|
||||
@@ -1025,15 +1023,15 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) {
|
||||
shownDialogs()->movePinned(_dragging, 1);
|
||||
std::swap(_pinnedRows[from], _pinnedRows[from + 1]);
|
||||
_pinnedRows[from].yadd = anim::value(_pinnedRows[from].yadd.current() + rowHeight, 0);
|
||||
_pinnedRows[from].animStartTime = ms;
|
||||
_pinnedRows[from].animStartTime = now;
|
||||
}
|
||||
}
|
||||
if (shift) {
|
||||
_draggingIndex += shift;
|
||||
_aboveIndex = _draggingIndex;
|
||||
_dragStart.setY(_dragStart.y() + shift * rowHeight);
|
||||
if (!_a_pinnedShifting.animating()) {
|
||||
_a_pinnedShifting.start();
|
||||
if (!_pinnedShiftAnimation.animating()) {
|
||||
_pinnedShiftAnimation.start();
|
||||
}
|
||||
}
|
||||
_aboveTopShift = qCeil(_pinnedRows[_aboveIndex].yadd.current());
|
||||
@@ -1041,22 +1039,22 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) {
|
||||
if (!_pinnedRows[_draggingIndex].animStartTime) {
|
||||
_pinnedRows[_draggingIndex].yadd.finish();
|
||||
}
|
||||
_a_pinnedShifting.step(ms, true);
|
||||
pinnedShiftAnimationCallback(now);
|
||||
|
||||
auto countDraggingScrollDelta = [this, localPosition] {
|
||||
const auto delta = [&] {
|
||||
if (localPosition.y() < _visibleTop) {
|
||||
return localPosition.y() - _visibleTop;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
}();
|
||||
|
||||
emit draggingScrollDelta(countDraggingScrollDelta());
|
||||
emit draggingScrollDelta(delta);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DialogsInner::step_pinnedShifting(crl::time ms, bool timer) {
|
||||
bool DialogsInner::pinnedShiftAnimationCallback(crl::time now) {
|
||||
if (anim::Disabled()) {
|
||||
ms += st::stickersRowDuration;
|
||||
now += st::stickersRowDuration;
|
||||
}
|
||||
|
||||
auto wasAnimating = false;
|
||||
@@ -1069,8 +1067,8 @@ void DialogsInner::step_pinnedShifting(crl::time ms, bool timer) {
|
||||
wasAnimating = true;
|
||||
if (updateMin < 0) updateMin = i;
|
||||
updateMax = i;
|
||||
if (start + st::stickersRowDuration > ms && ms >= start) {
|
||||
_pinnedRows[i].yadd.update(float64(ms - start) / st::stickersRowDuration, anim::sineInOut);
|
||||
if (start + st::stickersRowDuration > now && now >= start) {
|
||||
_pinnedRows[i].yadd.update(float64(now - start) / st::stickersRowDuration, anim::sineInOut);
|
||||
animating = true;
|
||||
} else {
|
||||
_pinnedRows[i].yadd.finish();
|
||||
@@ -1078,33 +1076,31 @@ void DialogsInner::step_pinnedShifting(crl::time ms, bool timer) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (timer || (wasAnimating && !animating)) {
|
||||
updateReorderIndexGetCount();
|
||||
if (_draggingIndex >= 0) {
|
||||
if (updateMin < 0 || updateMin > _draggingIndex) {
|
||||
updateMin = _draggingIndex;
|
||||
}
|
||||
if (updateMax < _draggingIndex) updateMax = _draggingIndex;
|
||||
updateReorderIndexGetCount();
|
||||
if (_draggingIndex >= 0) {
|
||||
if (updateMin < 0 || updateMin > _draggingIndex) {
|
||||
updateMin = _draggingIndex;
|
||||
}
|
||||
if (updateMin >= 0) {
|
||||
auto top = pinnedOffset();
|
||||
auto updateFrom = top + st::dialogsRowHeight * (updateMin - 1);
|
||||
auto updateHeight = st::dialogsRowHeight * (updateMax - updateMin + 3);
|
||||
if (base::in_range(_aboveIndex, 0, _pinnedRows.size())) {
|
||||
// Always include currently dragged chat in its current and old positions.
|
||||
auto aboveRowBottom = top + (_aboveIndex + 1) * st::dialogsRowHeight;
|
||||
auto aboveTopShift = qCeil(_pinnedRows[_aboveIndex].yadd.current());
|
||||
accumulate_max(updateHeight, (aboveRowBottom - updateFrom) + _aboveTopShift);
|
||||
accumulate_max(updateHeight, (aboveRowBottom - updateFrom) + aboveTopShift);
|
||||
_aboveTopShift = aboveTopShift;
|
||||
}
|
||||
update(0, updateFrom, getFullWidth(), updateHeight);
|
||||
if (updateMax < _draggingIndex) updateMax = _draggingIndex;
|
||||
}
|
||||
if (updateMin >= 0) {
|
||||
auto top = pinnedOffset();
|
||||
auto updateFrom = top + st::dialogsRowHeight * (updateMin - 1);
|
||||
auto updateHeight = st::dialogsRowHeight * (updateMax - updateMin + 3);
|
||||
if (base::in_range(_aboveIndex, 0, _pinnedRows.size())) {
|
||||
// Always include currently dragged chat in its current and old positions.
|
||||
auto aboveRowBottom = top + (_aboveIndex + 1) * st::dialogsRowHeight;
|
||||
auto aboveTopShift = qCeil(_pinnedRows[_aboveIndex].yadd.current());
|
||||
accumulate_max(updateHeight, (aboveRowBottom - updateFrom) + _aboveTopShift);
|
||||
accumulate_max(updateHeight, (aboveRowBottom - updateFrom) + aboveTopShift);
|
||||
_aboveTopShift = aboveTopShift;
|
||||
}
|
||||
update(0, updateFrom, getFullWidth(), updateHeight);
|
||||
}
|
||||
if (!animating) {
|
||||
_aboveIndex = _draggingIndex;
|
||||
_a_pinnedShifting.stop();
|
||||
}
|
||||
return animating;
|
||||
}
|
||||
|
||||
void DialogsInner::mouseReleaseEvent(QMouseEvent *e) {
|
||||
@@ -1120,8 +1116,8 @@ void DialogsInner::mousePressReleased(
|
||||
if (_draggingIndex >= 0) {
|
||||
_pinnedRows[_draggingIndex].yadd.start(0.);
|
||||
_pinnedRows[_draggingIndex].animStartTime = crl::now();
|
||||
if (!_a_pinnedShifting.animating()) {
|
||||
_a_pinnedShifting.start();
|
||||
if (!_pinnedShiftAnimation.animating()) {
|
||||
_pinnedShiftAnimation.start();
|
||||
}
|
||||
}
|
||||
finishReorderPinned();
|
||||
|
Reference in New Issue
Block a user