diff --git a/Telegram/SourceFiles/ui/chat/pinned_bar.cpp b/Telegram/SourceFiles/ui/chat/pinned_bar.cpp index f3c6723e01..d46141ebae 100644 --- a/Telegram/SourceFiles/ui/chat/pinned_bar.cpp +++ b/Telegram/SourceFiles/ui/chat/pinned_bar.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/message_bar.h" #include "ui/widgets/shadow.h" #include "ui/widgets/buttons.h" +#include "ui/wrap/fade_wrap.h" #include "styles/style_chat.h" #include "styles/palette.h" @@ -68,15 +69,24 @@ PinnedBar::PinnedBar( } PinnedBar::~PinnedBar() { - _rightButton.destroy(); + _right.button.destroy(); } void PinnedBar::setRightButton(object_ptr button) { - _rightButton.destroy(); - _rightButton = std::move(button); - if (_rightButton) { - _rightButton->setParent(_wrap.entity()); - _rightButton->show(); + if (auto previous = _right.button.release()) { + _right.previousButtonLifetime.make_state( + RightButton::fromRaw(std::move(previous))); + _right.previousButtonLifetime = previous->toggledValue( + ) | rpl::filter(!rpl::mappers::_1) | rpl::start_with_next([=] { + _right.previousButtonLifetime.destroy(); + }); + previous->hide(anim::type::normal); + } + _right.button.create(_wrap.entity(), std::move(button)); + if (_right.button) { + _right.button->setParent(_wrap.entity()); + _right.button->setDuration(st::defaultMessageBar.duration); + _right.button->show(anim::type::normal); } if (_bar) { updateControlsGeometry(_wrap.geometry()); @@ -85,13 +95,13 @@ void PinnedBar::setRightButton(object_ptr button) { void PinnedBar::updateControlsGeometry(QRect wrapGeometry) { _bar->widget()->resizeToWidth( - wrapGeometry.width() - (_rightButton ? _rightButton->width() : 0)); + wrapGeometry.width() - (_right.button ? _right.button->width() : 0)); const auto hidden = _wrap.isHidden() || !wrapGeometry.height(); if (_shadow->isHidden() != hidden) { _shadow->setVisible(!hidden); } - if (_rightButton) { - _rightButton->moveToRight(0, 0); + if (_right.button) { + _right.button->moveToRight(0, 0); } } @@ -117,8 +127,8 @@ void PinnedBar::createControls() { _bar = std::make_unique( _wrap.entity(), st::defaultMessageBar); - if (_rightButton) { - _rightButton->raise(); + if (_right.button) { + _right.button->raise(); } // Clicks. diff --git a/Telegram/SourceFiles/ui/chat/pinned_bar.h b/Telegram/SourceFiles/ui/chat/pinned_bar.h index fd47824af6..fd6a45c44f 100644 --- a/Telegram/SourceFiles/ui/chat/pinned_bar.h +++ b/Telegram/SourceFiles/ui/chat/pinned_bar.h @@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { struct MessageBarContent; +template +class FadeWrapScaled; class MessageBar; class IconButton; class PlainShadow; @@ -45,13 +47,19 @@ public: } private: + using RightButton = object_ptr>; void createControls(); void updateShadowGeometry(QRect wrapGeometry); void updateControlsGeometry(QRect wrapGeometry); Ui::SlideWrap<> _wrap; std::unique_ptr _bar; - object_ptr _rightButton = { nullptr }; + + struct { + RightButton button = { nullptr }; + rpl::lifetime previousButtonLifetime; + } _right; + std::unique_ptr _shadow; rpl::event_stream<> _barClicks; Fn _shadowGeometryPostprocess;