Added fade animation to right button in bar of pinned messages.

This commit is contained in:
23rd 2022-04-22 15:56:33 +03:00 committed by John Preston
parent 100a44daef
commit 7600c9bb2f
2 changed files with 30 additions and 12 deletions

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/message_bar.h" #include "ui/chat/message_bar.h"
#include "ui/widgets/shadow.h" #include "ui/widgets/shadow.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/wrap/fade_wrap.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
#include "styles/palette.h" #include "styles/palette.h"
@ -68,15 +69,24 @@ PinnedBar::PinnedBar(
} }
PinnedBar::~PinnedBar() { PinnedBar::~PinnedBar() {
_rightButton.destroy(); _right.button.destroy();
} }
void PinnedBar::setRightButton(object_ptr<Ui::RpWidget> button) { void PinnedBar::setRightButton(object_ptr<Ui::RpWidget> button) {
_rightButton.destroy(); if (auto previous = _right.button.release()) {
_rightButton = std::move(button); _right.previousButtonLifetime.make_state<RightButton>(
if (_rightButton) { RightButton::fromRaw(std::move(previous)));
_rightButton->setParent(_wrap.entity()); _right.previousButtonLifetime = previous->toggledValue(
_rightButton->show(); ) | 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) { if (_bar) {
updateControlsGeometry(_wrap.geometry()); updateControlsGeometry(_wrap.geometry());
@ -85,13 +95,13 @@ void PinnedBar::setRightButton(object_ptr<Ui::RpWidget> button) {
void PinnedBar::updateControlsGeometry(QRect wrapGeometry) { void PinnedBar::updateControlsGeometry(QRect wrapGeometry) {
_bar->widget()->resizeToWidth( _bar->widget()->resizeToWidth(
wrapGeometry.width() - (_rightButton ? _rightButton->width() : 0)); wrapGeometry.width() - (_right.button ? _right.button->width() : 0));
const auto hidden = _wrap.isHidden() || !wrapGeometry.height(); const auto hidden = _wrap.isHidden() || !wrapGeometry.height();
if (_shadow->isHidden() != hidden) { if (_shadow->isHidden() != hidden) {
_shadow->setVisible(!hidden); _shadow->setVisible(!hidden);
} }
if (_rightButton) { if (_right.button) {
_rightButton->moveToRight(0, 0); _right.button->moveToRight(0, 0);
} }
} }
@ -117,8 +127,8 @@ void PinnedBar::createControls() {
_bar = std::make_unique<MessageBar>( _bar = std::make_unique<MessageBar>(
_wrap.entity(), _wrap.entity(),
st::defaultMessageBar); st::defaultMessageBar);
if (_rightButton) { if (_right.button) {
_rightButton->raise(); _right.button->raise();
} }
// Clicks. // Clicks.

View File

@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui { namespace Ui {
struct MessageBarContent; struct MessageBarContent;
template <typename Widget>
class FadeWrapScaled;
class MessageBar; class MessageBar;
class IconButton; class IconButton;
class PlainShadow; class PlainShadow;
@ -45,13 +47,19 @@ public:
} }
private: private:
using RightButton = object_ptr<Ui::FadeWrapScaled<Ui::RpWidget>>;
void createControls(); void createControls();
void updateShadowGeometry(QRect wrapGeometry); void updateShadowGeometry(QRect wrapGeometry);
void updateControlsGeometry(QRect wrapGeometry); void updateControlsGeometry(QRect wrapGeometry);
Ui::SlideWrap<> _wrap; Ui::SlideWrap<> _wrap;
std::unique_ptr<Ui::MessageBar> _bar; std::unique_ptr<Ui::MessageBar> _bar;
object_ptr<Ui::RpWidget> _rightButton = { nullptr };
struct {
RightButton button = { nullptr };
rpl::lifetime previousButtonLifetime;
} _right;
std::unique_ptr<Ui::PlainShadow> _shadow; std::unique_ptr<Ui::PlainShadow> _shadow;
rpl::event_stream<> _barClicks; rpl::event_stream<> _barClicks;
Fn<QRect(QRect)> _shadowGeometryPostprocess; Fn<QRect(QRect)> _shadowGeometryPostprocess;