mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Hide self in small stories userpics.
This commit is contained in:
parent
087c27c5e0
commit
c1be4d6451
3 changed files with 59 additions and 23 deletions
|
@ -148,6 +148,7 @@ Content State::next() {
|
||||||
.userpic = std::move(userpic),
|
.userpic = std::move(userpic),
|
||||||
.unread = info.unread,
|
.unread = info.unread,
|
||||||
.hidden = info.hidden,
|
.hidden = info.hidden,
|
||||||
|
.self = user->isSelf(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -39,6 +39,7 @@ struct List::Layout {
|
||||||
float64 photoLeft = 0.;
|
float64 photoLeft = 0.;
|
||||||
float64 left = 0.;
|
float64 left = 0.;
|
||||||
float64 single = 0.;
|
float64 single = 0.;
|
||||||
|
int smallSkip = 0;
|
||||||
int leftFull = 0;
|
int leftFull = 0;
|
||||||
int leftSmall = 0;
|
int leftSmall = 0;
|
||||||
int singleFull = 0;
|
int singleFull = 0;
|
||||||
|
@ -114,17 +115,18 @@ void List::showContent(Content &&content) {
|
||||||
|
|
||||||
List::Summaries List::ComposeSummaries(Data &data) {
|
List::Summaries List::ComposeSummaries(Data &data) {
|
||||||
const auto total = int(data.items.size());
|
const auto total = int(data.items.size());
|
||||||
|
const auto skip = (total > 1 && data.items[0].user.self) ? 1 : 0;
|
||||||
auto unreadInFirst = 0;
|
auto unreadInFirst = 0;
|
||||||
auto unreadTotal = 0;
|
auto unreadTotal = 0;
|
||||||
for (auto i = 0; i != total; ++i) {
|
for (auto i = skip; i != total; ++i) {
|
||||||
if (data.items[i].user.unread) {
|
if (data.items[i].user.unread) {
|
||||||
++unreadTotal;
|
++unreadTotal;
|
||||||
if (i < kSmallUserpicsShown) {
|
if (i < skip + kSmallUserpicsShown) {
|
||||||
++unreadInFirst;
|
++unreadInFirst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto result = Summaries();
|
auto result = Summaries{ .skipSelf = (skip > 0) };
|
||||||
result.total.string
|
result.total.string
|
||||||
= tr::lng_stories_row_count(tr::now, lt_count, total);
|
= tr::lng_stories_row_count(tr::now, lt_count, total);
|
||||||
const auto append = [&](QString &to, int index, bool last) {
|
const auto append = [&](QString &to, int index, bool last) {
|
||||||
|
@ -143,13 +145,13 @@ List::Summaries List::ComposeSummaries(Data &data) {
|
||||||
};
|
};
|
||||||
if (!total) {
|
if (!total) {
|
||||||
return result;
|
return result;
|
||||||
} else if (total <= kSmallUserpicsShown) {
|
} else if (total <= skip + kSmallUserpicsShown) {
|
||||||
for (auto i = 0; i != total; ++i) {
|
for (auto i = skip; i != total; ++i) {
|
||||||
append(result.allNames.string, i, i == total - 1);
|
append(result.allNames.string, i, i == total - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unreadInFirst > 0 && unreadInFirst == unreadTotal) {
|
if (unreadInFirst > 0 && unreadInFirst == unreadTotal) {
|
||||||
for (auto i = 0; i != total; ++i) {
|
for (auto i = skip; i != total; ++i) {
|
||||||
if (data.items[i].user.unread) {
|
if (data.items[i].user.unread) {
|
||||||
append(result.unreadNames.string, i, !--unreadTotal);
|
append(result.unreadNames.string, i, !--unreadTotal);
|
||||||
}
|
}
|
||||||
|
@ -265,11 +267,16 @@ List::Layout List::computeLayout() const {
|
||||||
+ st::defaultDialogRow.photoSize
|
+ st::defaultDialogRow.photoSize
|
||||||
+ st::defaultDialogRow.padding.left();
|
+ st::defaultDialogRow.padding.left();
|
||||||
const auto narrow = (width() <= narrowWidth);
|
const auto narrow = (width() <= narrowWidth);
|
||||||
const auto smallCount = std::min(kSmallUserpicsShown, itemsCount);
|
const auto smallSkip = (itemsCount > 1 && rendering.items[0].user.self)
|
||||||
|
? 1
|
||||||
|
: 0;
|
||||||
|
const auto smallCount = std::min(
|
||||||
|
kSmallUserpicsShown,
|
||||||
|
itemsCount - smallSkip);
|
||||||
const auto smallWidth = st.photo + (smallCount - 1) * st.shift;
|
const auto smallWidth = st.photo + (smallCount - 1) * st.shift;
|
||||||
const auto leftSmall = narrow
|
const auto leftSmall = (narrow
|
||||||
? ((narrowWidth - smallWidth) / 2 - st.photoLeft)
|
? ((narrowWidth - smallWidth) / 2 - st.photoLeft)
|
||||||
: st.left;
|
: st.left) - (smallSkip ? st.shift : 0);
|
||||||
const auto leftFull = (narrow
|
const auto leftFull = (narrow
|
||||||
? ((narrowWidth - full.photo) / 2 - full.photoLeft)
|
? ((narrowWidth - full.photo) / 2 - full.photoLeft)
|
||||||
: full.left) - _scrollLeft;
|
: full.left) - _scrollLeft;
|
||||||
|
@ -278,9 +285,9 @@ List::Layout List::computeLayout() const {
|
||||||
const auto endIndexFull = std::min(
|
const auto endIndexFull = std::min(
|
||||||
(width() - leftFull + singleFull - 1) / singleFull,
|
(width() - leftFull + singleFull - 1) / singleFull,
|
||||||
itemsCount);
|
itemsCount);
|
||||||
const auto startIndexSmall = 0;
|
const auto startIndexSmall = std::min(startIndexFull, smallSkip);
|
||||||
const auto endIndexSmall = smallCount;
|
const auto endIndexSmall = smallSkip + smallCount;
|
||||||
const auto cellLeftSmall = leftSmall;
|
const auto cellLeftSmall = leftSmall + (startIndexSmall * st.shift);
|
||||||
const auto userpicLeftFull = cellLeftFull + full.photoLeft;
|
const auto userpicLeftFull = cellLeftFull + full.photoLeft;
|
||||||
const auto userpicLeftSmall = cellLeftSmall + st.photoLeft;
|
const auto userpicLeftSmall = cellLeftSmall + st.photoLeft;
|
||||||
const auto userpicLeft = lerp(userpicLeftSmall, userpicLeftFull);
|
const auto userpicLeft = lerp(userpicLeftSmall, userpicLeftFull);
|
||||||
|
@ -293,6 +300,7 @@ List::Layout List::computeLayout() const {
|
||||||
.photoLeft = photoLeft,
|
.photoLeft = photoLeft,
|
||||||
.left = userpicLeft - photoLeft,
|
.left = userpicLeft - photoLeft,
|
||||||
.single = lerp(st.shift, singleFull),
|
.single = lerp(st.shift, singleFull),
|
||||||
|
.smallSkip = smallSkip,
|
||||||
.leftFull = leftFull,
|
.leftFull = leftFull,
|
||||||
.leftSmall = leftSmall,
|
.leftSmall = leftSmall,
|
||||||
.singleFull = singleFull,
|
.singleFull = singleFull,
|
||||||
|
@ -355,7 +363,9 @@ void List::paintEvent(QPaintEvent *e) {
|
||||||
const auto lookup = [&](int index) {
|
const auto lookup = [&](int index) {
|
||||||
const auto indexSmall = layout.startIndexSmall + index;
|
const auto indexSmall = layout.startIndexSmall + index;
|
||||||
const auto indexFull = layout.startIndexFull + index;
|
const auto indexFull = layout.startIndexFull + index;
|
||||||
const auto small = (drawSmall && indexSmall < layout.endIndexSmall)
|
const auto small = (drawSmall
|
||||||
|
&& indexSmall < layout.endIndexSmall
|
||||||
|
&& indexSmall >= layout.smallSkip)
|
||||||
? &rendering.items[indexSmall]
|
? &rendering.items[indexSmall]
|
||||||
: nullptr;
|
: nullptr;
|
||||||
const auto full = (drawFull && indexFull < layout.endIndexFull)
|
const auto full = (drawFull && indexFull < layout.endIndexFull)
|
||||||
|
@ -370,20 +380,33 @@ void List::paintEvent(QPaintEvent *e) {
|
||||||
};
|
};
|
||||||
const auto enumerate = [&](auto &&paintGradient, auto &&paintOther) {
|
const auto enumerate = [&](auto &&paintGradient, auto &&paintOther) {
|
||||||
auto nextGradientPainted = false;
|
auto nextGradientPainted = false;
|
||||||
for (auto i = count; i != 0;) {
|
auto skippedPainted = false;
|
||||||
|
const auto first = layout.smallSkip - layout.startIndexSmall;
|
||||||
|
for (auto i = count; i != first;) {
|
||||||
--i;
|
--i;
|
||||||
|
const auto next = (i > 0) ? lookup(i - 1) : Single();
|
||||||
const auto gradientPainted = nextGradientPainted;
|
const auto gradientPainted = nextGradientPainted;
|
||||||
nextGradientPainted = false;
|
nextGradientPainted = false;
|
||||||
if (const auto current = lookup(i)) {
|
if (const auto current = lookup(i)) {
|
||||||
|
if (i == first && next && !skippedPainted) {
|
||||||
|
skippedPainted = true;
|
||||||
|
paintGradient(next);
|
||||||
|
paintOther(next);
|
||||||
|
}
|
||||||
if (!gradientPainted) {
|
if (!gradientPainted) {
|
||||||
paintGradient(current);
|
paintGradient(current);
|
||||||
}
|
}
|
||||||
if (i > 0 && hasUnread(current)) {
|
if (i > first && hasUnread(current) && next) {
|
||||||
if (const auto next = lookup(i - 1)) {
|
if (current.itemSmall || !next.itemSmall) {
|
||||||
if (current.itemSmall || !next.itemSmall) {
|
if (i - 1 == first && first > 0 && !skippedPainted) {
|
||||||
nextGradientPainted = true;
|
if (const auto skipped = lookup(i - 2)) {
|
||||||
paintGradient(next);
|
skippedPainted = true;
|
||||||
|
paintGradient(skipped);
|
||||||
|
paintOther(skipped);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
nextGradientPainted = true;
|
||||||
|
paintGradient(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
paintOther(current);
|
paintOther(current);
|
||||||
|
@ -523,7 +546,9 @@ List::Summary &List::ChooseSummary(
|
||||||
int totalItems,
|
int totalItems,
|
||||||
int fullWidth) {
|
int fullWidth) {
|
||||||
const auto &st = st::dialogsStories;
|
const auto &st = st::dialogsStories;
|
||||||
const auto used = std::min(totalItems, kSmallUserpicsShown);
|
const auto used = std::min(
|
||||||
|
totalItems - (summaries.skipSelf ? 1 : 0),
|
||||||
|
kSmallUserpicsShown);
|
||||||
const auto taken = st.left
|
const auto taken = st.left
|
||||||
+ st.photoLeft
|
+ st.photoLeft
|
||||||
+ st.photo
|
+ st.photo
|
||||||
|
@ -579,7 +604,9 @@ void List::paintSummary(
|
||||||
};
|
};
|
||||||
const auto &st = st::dialogsStories;
|
const auto &st = st::dialogsStories;
|
||||||
const auto &full = st::dialogsStoriesFull;
|
const auto &full = st::dialogsStoriesFull;
|
||||||
const auto used = std::min(total, kSmallUserpicsShown);
|
const auto used = std::min(
|
||||||
|
total - (data.summaries.skipSelf ? 1 : 0),
|
||||||
|
kSmallUserpicsShown);
|
||||||
const auto fullLeft = st.left
|
const auto fullLeft = st.left
|
||||||
+ st.photoLeft
|
+ st.photoLeft
|
||||||
+ st.photo
|
+ st.photo
|
||||||
|
@ -760,15 +787,20 @@ void List::updateSelected() {
|
||||||
const auto layout = computeLayout();
|
const auto layout = computeLayout();
|
||||||
const auto firstRightFull = layout.leftFull
|
const auto firstRightFull = layout.leftFull
|
||||||
+ (layout.startIndexFull + 1) * layout.singleFull;
|
+ (layout.startIndexFull + 1) * layout.singleFull;
|
||||||
|
const auto secondLeftFull = firstRightFull;
|
||||||
const auto firstRightSmall = layout.leftSmall
|
const auto firstRightSmall = layout.leftSmall
|
||||||
+ st.photoLeft
|
+ st.photoLeft
|
||||||
+ st.photo;
|
+ st.photo;
|
||||||
|
const auto secondLeftSmall = layout.smallSkip
|
||||||
|
? (layout.leftSmall + st.photoLeft + st.shift)
|
||||||
|
: firstRightSmall;
|
||||||
const auto lastRightAddFull = 0;
|
const auto lastRightAddFull = 0;
|
||||||
const auto lastRightAddSmall = st.photoLeft;
|
const auto lastRightAddSmall = st.photoLeft;
|
||||||
const auto lerp = [&](float64 a, float64 b) {
|
const auto lerp = [&](float64 a, float64 b) {
|
||||||
return a + (b - a) * layout.ratio;
|
return a + (b - a) * layout.ratio;
|
||||||
};
|
};
|
||||||
const auto firstRight = lerp(firstRightSmall, firstRightFull);
|
const auto firstRight = lerp(firstRightSmall, firstRightFull);
|
||||||
|
const auto secondLeft = lerp(secondLeftSmall, secondLeftFull);
|
||||||
const auto lastRightAdd = lerp(lastRightAddSmall, lastRightAddFull);
|
const auto lastRightAdd = lerp(lastRightAddSmall, lastRightAddFull);
|
||||||
const auto activateFull = (layout.ratio >= 0.5);
|
const auto activateFull = (layout.ratio >= 0.5);
|
||||||
const auto startIndex = activateFull
|
const auto startIndex = activateFull
|
||||||
|
@ -778,9 +810,10 @@ void List::updateSelected() {
|
||||||
? layout.endIndexFull
|
? layout.endIndexFull
|
||||||
: layout.endIndexSmall;
|
: layout.endIndexSmall;
|
||||||
const auto x = p.x();
|
const auto x = p.x();
|
||||||
const auto infiniteIndex = (x < firstRight)
|
const auto infiniteIndex = (x < secondLeft)
|
||||||
? 0
|
? 0
|
||||||
: int(std::floor(((x - firstRight) / layout.single) + 1));
|
: int(
|
||||||
|
std::floor((std::max(x - firstRight, 0.)) / layout.single) + 1);
|
||||||
const auto index = (endIndex == startIndex)
|
const auto index = (endIndex == startIndex)
|
||||||
? -1
|
? -1
|
||||||
: (infiniteIndex == endIndex - startIndex
|
: (infiniteIndex == endIndex - startIndex
|
||||||
|
|
|
@ -31,6 +31,7 @@ struct User {
|
||||||
std::shared_ptr<Userpic> userpic;
|
std::shared_ptr<Userpic> userpic;
|
||||||
bool unread = false;
|
bool unread = false;
|
||||||
bool hidden = false;
|
bool hidden = false;
|
||||||
|
bool self = false;
|
||||||
|
|
||||||
friend inline bool operator==(const User &a, const User &b) = default;
|
friend inline bool operator==(const User &a, const User &b) = default;
|
||||||
};
|
};
|
||||||
|
@ -87,6 +88,7 @@ private:
|
||||||
Summary total;
|
Summary total;
|
||||||
Summary allNames;
|
Summary allNames;
|
||||||
Summary unreadNames;
|
Summary unreadNames;
|
||||||
|
bool skipSelf = false;
|
||||||
};
|
};
|
||||||
struct Data {
|
struct Data {
|
||||||
std::vector<Item> items;
|
std::vector<Item> items;
|
||||||
|
|
Loading…
Add table
Reference in a new issue