mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Replaced snap util function with std::clamp.
This commit is contained in:
@@ -179,12 +179,15 @@ void SuggestionsWidget::scrollByWheelEvent(not_null<QWheelEvent*> e) {
|
||||
const auto delta = e->pixelDelta().x()
|
||||
? e->pixelDelta().x()
|
||||
: e->angleDelta().x();
|
||||
return snap(current - ((rtl() ? -1 : 1) * delta), 0, _scrollMax);
|
||||
return std::clamp(
|
||||
current - ((rtl() ? -1 : 1) * delta),
|
||||
0,
|
||||
_scrollMax);
|
||||
} else if (vertical) {
|
||||
const auto delta = e->pixelDelta().y()
|
||||
? e->pixelDelta().y()
|
||||
: e->angleDelta().y();
|
||||
return snap(current - delta, 0, _scrollMax);
|
||||
return std::clamp(current - delta, 0, _scrollMax);
|
||||
}
|
||||
return current;
|
||||
}();
|
||||
@@ -241,7 +244,7 @@ void SuggestionsWidget::paintEvent(QPaintEvent *e) {
|
||||
|
||||
void SuggestionsWidget::paintFadings(Painter &p) const {
|
||||
const auto scroll = scrollCurrent();
|
||||
const auto o_left = snap(
|
||||
const auto o_left = std::clamp(
|
||||
scroll / float64(st::emojiSuggestionsFadeAfter),
|
||||
0.,
|
||||
1.);
|
||||
@@ -256,7 +259,7 @@ void SuggestionsWidget::paintFadings(Painter &p) const {
|
||||
st::emojiSuggestionsFadeLeft.fill(p, rect);
|
||||
p.setOpacity(1.);
|
||||
}
|
||||
const auto o_right = snap(
|
||||
const auto o_right = std::clamp(
|
||||
(_scrollMax - scroll) / float64(st::emojiSuggestionsFadeAfter),
|
||||
0.,
|
||||
1.);
|
||||
@@ -422,7 +425,7 @@ void SuggestionsWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
const auto globalPosition = e->globalPos();
|
||||
if (_dragScrollStart >= 0) {
|
||||
const auto delta = (_mousePressPosition.x() - globalPosition.x());
|
||||
const auto scroll = snap(
|
||||
const auto scroll = std::clamp(
|
||||
_dragScrollStart + (rtl() ? -1 : 1) * delta,
|
||||
0,
|
||||
_scrollMax);
|
||||
|
@@ -404,7 +404,7 @@ void StickersListWidget::Footer::setSelectedIcon(
|
||||
auto iconsCountForCentering = (2 * _iconSel + 1);
|
||||
auto iconsWidthForCentering = iconsCountForCentering
|
||||
* st::stickerIconWidth;
|
||||
auto iconsXFinal = snap(
|
||||
auto iconsXFinal = std::clamp(
|
||||
(_iconsLeft + iconsWidthForCentering + _iconsRight - width()) / 2,
|
||||
0,
|
||||
_iconsMax);
|
||||
@@ -486,13 +486,19 @@ void StickersListWidget::Footer::paintSelectionBar(Painter &p) const {
|
||||
}
|
||||
|
||||
void StickersListWidget::Footer::paintLeftRightFading(Painter &p) const {
|
||||
auto o_left = snap(_iconsX.current() / st::stickerIconLeft.width(), 0., 1.);
|
||||
auto o_left = std::clamp(
|
||||
_iconsX.current() / st::stickerIconLeft.width(),
|
||||
0.,
|
||||
1.);
|
||||
if (o_left > 0) {
|
||||
p.setOpacity(o_left);
|
||||
st::stickerIconLeft.fill(p, style::rtlrect(_iconsLeft, _iconsTop, st::stickerIconLeft.width(), st::emojiFooterHeight, width()));
|
||||
p.setOpacity(1.);
|
||||
}
|
||||
auto o_right = snap((_iconsMax - _iconsX.current()) / st::stickerIconRight.width(), 0., 1.);
|
||||
auto o_right = std::clamp(
|
||||
(_iconsMax - _iconsX.current()) / st::stickerIconRight.width(),
|
||||
0.,
|
||||
1.);
|
||||
if (o_right > 0) {
|
||||
p.setOpacity(o_right);
|
||||
st::stickerIconRight.fill(p, style::rtlrect(width() - _iconsRight - st::stickerIconRight.width(), _iconsTop, st::stickerIconRight.width(), st::emojiFooterHeight, width()));
|
||||
@@ -554,7 +560,11 @@ void StickersListWidget::Footer::mouseMoveEvent(QMouseEvent *e) {
|
||||
}
|
||||
}
|
||||
if (_iconsDragging) {
|
||||
auto newX = snap(_iconsStartX + (rtl() ? -1 : 1) * (_iconsMouseDown.x() - _iconsMousePos.x()), 0, _iconsMax);
|
||||
auto newX = std::clamp(
|
||||
(rtl() ? -1 : 1) * (_iconsMouseDown.x() - _iconsMousePos.x())
|
||||
+ _iconsStartX,
|
||||
0,
|
||||
_iconsMax);
|
||||
if (newX != qRound(_iconsX.current())) {
|
||||
_iconsX = anim::value(newX, newX);
|
||||
_iconsStartAnim = 0;
|
||||
@@ -589,7 +599,10 @@ void StickersListWidget::Footer::mouseReleaseEvent(QMouseEvent *e) {
|
||||
}
|
||||
|
||||
void StickersListWidget::Footer::finishDragging() {
|
||||
auto newX = snap(_iconsStartX + _iconsMouseDown.x() - _iconsMousePos.x(), 0, _iconsMax);
|
||||
auto newX = std::clamp(
|
||||
_iconsStartX + _iconsMouseDown.x() - _iconsMousePos.x(),
|
||||
0,
|
||||
_iconsMax);
|
||||
if (newX != qRound(_iconsX.current())) {
|
||||
_iconsX = anim::value(newX, newX);
|
||||
_iconsStartAnim = 0;
|
||||
@@ -621,9 +634,19 @@ void StickersListWidget::Footer::scrollByWheelEvent(
|
||||
}
|
||||
auto newX = qRound(_iconsX.current());
|
||||
if (/*_horizontal && */horizontal) {
|
||||
newX = snap(newX - (rtl() ? -1 : 1) * (e->pixelDelta().x() ? e->pixelDelta().x() : e->angleDelta().x()), 0, _iconsMax);
|
||||
newX = std::clamp(
|
||||
newX - (rtl() ? -1 : 1) * (e->pixelDelta().x()
|
||||
? e->pixelDelta().x()
|
||||
: e->angleDelta().x()),
|
||||
0,
|
||||
_iconsMax);
|
||||
} else if (/*!_horizontal && */vertical) {
|
||||
newX = snap(newX - (e->pixelDelta().y() ? e->pixelDelta().y() : e->angleDelta().y()), 0, _iconsMax);
|
||||
newX = std::clamp(
|
||||
newX - (e->pixelDelta().y()
|
||||
? e->pixelDelta().y()
|
||||
: e->angleDelta().y()),
|
||||
0,
|
||||
_iconsMax);
|
||||
}
|
||||
if (newX != qRound(_iconsX.current())) {
|
||||
_iconsX = anim::value(newX, newX);
|
||||
|
@@ -151,7 +151,7 @@ void TabbedPanel::updateContentHeight() {
|
||||
auto marginsHeight = _selector->marginTop() + _selector->marginBottom();
|
||||
auto availableHeight = _bottom - marginsHeight;
|
||||
auto wantedContentHeight = qRound(_heightRatio * availableHeight) - addedHeight;
|
||||
auto contentHeight = marginsHeight + snap(
|
||||
auto contentHeight = marginsHeight + std::clamp(
|
||||
wantedContentHeight,
|
||||
_minContentHeight,
|
||||
_maxContentHeight);
|
||||
|
@@ -153,8 +153,9 @@ void TabbedSelector::SlideAnimation::paintFrame(QPainter &p, float64 dt, float64
|
||||
auto rightAlpha = (leftToRight ? departingAlpha : arrivingAlpha);
|
||||
|
||||
// _innerLeft ..(left).. leftTo ..(both).. bothTo ..(none).. noneTo ..(right).. _innerRight
|
||||
auto leftTo = _innerLeft + snap(_innerWidth + leftCoord, 0, _innerWidth);
|
||||
auto rightFrom = _innerLeft + snap(rightCoord, 0, _innerWidth);
|
||||
auto leftTo = _innerLeft
|
||||
+ std::clamp(_innerWidth + leftCoord, 0, _innerWidth);
|
||||
auto rightFrom = _innerLeft + std::clamp(rightCoord, 0, _innerWidth);
|
||||
auto painterRightFrom = rightFrom / cIntRetinaFactor();
|
||||
if (opacity < 1.) {
|
||||
_frame.fill(Qt::transparent);
|
||||
|
Reference in New Issue
Block a user