Improve shading of collapsed chats list.

This commit is contained in:
John Preston 2022-12-05 10:07:54 +04:00
parent fbf3168317
commit 2407ac50bc
4 changed files with 44 additions and 35 deletions

View file

@ -565,6 +565,18 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
auto dialogsClip = r; auto dialogsClip = r;
const auto ms = crl::now(); const auto ms = crl::now();
const auto childListShown = _childListShown.current(); 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 = [&]( const auto paintRow = [&](
not_null<Row*> row, not_null<Row*> row,
bool selected, bool selected,
@ -575,31 +587,21 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
if (forum && !_topicJumpCache) { if (forum && !_topicJumpCache) {
_topicJumpCache = std::make_unique<Ui::TopicJumpCache>(); _topicJumpCache = std::make_unique<Ui::TopicJumpCache>();
} }
const auto expanding = forum
&& (key.history()->peer->id == childListShown.peerId);
const auto expanded = (!active context.st = (forum ? &st::forumDialogRow : _st.get());
&& forum context.topicsExpanded = (expanding && !active)
&& (key.history()->peer->id == childListShown.peerId))
? childListShown.shown ? childListShown.shown
: 0.; : 0.;
Ui::RowPainter::Paint(p, row, validateVideoUserpic(row), { context.active = active;
.st = (forum ? &st::forumDialogRow : _st.get()), context.selected = _menuRow.key
.topicJumpCache = _topicJumpCache.get(), ? (row->key() == _menuRow.key)
.folder = _openedFolder, : selected;
.forum = _openedForum, context.topicJumpSelected = selected
.filter = _filterId, && _selectedTopicJump
.topicsExpanded = expanded, && (!_pressed || _pressedTopicJump);
.now = ms, Ui::RowPainter::Paint(p, row, validateVideoUserpic(row), context);
.width = fullWidth,
.active = active,
.selected = (_menuRow.key
? (row->key() == _menuRow.key)
: selected),
.topicJumpSelected = (selected
&& _selectedTopicJump
&& (!_pressed || _pressedTopicJump)),
.paused = videoPaused,
.narrow = (fullWidth < st::columnMinimalWidthLeft / 2),
});
}; };
if (_state == WidgetState::Default) { if (_state == WidgetState::Default) {
paintCollapsedRows(p, r); paintCollapsedRows(p, r);

View file

@ -2013,21 +2013,17 @@ void Widget::openChildList(
const auto opacity = shadow->lifetime().make_state<float64>(0.); const auto opacity = shadow->lifetime().make_state<float64>(0.);
shadow->setAttribute(Qt::WA_TransparentForMouseEvents); shadow->setAttribute(Qt::WA_TransparentForMouseEvents);
shadow->paintRequest( shadow->paintRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=](QRect clip) {
auto p = QPainter(shadow); auto p = QPainter(shadow);
p.setOpacity(*opacity); p.setOpacity(*opacity);
st::slideShadow.fill(p, QRect( p.fillRect(clip, st::shadowFg);
shadow->width() - st::slideShadow.width(),
0,
st::slideShadow.width(),
shadow->height()));
}, shadow->lifetime()); }, shadow->lifetime());
_childListShown.value() | rpl::start_with_next([=](float64 value) { _childListShown.value() | rpl::start_with_next([=](float64 value) {
*opacity = value; *opacity = value;
update();
_inner->update();
if (!value && _childListShadow.get() != shadow) { if (!value && _childListShadow.get() != shadow) {
delete shadow; delete shadow;
} else {
shadow->update();
} }
}, shadow->lifetime()); }, shadow->lifetime());
@ -2056,6 +2052,7 @@ void Widget::closeChildList(anim::type animated) {
if (animated == anim::type::normal) { if (animated == anim::type::normal) {
oldContentCache = Ui::GrabWidget(_childList.get()); oldContentCache = Ui::GrabWidget(_childList.get());
_hideChildListCanvas = std::make_unique<Ui::RpWidget>(this); _hideChildListCanvas = std::make_unique<Ui::RpWidget>(this);
_hideChildListCanvas->setAttribute(Qt::WA_TransparentForMouseEvents);
_hideChildListCanvas->setGeometry(geometry); _hideChildListCanvas->setGeometry(geometry);
animation = _hideChildListCanvas->lifetime().make_state< animation = _hideChildListCanvas->lifetime().make_state<
Window::SlideAnimation Window::SlideAnimation
@ -2457,10 +2454,12 @@ void Widget::updateControlsGeometry() {
if (_childList) { if (_childList) {
const auto childw = std::max(_narrowWidth, width() - scrollw); const auto childw = std::max(_narrowWidth, width() - scrollw);
const auto childh = scrollTop + scrollHeight; const auto childh = scrollTop + scrollHeight;
const auto childx = width() - childw;
_childList->setGeometryWithTopMoved( _childList->setGeometryWithTopMoved(
{ width() - childw, 0, childw, childh }, { childx, 0, childw, childh },
_topDelta); _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); _showAnimation->paintContents(p);
return; return;
} }
const auto bg = anim::brush(
st::dialogsBg,
st::dialogsBgOver,
_childListShown.current());
auto above = QRect(0, 0, width(), _scroll->y()); auto above = QRect(0, 0, width(), _scroll->y());
if (above.intersects(r)) { 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()); 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); auto below = QRect(0, belowTop, width(), height() - belowTop);
if (below.intersects(r)) { if (below.intersects(r)) {
p.fillRect(below.intersected(r), st::dialogsBg); p.fillRect(below.intersected(r), bg);
} }
} }

View file

@ -305,7 +305,10 @@ void PaintRow(
? st::dialogsBgActive ? st::dialogsBgActive
: context.selected : context.selected
? st::dialogsBgOver ? st::dialogsBgOver
: st::dialogsBg; : anim::brush(
st::dialogsBg,
st::dialogsBgOver,
context.childListShown);
p.fillRect(geometry, bg); p.fillRect(geometry, bg);
if (!(flags & Flag::TopicJumpRipple)) { if (!(flags & Flag::TopicJumpRipple)) {
auto ripple = context.active auto ripple = context.active

View file

@ -59,6 +59,7 @@ struct PaintContext {
Data::Forum *forum = nullptr; Data::Forum *forum = nullptr;
FilterId filter = 0; FilterId filter = 0;
float64 topicsExpanded = 0.; float64 topicsExpanded = 0.;
float64 childListShown = 0.;
crl::time now = 0; crl::time now = 0;
int width = 0; int width = 0;
bool active = false; bool active = false;