From 7d538ea08062356434f844911cd0e850fa79855d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 28 Sep 2025 09:28:37 +0300 Subject: [PATCH] Added ability to set pinned intervals to sub tabs for gifts collection. --- .../peer_gifts/info_peer_gifts_widget.cpp | 3 +++ Telegram/SourceFiles/ui/controls/sub_tabs.cpp | 21 +++++++++++++++++-- Telegram/SourceFiles/ui/controls/sub_tabs.h | 9 ++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp index 692873152a..8d60928300 100644 --- a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp +++ b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp @@ -1226,12 +1226,15 @@ void InnerWidget::refreshCollectionsTabs() { &Data::GiftCollection::id)) ? QString::number(selectedId) : u"all"_q; + const auto tabsCount = tabs.size(); _collectionsTabs = std::make_unique( this, st::collectionSubTabs, Ui::SubTabs::Options{ .selected = selected, .centered = true }, std::move(tabs), context); + _collectionsTabs->setPinnedInterval(0, 1); + _collectionsTabs->setPinnedInterval(tabsCount - 1, tabsCount); _collectionsTabs->show(); _collectionsTabs->activated( diff --git a/Telegram/SourceFiles/ui/controls/sub_tabs.cpp b/Telegram/SourceFiles/ui/controls/sub_tabs.cpp index 6ccfb12c8a..80bfa0278e 100644 --- a/Telegram/SourceFiles/ui/controls/sub_tabs.cpp +++ b/Telegram/SourceFiles/ui/controls/sub_tabs.cpp @@ -118,6 +118,23 @@ bool SubTabs::reorderEnabled() const { return _reorderEnable; } +void SubTabs::setPinnedInterval(int from, int to) { + _pinnedIntervals.push_back({ from, to }); +} + +void SubTabs::clearPinnedIntervals() { + _pinnedIntervals.clear(); +} + +bool SubTabs::isIndexPinned(int index) const { + for (const auto &interval : _pinnedIntervals) { + if (index >= interval.from && index < interval.to) { + return true; + } + } + return false; +} + void SubTabs::setSelected(int index) { const auto was = (_selected >= 0); const auto now = (index >= 0); @@ -285,7 +302,7 @@ void SubTabs::paintEvent(QPaintEvent *e) { const auto &button = _buttons[i]; const auto geometry = button.geometry.translated(shift); - if (hasShake && _reorderEnable) { + if (hasShake && _reorderEnable && !isIndexPinned(i)) { shakeTransform(p, i, geometry.topLeft(), now); } @@ -303,7 +320,7 @@ void SubTabs::paintEvent(QPaintEvent *e) { .availableWidth = button.text.maxWidth(), }); - if (hasShake && _reorderEnable) { + if (hasShake && _reorderEnable && !isIndexPinned(i)) { p.resetTransform(); } } diff --git a/Telegram/SourceFiles/ui/controls/sub_tabs.h b/Telegram/SourceFiles/ui/controls/sub_tabs.h index 79b8431e8a..11a3a35ee9 100644 --- a/Telegram/SourceFiles/ui/controls/sub_tabs.h +++ b/Telegram/SourceFiles/ui/controls/sub_tabs.h @@ -51,6 +51,9 @@ public: void setReorderEnabled(bool enabled); [[nodiscard]] bool reorderEnabled() const; + void setPinnedInterval(int from, int to); + void clearPinnedIntervals(); + [[nodiscard]] rpl::producer activated() const; [[nodiscard]] rpl::producer contextMenuRequests() const; @@ -75,6 +78,7 @@ private: void setActive(int index); [[nodiscard]] QPoint scroll() const; void shakeTransform(QPainter &p, int index, QPoint position, crl::time now) const; + [[nodiscard]] bool isIndexPinned(int index) const; const style::SubTabs &_st; std::vector