Collapse forum row height in narrow layout.

This commit is contained in:
John Preston 2022-12-01 21:36:26 +04:00
parent c200263f2e
commit f0b8ccbd71
12 changed files with 92 additions and 43 deletions

View file

@ -380,13 +380,6 @@ void Entry::updateChatListEntryPostponed() {
} }
void Entry::updateChatListEntryHeight() { void Entry::updateChatListEntryHeight() {
auto &filters = _owner->chatsFilters();
for (auto &[filterId, rows] : _chatListLinks) {
const auto list = filterId
? filters.chatsList(filterId)
: _owner->chatsList(folder());
list->updateEntryHeight(rows);
}
session().changes().entryUpdated(this, Data::EntryUpdate::Flag::Height); session().changes().entryUpdated(this, Data::EntryUpdate::Flag::Height);
} }

View file

@ -61,13 +61,12 @@ void IndexedList::adjustByDate(const RowsByLetter &links) {
} }
} }
void IndexedList::updateHeight(const RowsByLetter &links) { bool IndexedList::updateHeights(float64 narrowRatio) {
_list.updateHeight(links.main); return _list.updateHeights(narrowRatio);
for (const auto &[ch, row] : links.letters) { }
if (auto it = _index.find(ch); it != _index.cend()) {
it->second.updateHeight(row); bool IndexedList::updateHeight(Key key, float64 narrowRatio) {
} return _list.updateHeight(key, narrowRatio);
}
} }
void IndexedList::moveToTop(Key key) { void IndexedList::moveToTop(Key key) {

View file

@ -22,7 +22,8 @@ public:
Row *addByName(Key key); Row *addByName(Key key);
void adjustByDate(const RowsByLetter &links); void adjustByDate(const RowsByLetter &links);
void moveToTop(Key key); void moveToTop(Key key);
void updateHeight(const RowsByLetter &links); bool updateHeight(Key key, float64 narrowRatio);
bool updateHeights(float64 narrowRatio);
// row must belong to this indexed list all(). // row must belong to this indexed list all().
void movePinned(Row *row, int deltaSign); void movePinned(Row *row, int deltaSign);

View file

@ -294,8 +294,9 @@ InnerWidget::InnerWidget(
) | rpl::start_with_next([=](const Data::EntryUpdate &update) { ) | rpl::start_with_next([=](const Data::EntryUpdate &update) {
const auto entry = update.entry; const auto entry = update.entry;
if (update.flags & Data::EntryUpdate::Flag::Height) { if (update.flags & Data::EntryUpdate::Flag::Height) {
updateFilteredEntryHeight(entry); if (updateEntryHeight(entry)) {
refresh(); refresh();
}
return; return;
} }
const auto repaintId = (_state == WidgetState::Default) const auto repaintId = (_state == WidgetState::Default)
@ -331,7 +332,10 @@ InnerWidget::InnerWidget(
setupShortcuts(); setupShortcuts();
} }
void InnerWidget::updateFilteredEntryHeight(not_null<Entry*> entry) { bool InnerWidget::updateEntryHeight(not_null<Entry*> entry) {
if (!_geometryInited) {
return false;
}
auto changing = false; auto changing = false;
auto top = 0; auto top = 0;
for (auto &result : _filterResults) { for (auto &result : _filterResults) {
@ -339,7 +343,7 @@ void InnerWidget::updateFilteredEntryHeight(not_null<Entry*> entry) {
result.top = top; result.top = top;
} }
if (result.row->key().entry() == entry) { if (result.row->key().entry() == entry) {
result.row->recountHeight(); result.row->recountHeight(_narrowRatio);
changing = true; changing = true;
top = result.top; top = result.top;
} }
@ -347,6 +351,18 @@ void InnerWidget::updateFilteredEntryHeight(not_null<Entry*> entry) {
top += result.row->height(); top += result.row->height();
} }
} }
return _shownList->updateHeight(entry, _narrowRatio) || changing;
}
void InnerWidget::setNarrowRatio(float64 narrowRatio) {
if (_geometryInited && _narrowRatio == narrowRatio) {
return;
}
_geometryInited = true;
_narrowRatio = narrowRatio;
if (_shownList->updateHeights(_narrowRatio) || !height()) {
refresh();
}
} }
Main::Session &InnerWidget::session() const { Main::Session &InnerWidget::session() const {
@ -2070,11 +2086,14 @@ void InnerWidget::updateSelectedRow(Key key) {
} }
void InnerWidget::refreshShownList() { void InnerWidget::refreshShownList() {
_shownList = _openedForum const auto list = _openedForum
? _openedForum->topicsList()->indexed() ? _openedForum->topicsList()->indexed()
: _filterId : _filterId
? session().data().chatsFilters().chatsList(_filterId)->indexed() ? session().data().chatsFilters().chatsList(_filterId)->indexed()
: session().data().chatsList(_openedFolder)->indexed(); : session().data().chatsList(_openedFolder)->indexed();
if (_shownList != list) {
_shownList = list;
}
} }
void InnerWidget::leaveEventHook(QEvent *e) { void InnerWidget::leaveEventHook(QEvent *e) {
@ -2240,6 +2259,7 @@ void InnerWidget::applyFilterUpdate(QString newFilter, bool force) {
end(results)); end(results));
for (const auto e = end(_filterResults); i != e; ++i) { for (const auto e = end(_filterResults); i != e; ++i) {
i->top = top; i->top = top;
i->row->recountHeight(_narrowRatio);
top += i->row->height(); top += i->row->height();
} }
}; };
@ -2672,7 +2692,9 @@ void InnerWidget::editOpenedFilter() {
} }
void InnerWidget::refresh(bool toTop) { void InnerWidget::refresh(bool toTop) {
if (needCollapsedRowsRefresh()) { if (!_geometryInited) {
return;
} else if (needCollapsedRowsRefresh()) {
return refreshWithCollapsedRows(toTop); return refreshWithCollapsedRows(toTop);
} }
refreshEmptyLabel(); refreshEmptyLabel();

View file

@ -112,6 +112,7 @@ public:
void selectSkipPage(int32 pixels, int32 direction); void selectSkipPage(int32 pixels, int32 direction);
void dragLeft(); void dragLeft();
void setNarrowRatio(float64 narrowRatio);
void clearFilter(); void clearFilter();
void refresh(bool toTop = false); void refresh(bool toTop = false);
@ -235,7 +236,7 @@ private:
void repaintDialogRow(FilterId filterId, not_null<Row*> row); void repaintDialogRow(FilterId filterId, not_null<Row*> row);
void repaintDialogRow(RowDescriptor row); void repaintDialogRow(RowDescriptor row);
void refreshDialogRow(RowDescriptor row); void refreshDialogRow(RowDescriptor row);
void updateFilteredEntryHeight(not_null<Entry*> entry); bool updateEntryHeight(not_null<Entry*> entry);
void clearMouseSelection(bool clearSelection = false); void clearMouseSelection(bool clearSelection = false);
void mousePressReleased( void mousePressReleased(
@ -496,6 +497,8 @@ private:
rpl::event_stream<> _refreshHashtagsRequests; rpl::event_stream<> _refreshHashtagsRequests;
rpl::variable<ChildListShown> _childListShown; rpl::variable<ChildListShown> _childListShown;
float64 _narrowRatio = 0.;
bool _geometryInited = false;
base::unique_qptr<Ui::PopupMenu> _menu; base::unique_qptr<Ui::PopupMenu> _menu;

View file

@ -33,6 +33,7 @@ not_null<Row*> List::addToEnd(Key key) {
key, key,
std::make_unique<Row>(key, _rows.size(), height()) std::make_unique<Row>(key, _rows.size(), height())
).first->second.get(); ).first->second.get();
result->recountHeight(_narrowRatio);
_rows.emplace_back(result); _rows.emplace_back(result);
if (_sortMode == SortMode::Date) { if (_sortMode == SortMode::Date) {
adjustByDate(result); adjustByDate(result);
@ -103,15 +104,36 @@ void List::adjustByDate(not_null<Row*> row) {
} }
} }
void List::updateHeight(not_null<Row*> row) { bool List::updateHeight(Key key, float64 narrowRatio) {
row->recountHeight(); const auto i = _rowByKey.find(key);
if (i == _rowByKey.cend()) {
return false;
}
const auto row = i->second.get();
const auto index = row->index(); const auto index = row->index();
auto top = row->top(); auto top = row->top();
const auto was = row->height();
row->recountHeight(narrowRatio);
if (row->height() == was) {
return false;
}
for (auto i = _rows.begin() + index, e = _rows.end(); i != e; ++i) { for (auto i = _rows.begin() + index, e = _rows.end(); i != e; ++i) {
(*i)->_top = top; (*i)->_top = top;
top += (*i)->height(); top += (*i)->height();
} }
return true;
}
bool List::updateHeights(float64 narrowRatio) {
_narrowRatio = narrowRatio;
auto was = height();
auto top = 0;
for (const auto &row : _rows) {
row->_top = top;
row->recountHeight(narrowRatio);
top += row->height();
}
return (height() != was);
} }
bool List::moveToTop(Key key) { bool List::moveToTop(Key key) {

View file

@ -48,7 +48,8 @@ public:
not_null<Row*> addByName(Key key); not_null<Row*> addByName(Key key);
bool moveToTop(Key key); bool moveToTop(Key key);
void adjustByDate(not_null<Row*> row); void adjustByDate(not_null<Row*> row);
void updateHeight(not_null<Row*> row); bool updateHeight(Key key, float64 narrowRatio);
bool updateHeights(float64 narrowRatio);
bool remove(Key key, Row *replacedBy = nullptr); bool remove(Key key, Row *replacedBy = nullptr);
using const_iterator = std::vector<not_null<Row*>>::const_iterator; using const_iterator = std::vector<not_null<Row*>>::const_iterator;
@ -76,6 +77,7 @@ private:
SortMode _sortMode = SortMode(); SortMode _sortMode = SortMode();
FilterId _filterId = 0; FilterId _filterId = 0;
float64 _narrowRatio = 0.;
std::vector<not_null<Row*>> _rows; std::vector<not_null<Row*>> _rows;
std::map<Key, std::unique_ptr<Row>> _rowByKey; std::map<Key, std::unique_ptr<Row>> _rowByKey;

View file

@ -107,10 +107,6 @@ void MainList::removeEntry(Key key) {
recomputeFullListSize(); recomputeFullListSize();
} }
void MainList::updateEntryHeight(const RowsByLetter &links) {
_all.updateHeight(links);
}
void MainList::recomputeFullListSize() { void MainList::recomputeFullListSize() {
_fullListSize = std::max(_all.size(), loaded() ? 0 : _cloudListSize); _fullListSize = std::max(_all.size(), loaded() ? 0 : _cloudListSize);
} }

View file

@ -35,7 +35,6 @@ public:
RowsByLetter addEntry(Key key); RowsByLetter addEntry(Key key);
void removeEntry(Key key); void removeEntry(Key key);
void updateEntryHeight(const RowsByLetter &links);
void unreadStateChanged( void unreadStateChanged(
const UnreadState &wasState, const UnreadState &wasState,

View file

@ -101,13 +101,15 @@ Row::Row(Key key, int index, int top) : _id(key), _top(top), _index(index) {
if (const auto history = key.history()) { if (const auto history = key.history()) {
updateCornerBadgeShown(history->peer); updateCornerBadgeShown(history->peer);
} }
recountHeight();
} }
void Row::recountHeight() { void Row::recountHeight(float64 narrowRatio) {
if (const auto history = _id.history()) { if (const auto history = _id.history()) {
_height = history->peer->isForum() _height = history->peer->isForum()
? st::forumDialogRow.height ? anim::interpolate(
st::forumDialogRow.height,
st::defaultDialogRow.height,
narrowRatio)
: st::defaultDialogRow.height; : st::defaultDialogRow.height;
} else if (_id.folder()) { } else if (_id.folder()) {
_height = st::defaultDialogRow.height; _height = st::defaultDialogRow.height;

View file

@ -89,9 +89,11 @@ public:
return _top; return _top;
} }
[[nodiscard]] int height() const { [[nodiscard]] int height() const {
Expects(_height != 0);
return _height; return _height;
} }
void recountHeight(); void recountHeight(float64 narrowRatio);
void updateCornerBadgeShown( void updateCornerBadgeShown(
not_null<PeerData*> peer, not_null<PeerData*> peer,

View file

@ -436,15 +436,19 @@ void Widget::chosenRow(const ChosenRow &row) {
? history->peer->forumTopicFor(row.message.fullId.msg) ? history->peer->forumTopicFor(row.message.fullId.msg)
: nullptr; : nullptr;
if (topicJump) { if (topicJump) {
if (!controller()->adaptive().isOneColumn()) { if (controller()->shownForum().current() == topicJump->forum()) {
controller()->showForum( controller()->closeForum();
topicJump->forum(), } else {
Window::SectionShow().withChildColumn()); if (!controller()->adaptive().isOneColumn()) {
controller()->showForum(
topicJump->forum(),
Window::SectionShow().withChildColumn());
}
controller()->showThread(
topicJump,
ShowAtUnreadMsgId,
Window::SectionShow::Way::ClearStack);
} }
controller()->showThread(
topicJump,
ShowAtUnreadMsgId,
Window::SectionShow::Way::ClearStack);
return; return;
} else if (const auto topic = row.key.topic()) { } else if (const auto topic = row.key.topic()) {
controller()->showThread( controller()->showThread(
@ -2334,6 +2338,9 @@ void Widget::updateSearchFromVisibility(bool fast) {
} }
void Widget::updateControlsGeometry() { void Widget::updateControlsGeometry() {
if (width() < _narrowWidth) {
return;
}
auto filterAreaTop = 0; auto filterAreaTop = 0;
const auto ratiow = anim::interpolate( const auto ratiow = anim::interpolate(
@ -2434,6 +2441,7 @@ void Widget::updateControlsGeometry() {
const auto wasScrollHeight = _scroll->height(); const auto wasScrollHeight = _scroll->height();
_scroll->setGeometry(0, scrollTop, scrollw, scrollHeight); _scroll->setGeometry(0, scrollTop, scrollw, scrollHeight);
_inner->resize(scrollw, _inner->height()); _inner->resize(scrollw, _inner->height());
_inner->setNarrowRatio(narrowRatio);
if (scrollHeight != wasScrollHeight) { if (scrollHeight != wasScrollHeight) {
controller()->floatPlayerAreaUpdated(); controller()->floatPlayerAreaUpdated();
} }