Added ability to set pinned intervals to sub tabs for gifts collection.

This commit is contained in:
23rd
2025-09-28 09:28:37 +03:00
committed by John Preston
parent aad1ff95be
commit 7d538ea080
3 changed files with 31 additions and 2 deletions
@@ -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<Ui::SubTabs>(
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(
+19 -2
View File
@@ -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();
}
}
@@ -51,6 +51,9 @@ public:
void setReorderEnabled(bool enabled);
[[nodiscard]] bool reorderEnabled() const;
void setPinnedInterval(int from, int to);
void clearPinnedIntervals();
[[nodiscard]] rpl::producer<QString> activated() const;
[[nodiscard]] rpl::producer<QString> 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<Button> _buttons;
@@ -96,6 +100,11 @@ private:
bool _centered = false;
bool _reorderEnable = false;
Ui::Animations::Basic _shakeAnimation;
struct PinnedInterval {
int from;
int to;
};
std::vector<PinnedInterval> _pinnedIntervals;
};