From 2407ac50bc5485807e2b82bb2c9631633bfdb40e Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 5 Dec 2022 10:07:54 +0400 Subject: [PATCH] Improve shading of collapsed chats list. --- .../dialogs/dialogs_inner_widget.cpp | 46 ++++++++++--------- .../SourceFiles/dialogs/dialogs_widget.cpp | 27 ++++++----- .../SourceFiles/dialogs/ui/dialogs_layout.cpp | 5 +- .../SourceFiles/dialogs/ui/dialogs_layout.h | 1 + 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 6303c1e9a4..51b77d4691 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -565,6 +565,18 @@ void InnerWidget::paintEvent(QPaintEvent *e) { auto dialogsClip = r; const auto ms = crl::now(); const auto childListShown = _childListShown.current(); + auto context = Ui::PaintContext{ + .st = _st, + .topicJumpCache = _topicJumpCache.get(), + .folder = _openedFolder, + .forum = _openedForum, + .filter = _filterId, + .childListShown = childListShown.shown, + .now = ms, + .width = fullWidth, + .paused = videoPaused, + .narrow = (fullWidth < st::columnMinimalWidthLeft / 2), + }; const auto paintRow = [&]( not_null row, bool selected, @@ -575,31 +587,21 @@ void InnerWidget::paintEvent(QPaintEvent *e) { if (forum && !_topicJumpCache) { _topicJumpCache = std::make_unique(); } + const auto expanding = forum + && (key.history()->peer->id == childListShown.peerId); - const auto expanded = (!active - && forum - && (key.history()->peer->id == childListShown.peerId)) + context.st = (forum ? &st::forumDialogRow : _st.get()); + context.topicsExpanded = (expanding && !active) ? childListShown.shown : 0.; - Ui::RowPainter::Paint(p, row, validateVideoUserpic(row), { - .st = (forum ? &st::forumDialogRow : _st.get()), - .topicJumpCache = _topicJumpCache.get(), - .folder = _openedFolder, - .forum = _openedForum, - .filter = _filterId, - .topicsExpanded = expanded, - .now = ms, - .width = fullWidth, - .active = active, - .selected = (_menuRow.key - ? (row->key() == _menuRow.key) - : selected), - .topicJumpSelected = (selected - && _selectedTopicJump - && (!_pressed || _pressedTopicJump)), - .paused = videoPaused, - .narrow = (fullWidth < st::columnMinimalWidthLeft / 2), - }); + context.active = active; + context.selected = _menuRow.key + ? (row->key() == _menuRow.key) + : selected; + context.topicJumpSelected = selected + && _selectedTopicJump + && (!_pressed || _pressedTopicJump); + Ui::RowPainter::Paint(p, row, validateVideoUserpic(row), context); }; if (_state == WidgetState::Default) { paintCollapsedRows(p, r); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index fd278ff770..ae782a3844 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -2013,21 +2013,17 @@ void Widget::openChildList( const auto opacity = shadow->lifetime().make_state(0.); shadow->setAttribute(Qt::WA_TransparentForMouseEvents); shadow->paintRequest( - ) | rpl::start_with_next([=] { + ) | rpl::start_with_next([=](QRect clip) { auto p = QPainter(shadow); p.setOpacity(*opacity); - st::slideShadow.fill(p, QRect( - shadow->width() - st::slideShadow.width(), - 0, - st::slideShadow.width(), - shadow->height())); + p.fillRect(clip, st::shadowFg); }, shadow->lifetime()); _childListShown.value() | rpl::start_with_next([=](float64 value) { *opacity = value; + update(); + _inner->update(); if (!value && _childListShadow.get() != shadow) { delete shadow; - } else { - shadow->update(); } }, shadow->lifetime()); @@ -2056,6 +2052,7 @@ void Widget::closeChildList(anim::type animated) { if (animated == anim::type::normal) { oldContentCache = Ui::GrabWidget(_childList.get()); _hideChildListCanvas = std::make_unique(this); + _hideChildListCanvas->setAttribute(Qt::WA_TransparentForMouseEvents); _hideChildListCanvas->setGeometry(geometry); animation = _hideChildListCanvas->lifetime().make_state< Window::SlideAnimation @@ -2457,10 +2454,12 @@ void Widget::updateControlsGeometry() { if (_childList) { const auto childw = std::max(_narrowWidth, width() - scrollw); const auto childh = scrollTop + scrollHeight; + const auto childx = width() - childw; _childList->setGeometryWithTopMoved( - { width() - childw, 0, childw, childh }, + { childx, 0, childw, childh }, _topDelta); - _childListShadow->setGeometry(0, 0, (width() - childw), childh); + const auto line = st::lineWidth; + _childListShadow->setGeometry(childx - line, 0, line, childh); } } @@ -2511,9 +2510,13 @@ void Widget::paintEvent(QPaintEvent *e) { _showAnimation->paintContents(p); return; } + const auto bg = anim::brush( + st::dialogsBg, + st::dialogsBgOver, + _childListShown.current()); auto above = QRect(0, 0, width(), _scroll->y()); if (above.intersects(r)) { - p.fillRect(above.intersected(r), st::dialogsBg); + p.fillRect(above.intersected(r), bg); } auto belowTop = _scroll->y() + qMin(_scroll->height(), _inner->height()); @@ -2524,7 +2527,7 @@ void Widget::paintEvent(QPaintEvent *e) { auto below = QRect(0, belowTop, width(), height() - belowTop); if (below.intersects(r)) { - p.fillRect(below.intersected(r), st::dialogsBg); + p.fillRect(below.intersected(r), bg); } } diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp index 2e601b997d..02a0228239 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp @@ -305,7 +305,10 @@ void PaintRow( ? st::dialogsBgActive : context.selected ? st::dialogsBgOver - : st::dialogsBg; + : anim::brush( + st::dialogsBg, + st::dialogsBgOver, + context.childListShown); p.fillRect(geometry, bg); if (!(flags & Flag::TopicJumpRipple)) { auto ripple = context.active diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.h b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.h index cd5627773b..29ebc80c03 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.h +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.h @@ -59,6 +59,7 @@ struct PaintContext { Data::Forum *forum = nullptr; FilterId filter = 0; float64 topicsExpanded = 0.; + float64 childListShown = 0.; crl::time now = 0; int width = 0; bool active = false;