From dd01ece14a2cfb12f172f033653e04ca0e80a10f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 23 Jan 2021 06:29:50 +0300 Subject: [PATCH] Replaced snap util function with std::clamp. --- Telegram/SourceFiles/apiwrap.cpp | 2 +- Telegram/SourceFiles/boxes/edit_color_box.cpp | 22 +++++------ Telegram/SourceFiles/boxes/edit_color_box.h | 4 +- Telegram/SourceFiles/boxes/peer_list_box.cpp | 5 ++- .../chat_helpers/emoji_suggestions_widget.cpp | 13 ++++--- .../chat_helpers/stickers_list_widget.cpp | 37 +++++++++++++++---- .../SourceFiles/chat_helpers/tabbed_panel.cpp | 2 +- .../chat_helpers/tabbed_selector.cpp | 5 ++- Telegram/SourceFiles/core/core_settings.cpp | 7 +++- Telegram/SourceFiles/core/utils.h | 19 +++++----- Telegram/SourceFiles/data/data_document.cpp | 2 +- .../SourceFiles/data/data_peer_values.cpp | 2 +- Telegram/SourceFiles/data/data_photo.cpp | 2 +- .../dialogs/dialogs_inner_widget.cpp | 16 +++++++- .../admin_log/history_admin_log_inner.cpp | 4 +- .../history/feed/history_feed_section.cpp | 12 ++++-- .../history/history_inner_widget.cpp | 20 ++++++++-- .../SourceFiles/history/history_widget.cpp | 5 ++- .../history/view/history_view_list_widget.cpp | 4 +- .../history/view/history_view_message.cpp | 2 +- .../view/history_view_pinned_section.cpp | 7 +++- .../view/history_view_replies_section.cpp | 7 +++- .../view/history_view_schedule_box.cpp | 2 +- .../view/history_view_scheduled_section.cpp | 7 +++- .../view/media/history_view_document.cpp | 13 ++++++- .../SourceFiles/info/info_layer_widget.cpp | 2 +- .../inline_bots/inline_results_widget.cpp | 5 ++- Telegram/SourceFiles/intro/intro_step.cpp | 6 ++- .../main/main_session_settings.cpp | 2 +- Telegram/SourceFiles/mainwidget.cpp | 2 +- .../media/player/media_player_float.cpp | 2 +- .../media/player/media_player_widget.cpp | 4 +- .../view/media_view_playback_controls.cpp | 4 +- .../view/media_view_playback_progress.cpp | 4 +- .../SourceFiles/mtproto/session_private.cpp | 5 ++- .../passport/passport_panel_details_row.cpp | 2 +- .../SourceFiles/settings/settings_intro.cpp | 2 +- .../settings/settings_notifications.cpp | 2 +- .../details/storage_settings_scheme.cpp | 4 +- .../storage/storage_cloud_blob.cpp | 2 +- .../support/support_autocomplete.cpp | 2 +- .../SourceFiles/ui/effects/round_checkbox.cpp | 4 +- .../ui/widgets/continuous_sliders.cpp | 4 +- .../ui/widgets/discrete_sliders.cpp | 6 ++- 44 files changed, 193 insertions(+), 92 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index f116c33cf5..af47774f12 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -354,7 +354,7 @@ void ApiWrap::requestTermsUpdate() { const auto requestNext = [&](auto &&data) { const auto timeout = (data.vexpires().v - base::unixtime::now()); - _termsUpdateSendAt = crl::now() + snap( + _termsUpdateSendAt = crl::now() + std::clamp( timeout * crl::time(1000), kTermsUpdateTimeoutMin, kTermsUpdateTimeoutMax); diff --git a/Telegram/SourceFiles/boxes/edit_color_box.cpp b/Telegram/SourceFiles/boxes/edit_color_box.cpp index 86582b30d4..8e39dae790 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_color_box.cpp @@ -228,8 +228,8 @@ void EditColorBox::Picker::preparePaletteHSL() { } void EditColorBox::Picker::updateCurrentPoint(QPoint localPosition) { - auto x = snap(localPosition.x(), 0, width()) / float64(width()); - auto y = snap(localPosition.y(), 0, height()) / float64(height()); + auto x = std::clamp(localPosition.x(), 0, width()) / float64(width()); + auto y = std::clamp(localPosition.y(), 0, height()) / float64(height()); if (_x != x || _y != y) { _x = x; _y = y; @@ -245,14 +245,14 @@ void EditColorBox::Picker::setHSB(HSB hsb) { _topright = _topright.toRgb(); _bottomleft = _bottomright = QColor(0, 0, 0); - _x = snap(hsb.saturation / 255., 0., 1.); - _y = 1. - snap(hsb.brightness / 255., 0., 1.); + _x = std::clamp(hsb.saturation / 255., 0., 1.); + _y = 1. - std::clamp(hsb.brightness / 255., 0., 1.); } else { _topleft = _topright = QColor::fromHsl(0, 255, hsb.brightness); _bottomleft = _bottomright = QColor::fromHsl(0, 0, hsb.brightness); - _x = snap(hsb.hue / 360., 0., 1.); - _y = 1. - snap(hsb.saturation / 255., 0., 1.); + _x = std::clamp(hsb.hue / 360., 0., 1.); + _y = 1. - std::clamp(hsb.saturation / 255., 0., 1.); } _paletteInvalidated = true; @@ -291,7 +291,7 @@ public: return _value; } void setValue(float64 value) { - _value = snap(value, 0., 1.); + _value = std::clamp(value, 0., 1.); update(); } void setHSB(HSB hsb); @@ -508,12 +508,12 @@ float64 EditColorBox::Slider::valueFromColor(QColor color) const { } float64 EditColorBox::Slider::valueFromHue(int hue) const { - return (1. - snap(hue, 0, 360) / 360.); + return (1. - std::clamp(hue, 0, 360) / 360.); } void EditColorBox::Slider::setAlpha(int alpha) { if (_type == Type::Opacity) { - _value = snap(alpha, 0, 255) / 255.; + _value = std::clamp(alpha, 0, 255) / 255.; update(); } } @@ -534,7 +534,7 @@ void EditColorBox::Slider::updatePixmapFromMask() { void EditColorBox::Slider::updateCurrentPoint(QPoint localPosition) { auto coord = (isHorizontal() ? localPosition.x() : localPosition.y()) - st::colorSliderSkip; auto maximum = (isHorizontal() ? width() : height()) - 2 * st::colorSliderSkip; - auto value = snap(coord, 0, maximum) / float64(maximum); + auto value = std::clamp(coord, 0, maximum) / float64(maximum); if (_value != value) { _value = value; update(); @@ -663,7 +663,7 @@ void EditColorBox::Field::wheelEvent(QWheelEvent *e) { void EditColorBox::Field::changeValue(int delta) { auto currentValue = value(); - auto newValue = snap(currentValue + delta, 0, _limit); + auto newValue = std::clamp(currentValue + delta, 0, _limit); if (newValue != currentValue) { setText(QString::number(newValue)); setFocus(); diff --git a/Telegram/SourceFiles/boxes/edit_color_box.h b/Telegram/SourceFiles/boxes/edit_color_box.h index 28ad8cc5a4..5c2e7170a9 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.h +++ b/Telegram/SourceFiles/boxes/edit_color_box.h @@ -66,10 +66,10 @@ private: [[nodiscard]] QColor applyLimits(QColor color) const; int percentFromByte(int byte) { - return snap(qRound(byte * 100 / 255.), 0, 100); + return std::clamp(qRound(byte * 100 / 255.), 0, 100); } int percentToByte(int percent) { - return snap(qRound(percent * 255 / 100.), 0, 255); + return std::clamp(qRound(percent * 255 / 100.), 0, 255); } class Picker; diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 56e0f15683..281de0b959 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -1440,7 +1440,10 @@ PeerListContent::SkipResult PeerListContent::selectSkip(int direction) { } // Snap the index. - newSelectedIndex = snap(newSelectedIndex, firstEnabled - 1, lastEnabled); + newSelectedIndex = std::clamp( + newSelectedIndex, + firstEnabled - 1, + lastEnabled); // Skip the disabled rows. if (newSelectedIndex < firstEnabled) { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp index 772d2e0cec..d96472682a 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp @@ -179,12 +179,15 @@ void SuggestionsWidget::scrollByWheelEvent(not_null 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); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 017c5e27e6..8a92680ada 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -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); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index 04afc8f336..bb946ec44b 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -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); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 9b9a929107..739b9ccc44 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -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); diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index 5eb5bbcd8e..ca70b71c67 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -101,7 +101,7 @@ QByteArray Settings::serialize() const { << qint32(_floatPlayerColumn) << qint32(_floatPlayerCorner) << qint32(_thirdSectionInfoEnabled ? 1 : 0) - << qint32(snap( + << qint32(std::clamp( qRound(_dialogsWidthRatio.current() * 1000000), 0, 1000000)) @@ -259,7 +259,10 @@ void Settings::addFromSerialized(const QByteArray &serialized) { >> thirdColumnWidth >> thirdSectionExtendedBy >> notifyFromAll; - dialogsWidthRatio = snap(dialogsWidthRatioInt / 1000000., 0., 1.); + dialogsWidthRatio = std::clamp( + dialogsWidthRatioInt / 1000000., + 0., + 1.); } if (!stream.atEnd()) { stream >> nativeWindowFrame; diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index 90ae40d0e4..f71ba5216a 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -124,11 +124,6 @@ T rand_value() { return result; } -template -inline T snap(const T &v, const T &_min, const T &_max) { - return (v < _min) ? _min : ((v > _max) ? _max : v); -} - QString translitRusEng(const QString &rus); QString rusKeyboardLayoutSwitch(const QString &from); @@ -150,16 +145,22 @@ inline int rowscount(int fullCount, int countPerRow) { return (fullCount + countPerRow - 1) / countPerRow; } inline int floorclamp(int value, int step, int lowest, int highest) { - return qMin(qMax(value / step, lowest), highest); + return std::clamp(value / step, lowest, highest); } inline int floorclamp(float64 value, int step, int lowest, int highest) { - return qMin(qMax(static_cast(std::floor(value / step)), lowest), highest); + return std::clamp( + static_cast(std::floor(value / step)), + lowest, + highest); } inline int ceilclamp(int value, int step, int lowest, int highest) { - return qMax(qMin((value + step - 1) / step, highest), lowest); + return std::clamp((value + step - 1) / step, lowest, highest); } inline int ceilclamp(float64 value, int32 step, int32 lowest, int32 highest) { - return qMax(qMin(static_cast(std::ceil(value / step)), highest), lowest); + return std::clamp( + static_cast(std::ceil(value / step)), + lowest, + highest); } static int32 FullArcLength = 360 * 16; diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index a615e17f02..c241c6b244 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -893,7 +893,7 @@ float64 DocumentData::progress() const { if (uploadingData->size > 0) { const auto result = float64(uploadingData->offset) / uploadingData->size; - return snap(result, 0., 1.); + return std::clamp(result, 0., 1.); } return 0.; } diff --git a/Telegram/SourceFiles/data/data_peer_values.cpp b/Telegram/SourceFiles/data/data_peer_values.cpp index 85f28a3018..606a5d7579 100644 --- a/Telegram/SourceFiles/data/data_peer_values.cpp +++ b/Telegram/SourceFiles/data/data_peer_values.cpp @@ -350,7 +350,7 @@ TimeId SortByOnlineValue(not_null user, TimeId now) { crl::time OnlineChangeTimeout(TimeId online, TimeId now) { const auto result = OnlinePhraseChangeInSeconds(online, now); Assert(result >= 0); - return snap( + return std::clamp( result * crl::time(1000), kMinOnlineChangeTimeout, kMaxOnlineChangeTimeout); diff --git a/Telegram/SourceFiles/data/data_photo.cpp b/Telegram/SourceFiles/data/data_photo.cpp index b1d67d1cd0..c382511f8f 100644 --- a/Telegram/SourceFiles/data/data_photo.cpp +++ b/Telegram/SourceFiles/data/data_photo.cpp @@ -166,7 +166,7 @@ float64 PhotoData::progress() const { if (uploadingData->size > 0) { const auto result = float64(uploadingData->offset) / uploadingData->size; - return snap(result, 0., 1.); + return std::clamp(result, 0., 1.); } return 0.; } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index d9bd464888..a4c87531cc 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -2437,7 +2437,13 @@ void InnerWidget::selectSkip(int32 direction) { ? _collapsedSelected : int(_collapsedRows.size() + (list->cfind(_selected) - list->cbegin() - _skipTopDialogs)); - cur = snap(cur + direction, 0, static_cast(_collapsedRows.size() + list->size() - _skipTopDialogs - 1)); + cur = std::clamp( + cur + direction, + 0, + static_cast(_collapsedRows.size() + + list->size() + - _skipTopDialogs + - 1)); if (cur < _collapsedRows.size()) { _collapsedSelected = cur; _selected = nullptr; @@ -2477,7 +2483,13 @@ void InnerWidget::selectSkip(int32 direction) { : (base::in_range(_peerSearchSelected, 0, _peerSearchResults.size()) ? (_peerSearchSelected + _filterResults.size() + _hashtagResults.size()) : (_searchedSelected + _peerSearchResults.size() + _filterResults.size() + _hashtagResults.size()))); - cur = snap(cur + direction, 0, static_cast(_hashtagResults.size() + _filterResults.size() + _peerSearchResults.size() + _searchResults.size()) - 1); + cur = std::clamp( + cur + direction, + 0, + static_cast(_hashtagResults.size() + + _filterResults.size() + + _peerSearchResults.size() + + _searchResults.size()) - 1); if (cur < _hashtagResults.size()) { _hashtagSelected = cur; _filteredSelected = _peerSearchSelected = _searchedSelected = -1; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index c3781e0d2e..bc26d4a182 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -1535,7 +1535,9 @@ void InnerWidget::mouseActionFinish(const QPoint &screenPos, Qt::MouseButton but void InnerWidget::updateSelected() { auto mousePosition = mapFromGlobal(_mousePosition); - auto point = QPoint(snap(mousePosition.x(), 0, width()), snap(mousePosition.y(), _visibleTop, _visibleBottom)); + auto point = QPoint( + std::clamp(mousePosition.x(), 0, width()), + std::clamp(mousePosition.y(), _visibleTop, _visibleBottom)); auto itemPoint = QPoint(); auto begin = std::rbegin(_items), end = std::rend(_items); diff --git a/Telegram/SourceFiles/history/feed/history_feed_section.cpp b/Telegram/SourceFiles/history/feed/history_feed_section.cpp index 571492247d..3ecf7ee0d0 100644 --- a/Telegram/SourceFiles/history/feed/history_feed_section.cpp +++ b/Telegram/SourceFiles/history/feed/history_feed_section.cpp @@ -181,10 +181,13 @@ void Widget::showAtPosition(Data::MessagePosition position) { bool Widget::showAtPositionNow(Data::MessagePosition position) { if (const auto scrollTop = _inner->scrollTopForPosition(position)) { const auto currentScrollTop = _scroll->scrollTop(); - const auto wanted = snap(*scrollTop, 0, _scroll->scrollTopMax()); + const auto wanted = std::clamp( + *scrollTop, + 0, + _scroll->scrollTopMax()); const auto fullDelta = (wanted - currentScrollTop); const auto limit = _scroll->height(); - const auto scrollDelta = snap(fullDelta, -limit, limit); + const auto scrollDelta = std::clamp(fullDelta, -limit, limit); _inner->animatedScrollTo( wanted, position, @@ -432,7 +435,10 @@ void Widget::listContentRefreshed() { } const auto position = *base::take(_nextAnimatedScrollPosition); if (const auto scrollTop = _inner->scrollTopForPosition(position)) { - const auto wanted = snap(*scrollTop, 0, _scroll->scrollTopMax()); + const auto wanted = std::clamp( + *scrollTop, + 0, + _scroll->scrollTopMax()); _inner->animatedScrollTo( wanted, position, diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 3ccafebf4d..38ab5c227e 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -838,16 +838,28 @@ void HistoryInner::touchUpdateSpeed() { const int oldSpeedX = _touchSpeed.x(); if ((oldSpeedY <= 0 && newSpeedY <= 0) || ((oldSpeedY >= 0 && newSpeedY >= 0) && (oldSpeedX <= 0 && newSpeedX <= 0)) || (oldSpeedX >= 0 && newSpeedX >= 0)) { - _touchSpeed.setY(snap((oldSpeedY + (newSpeedY / 4)), -Ui::kMaxScrollAccelerated, +Ui::kMaxScrollAccelerated)); - _touchSpeed.setX(snap((oldSpeedX + (newSpeedX / 4)), -Ui::kMaxScrollAccelerated, +Ui::kMaxScrollAccelerated)); + _touchSpeed.setY(std::clamp( + (oldSpeedY + (newSpeedY / 4)), + -Ui::kMaxScrollAccelerated, + +Ui::kMaxScrollAccelerated)); + _touchSpeed.setX(std::clamp( + (oldSpeedX + (newSpeedX / 4)), + -Ui::kMaxScrollAccelerated, + +Ui::kMaxScrollAccelerated)); } else { _touchSpeed = QPoint(); } } else { // we average the speed to avoid strange effects with the last delta if (!_touchSpeed.isNull()) { - _touchSpeed.setX(snap((_touchSpeed.x() / 4) + (newSpeedX * 3 / 4), -Ui::kMaxScrollFlick, +Ui::kMaxScrollFlick)); - _touchSpeed.setY(snap((_touchSpeed.y() / 4) + (newSpeedY * 3 / 4), -Ui::kMaxScrollFlick, +Ui::kMaxScrollFlick)); + _touchSpeed.setX(std::clamp( + (_touchSpeed.x() / 4) + (newSpeedX * 3 / 4), + -Ui::kMaxScrollFlick, + +Ui::kMaxScrollFlick)); + _touchSpeed.setY(std::clamp( + (_touchSpeed.y() / 4) + (newSpeedY * 3 / 4), + -Ui::kMaxScrollFlick, + +Ui::kMaxScrollFlick)); } else { _touchSpeed = QPoint(newSpeedX, newSpeedY); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 8772e78ac3..bdd9a0e6e3 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -976,7 +976,7 @@ void HistoryWidget::animatedScrollToItem(MsgId msgId) { return; } - auto scrollTo = snap( + auto scrollTo = std::clamp( itemTopForHighlight(to->mainView()), 0, _scroll->scrollTopMax()); @@ -6625,7 +6625,8 @@ void HistoryWidget::noSelectingScroll() { } bool HistoryWidget::touchScroll(const QPoint &delta) { - int32 scTop = _scroll->scrollTop(), scMax = _scroll->scrollTopMax(), scNew = snap(scTop - delta.y(), 0, scMax); + int32 scTop = _scroll->scrollTop(), scMax = _scroll->scrollTopMax(); + const auto scNew = std::clamp(scTop - delta.y(), 0, scMax); if (scNew == scTop) return false; _scroll->scrollToY(scNew); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 2fa4988448..49089a05a4 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2269,7 +2269,9 @@ void ListWidget::mouseActionFinish( void ListWidget::mouseActionUpdate() { auto mousePosition = mapFromGlobal(_mousePosition); - auto point = QPoint(snap(mousePosition.x(), 0, width()), snap(mousePosition.y(), _visibleTop, _visibleBottom)); + auto point = QPoint( + std::clamp(mousePosition.x(), 0, width()), + std::clamp(mousePosition.y(), _visibleTop, _visibleBottom)); const auto view = strictFindItemByY(point.y()); const auto item = view ? view->data().get() : nullptr; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index d5dac07359..3c2465a088 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1319,7 +1319,7 @@ TextState Message::textState( } checkForPointInTime(); if (const auto size = rightActionSize()) { - const auto fastShareSkip = snap( + const auto fastShareSkip = std::clamp( (g.height() - size->height()) / 2, 0, st::historyFastShareBottom); diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index 00199717da..b347da9f70 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -221,10 +221,13 @@ bool PinnedWidget::showAtPositionNow( const auto use = item ? item->position() : position; if (const auto scrollTop = _inner->scrollTopForPosition(use)) { const auto currentScrollTop = _scroll->scrollTop(); - const auto wanted = snap(*scrollTop, 0, _scroll->scrollTopMax()); + const auto wanted = std::clamp( + *scrollTop, + 0, + _scroll->scrollTopMax()); const auto fullDelta = (wanted - currentScrollTop); const auto limit = _scroll->height(); - const auto scrollDelta = snap(fullDelta, -limit, limit); + const auto scrollDelta = std::clamp(fullDelta, -limit, limit); const auto type = (animated == anim::type::instant) ? AnimatedScroll::None : (std::abs(fullDelta) > limit) diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index caf5059fe2..1ec9222627 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -1219,10 +1219,13 @@ bool RepliesWidget::showAtPositionNow( calculateNextReplyReturn(); } const auto currentScrollTop = _scroll->scrollTop(); - const auto wanted = snap(*scrollTop, 0, _scroll->scrollTopMax()); + const auto wanted = std::clamp( + *scrollTop, + 0, + _scroll->scrollTopMax()); const auto fullDelta = (wanted - currentScrollTop); const auto limit = _scroll->height(); - const auto scrollDelta = snap(fullDelta, -limit, limit); + const auto scrollDelta = std::clamp(fullDelta, -limit, limit); const auto type = (animated == anim::type::instant) ? AnimatedScroll::None : (std::abs(fullDelta) > limit) diff --git a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp index f09de4f01e..52b05ae4a4 100644 --- a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp +++ b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp @@ -433,7 +433,7 @@ void TimeInput::paintEvent(QPaintEvent *e) { auto borderShownDegree = _a_borderShown.value(1.); auto borderOpacity = _a_borderOpacity.value(_borderVisible ? 1. : 0.); if (_st.borderActive && (borderOpacity > 0.)) { - auto borderStart = snap(_borderAnimationStart, 0, width()); + auto borderStart = std::clamp(_borderAnimationStart, 0, width()); auto borderFrom = qRound(borderStart * (1. - borderShownDegree)); auto borderTo = borderStart + qRound((width() - borderStart) * borderShownDegree); if (borderTo > borderFrom) { diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 9d72215a5d..1755b6ed6a 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -810,10 +810,13 @@ void ScheduledWidget::showAtPosition(Data::MessagePosition position) { bool ScheduledWidget::showAtPositionNow(Data::MessagePosition position) { if (const auto scrollTop = _inner->scrollTopForPosition(position)) { const auto currentScrollTop = _scroll->scrollTop(); - const auto wanted = snap(*scrollTop, 0, _scroll->scrollTopMax()); + const auto wanted = std::clamp( + *scrollTop, + 0, + _scroll->scrollTopMax()); const auto fullDelta = (wanted - currentScrollTop); const auto limit = _scroll->height(); - const auto scrollDelta = snap(fullDelta, -limit, limit); + const auto scrollDelta = std::clamp(fullDelta, -limit, limit); _inner->scrollTo( wanted, position, diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index a28aabf316..4536e7f39f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -778,7 +778,11 @@ void Document::updatePressed(QPoint point) { const auto &st = thumbed ? st::msgFileThumbLayout : st::msgFileLayout; const auto nameleft = st.padding.left() + st.thumbSize + st.padding.right(); const auto nameright = st.padding.left(); - voice->setSeekingCurrent(snap((point.x() - nameleft) / float64(width() - nameleft - nameright), 0., 1.)); + voice->setSeekingCurrent(std::clamp( + (point.x() - nameleft) + / float64(width() - nameleft - nameright), + 0., + 1.)); history()->owner().requestViewRepaint(_parent); } } @@ -863,7 +867,12 @@ bool Document::updateStatusText() const { bool was = (voice->_playback != nullptr); voice->ensurePlayback(this); if (!was || state.position != voice->_playback->position) { - auto prg = state.length ? snap(float64(state.position) / state.length, 0., 1.) : 0.; + auto prg = state.length + ? std::clamp( + float64(state.position) / state.length, + 0., + 1.) + : 0.; if (voice->_playback->position < state.position) { voice->_playback->progress.start(prg); } else { diff --git a/Telegram/SourceFiles/info/info_layer_widget.cpp b/Telegram/SourceFiles/info/info_layer_widget.cpp index 0c4b307803..750e30856c 100644 --- a/Telegram/SourceFiles/info/info_layer_widget.cpp +++ b/Telegram/SourceFiles/info/info_layer_widget.cpp @@ -207,7 +207,7 @@ int LayerWidget::resizeGetHeight(int newWidth) { auto windowWidth = parentSize.width(); auto windowHeight = parentSize.height(); auto newLeft = (windowWidth - newWidth) / 2; - auto newTop = snap( + auto newTop = std::clamp( windowHeight / 24, st::infoLayerTopMinimal, st::infoLayerTopMaximal); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index a384d1f2ef..b599c3e7c4 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -87,7 +87,10 @@ void Widget::moveBottom(int bottom) { void Widget::updateContentHeight() { auto addedHeight = innerPadding().top() + innerPadding().bottom(); auto wantedContentHeight = qRound(st::emojiPanHeightRatio * _bottom) - addedHeight; - auto contentHeight = snap(wantedContentHeight, st::inlineResultsMinHeight, st::inlineResultsMaxHeight); + auto contentHeight = std::clamp( + wantedContentHeight, + st::inlineResultsMinHeight, + st::inlineResultsMaxHeight); accumulate_min(contentHeight, _bottom - addedHeight); accumulate_min(contentHeight, _contentMaxHeight); auto resultTop = _bottom - addedHeight - contentHeight; diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index 92a627d13f..ea4f05bd5e 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -411,7 +411,11 @@ int Step::contentTop() const { accumulate_max(result, st::introStepTopMin); if (_hasCover) { const auto currentHeightFull = result + st::introNextTop + st::introContentTopAdd; - auto added = 1. - snap(float64(currentHeightFull - st::windowMinHeight) / (st::introStepHeightFull - st::windowMinHeight), 0., 1.); + auto added = 1. - std::clamp( + float64(currentHeightFull - st::windowMinHeight) + / (st::introStepHeightFull - st::windowMinHeight), + 0., + 1.); result += qRound(added * st::introContentTopAdd); } return result; diff --git a/Telegram/SourceFiles/main/main_session_settings.cpp b/Telegram/SourceFiles/main/main_session_settings.cpp index f38f2e3e47..ba7e979198 100644 --- a/Telegram/SourceFiles/main/main_session_settings.cpp +++ b/Telegram/SourceFiles/main/main_session_settings.cpp @@ -189,7 +189,7 @@ void SessionSettings::addFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { qint32 value = 0; stream >> value; - appDialogsWidthRatio = snap(value / 1000000., 0., 1.); + appDialogsWidthRatio = std::clamp(value / 1000000., 0., 1.); stream >> value; appThirdColumnWidth = value; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 1949de3e33..e7c2585196 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2406,7 +2406,7 @@ void MainWidget::ensureThirdColumnResizeAreaCreated() { if (!Adaptive::ThreeColumn() || !_thirdSection) { return; } - Core::App().settings().setThirdColumnWidth(snap( + Core::App().settings().setThirdColumnWidth(std::clamp( Core::App().settings().thirdColumnWidth(), st::columnMinimalWidthThird, st::columnMaximalWidthThird)); diff --git a/Telegram/SourceFiles/media/player/media_player_float.cpp b/Telegram/SourceFiles/media/player/media_player_float.cpp index 637f3a70bd..bb76152055 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.cpp +++ b/Telegram/SourceFiles/media/player/media_player_float.cpp @@ -111,7 +111,7 @@ float64 Float::outRatio() const { if (y() + height() > parent.y() + parent.height()) { accumulate_min(min, 1. - (y() + height() - parent.y() - parent.height()) / float64(height())); } - return snap(min, 0., 1.); + return std::clamp(min, 0., 1.); } void Float::mouseReleaseEvent(QMouseEvent *e) { diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index c4f7319639..16c65351f2 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -250,7 +250,7 @@ Widget::~Widget() = default; void Widget::handleSeekProgress(float64 progress) { if (!_lastDurationMs) return; - const auto positionMs = snap( + const auto positionMs = std::clamp( static_cast(progress * _lastDurationMs), crl::time(0), _lastDurationMs); @@ -265,7 +265,7 @@ void Widget::handleSeekProgress(float64 progress) { void Widget::handleSeekFinished(float64 progress) { if (!_lastDurationMs) return; - const auto positionMs = snap( + const auto positionMs = std::clamp( static_cast(progress * _lastDurationMs), crl::time(0), _lastDurationMs); diff --git a/Telegram/SourceFiles/media/view/media_view_playback_controls.cpp b/Telegram/SourceFiles/media/view/media_view_playback_controls.cpp index 3b8bb05be4..5c6cd0994c 100644 --- a/Telegram/SourceFiles/media/view/media_view_playback_controls.cpp +++ b/Telegram/SourceFiles/media/view/media_view_playback_controls.cpp @@ -104,7 +104,7 @@ PlaybackControls::PlaybackControls( void PlaybackControls::handleSeekProgress(float64 progress) { if (!_lastDurationMs) return; - const auto positionMs = snap( + const auto positionMs = std::clamp( static_cast(progress * _lastDurationMs), crl::time(0), _lastDurationMs); @@ -120,7 +120,7 @@ void PlaybackControls::handleSeekProgress(float64 progress) { void PlaybackControls::handleSeekFinished(float64 progress) { if (!_lastDurationMs) return; - const auto positionMs = snap( + const auto positionMs = std::clamp( static_cast(progress * _lastDurationMs), crl::time(0), _lastDurationMs); diff --git a/Telegram/SourceFiles/media/view/media_view_playback_progress.cpp b/Telegram/SourceFiles/media/view/media_view_playback_progress.cpp index 9a8ecbc781..745c4374f9 100644 --- a/Telegram/SourceFiles/media/view/media_view_playback_progress.cpp +++ b/Telegram/SourceFiles/media/view/media_view_playback_progress.cpp @@ -58,10 +58,10 @@ void PlaybackProgress::updateState( const auto progress = (position > length) ? 1. : length - ? snap(float64(position) / length, 0., 1.) + ? std::clamp(float64(position) / length, 0., 1.) : 0.; const auto availableTillProgress = (availableTill > position) - ? snap(float64(availableTill) / length, 0., 1.) + ? std::clamp(float64(availableTill) / length, 0., 1.) : -1.; const auto animatedPosition = position + (state.frequency * kPlaybackAnimationDurationMs / 1000); const auto animatedProgress = length ? qMax(float64(animatedPosition) / length, 0.) : 0.; diff --git a/Telegram/SourceFiles/mtproto/session_private.cpp b/Telegram/SourceFiles/mtproto/session_private.cpp index 8bbcf7caa3..9ddab55b85 100644 --- a/Telegram/SourceFiles/mtproto/session_private.cpp +++ b/Telegram/SourceFiles/mtproto/session_private.cpp @@ -1073,7 +1073,10 @@ void SessionPrivate::onSentSome(uint64 size) { if (!_oldConnection) { // 8kb / sec, so 512 kb give 64 sec auto remainBySize = size * _waitForReceived / 8192; - remain = snap(remainBySize, remain, uint64(kMaxReceiveTimeout)); + remain = std::clamp( + remainBySize, + remain, + uint64(kMaxReceiveTimeout)); if (remain != _waitForReceived) { DEBUG_LOG(("Checking connect for request with size %1 bytes, delay will be %2").arg(size).arg(remain)); } diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp index 150baa35f7..20b7c9732a 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp @@ -680,7 +680,7 @@ void DateRow::paintEvent(QPaintEvent *e) { auto borderShownDegree = _a_borderShown.value(1.); auto borderOpacity = _a_borderOpacity.value(_borderVisible ? 1. : 0.); if (_st.borderActive && (borderOpacity > 0.)) { - auto borderStart = snap(_borderAnimationStart, 0, width); + auto borderStart = std::clamp(_borderAnimationStart, 0, width); auto borderFrom = qRound(borderStart * (1. - borderShownDegree)); auto borderTo = borderStart + qRound((width - borderStart) * borderShownDegree); if (borderTo > borderFrom) { diff --git a/Telegram/SourceFiles/settings/settings_intro.cpp b/Telegram/SourceFiles/settings/settings_intro.cpp index 9e2695bccd..44f0ef1472 100644 --- a/Telegram/SourceFiles/settings/settings_intro.cpp +++ b/Telegram/SourceFiles/settings/settings_intro.cpp @@ -473,7 +473,7 @@ int LayerWidget::resizeGetHeight(int newWidth) { _tillTop = _tillBottom = true; return windowHeight; } - auto newTop = snap( + auto newTop = std::clamp( windowHeight / 24, st::infoLayerTopMinimal, st::infoLayerTopMaximal); diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index 9c2981c1d0..f6ce983b0b 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -41,7 +41,7 @@ namespace { constexpr auto kMaxNotificationsCount = 5; [[nodiscard]] int CurrentCount() { - return snap( + return std::clamp( Core::App().settings().notificationsCount(), 1, kMaxNotificationsCount); diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index 535deee66a..4efc521cf5 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -1053,7 +1053,7 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - Core::App().settings().setSongVolume(snap(v / 1e6, 0., 1.)); + Core::App().settings().setSongVolume(std::clamp(v / 1e6, 0., 1.)); context.legacyRead = true; } break; @@ -1062,7 +1062,7 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - Core::App().settings().setVideoVolume(snap(v / 1e6, 0., 1.)); + Core::App().settings().setVideoVolume(std::clamp(v / 1e6, 0., 1.)); context.legacyRead = true; } break; diff --git a/Telegram/SourceFiles/storage/storage_cloud_blob.cpp b/Telegram/SourceFiles/storage/storage_cloud_blob.cpp index 6928dfebc1..c4c8f0578d 100644 --- a/Telegram/SourceFiles/storage/storage_cloud_blob.cpp +++ b/Telegram/SourceFiles/storage/storage_cloud_blob.cpp @@ -80,7 +80,7 @@ QString StateDescription(const BlobState &state, tr::phrase<> activeText) { return activeText(tr::now); }, [](const Loading &data) { const auto percent = (data.size > 0) - ? snap((data.already * 100) / float64(data.size), 0., 100.) + ? std::clamp((data.already * 100) / float64(data.size), 0., 100.) : 0.; return tr::lng_emoji_set_loading( tr::now, diff --git a/Telegram/SourceFiles/support/support_autocomplete.cpp b/Telegram/SourceFiles/support/support_autocomplete.cpp index e6b96c52ce..d7ceabdd96 100644 --- a/Telegram/SourceFiles/support/support_autocomplete.cpp +++ b/Telegram/SourceFiles/support/support_autocomplete.cpp @@ -528,7 +528,7 @@ void ConfirmContactBox::prepare() { _contact->initDimensions(); accumulate_max(maxWidth, _contact->maxWidth()); maxWidth += st::boxPadding.left() + st::boxPadding.right(); - const auto width = snap(maxWidth, st::boxWidth, st::boxWideWidth); + const auto width = std::clamp(maxWidth, st::boxWidth, st::boxWideWidth); const auto available = width - st::boxPadding.left() - st::boxPadding.right(); diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp index f018132b1f..881081b27d 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp @@ -423,7 +423,7 @@ void RoundImageCheckbox::paint(Painter &p, int x, int y, int outerWidth) { if (selectionLevel > 0) { PainterHighQualityEnabler hq(p); - p.setOpacity(snap(selectionLevel, 0., 1.)); + p.setOpacity(std::clamp(selectionLevel, 0., 1.)); p.setBrush(Qt::NoBrush); auto pen = _st.selectFg->p; pen.setWidth(_st.selectWidth); @@ -438,7 +438,7 @@ void RoundImageCheckbox::paint(Painter &p, int x, int y, int outerWidth) { } float64 RoundImageCheckbox::checkedAnimationRatio() const { - return snap(_selection.value(checked() ? 1. : 0.), 0., 1.); + return std::clamp(_selection.value(checked() ? 1. : 0.), 0., 1.); } void RoundImageCheckbox::setChecked(bool newChecked, anim::type animated) { diff --git a/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp b/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp index e6aa9cec5f..09f88c8908 100644 --- a/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp +++ b/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp @@ -78,7 +78,7 @@ float64 ContinuousSlider::computeValue(const QPoint &pos) const { const auto result = isHorizontal() ? (pos.x() - seekRect.x()) / float64(seekRect.width()) : (1. - (pos.y() - seekRect.y()) / float64(seekRect.height())); - const auto snapped = snap(result, 0., 1.); + const auto snapped = std::clamp(result, 0., 1.); return _adjustCallback ? _adjustCallback(snapped) : snapped; } @@ -120,7 +120,7 @@ void ContinuousSlider::wheelEvent(QWheelEvent *e) { deltaX *= -1; } auto delta = (qAbs(deltaX) > qAbs(deltaY)) ? deltaX : deltaY; - auto finalValue = snap(_value + delta * coef, 0., 1.); + auto finalValue = std::clamp(_value + delta * coef, 0., 1.); setValue(finalValue); if (_changeProgressCallback) { _changeProgressCallback(finalValue); diff --git a/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp b/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp index e4cb7cdb98..9de847c784 100644 --- a/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp +++ b/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp @@ -280,7 +280,11 @@ void SettingsSlider::paintEvent(QPaintEvent *e) { auto activeLeft = getCurrentActiveLeft(); enumerateSections([&](Section §ion) { - auto active = 1. - snap(qAbs(activeLeft - section.left) / float64(section.width), 0., 1.); + auto active = 1. + - std::clamp( + qAbs(activeLeft - section.left) / float64(section.width), + 0., + 1.); if (section.ripple) { auto color = anim::color(_st.rippleBg, _st.rippleBgActive, active); section.ripple->paint(p, section.left, 0, width(), &color);