Animate Info-to-Info transitions.

This commit is contained in:
John Preston 2017-10-03 15:57:11 +01:00
parent 93c15e5ee6
commit c6c75a1980
16 changed files with 128 additions and 131 deletions

View File

@ -125,12 +125,17 @@ rpl::producer<int> ContentWidget::desiredHeightValue() const {
return value + _scrollTopSkip;
});
}
rpl::producer<bool> ContentWidget::desiredShadowVisibility() const {
using namespace rpl::mappers;
return _scroll->scrollTopValue()
| rpl::map($1 > 0);
}
bool ContentWidget::hasTopBarShadow() const {
return (_scroll->scrollTop() > 0);
}
int ContentWidget::scrollTopSave() const {
return _scroll->scrollTop();
}

View File

@ -62,6 +62,7 @@ public:
rpl::producer<int> desiredHeightValue() const override;
rpl::producer<bool> desiredShadowVisibility() const;
bool hasTopBarShadow() const;
virtual void setInnerFocus() {
_inner->setFocus();

View File

@ -57,7 +57,7 @@ LayerWidget::LayerWidget(
void LayerWidget::setupHeightConsumers() {
_content->desiredHeightValue()
| rpl::start_with_next([this](int height) {
_desiredHeight = height;
accumulate_max(_desiredHeight, height);
resizeToWidth(width());
}, lifetime());
}

View File

@ -56,7 +56,7 @@ void SectionWidget::init() {
}
PeerData *SectionWidget::peerForDialogs() const {
return _content->peer();
return _content->peerForDialogs();
}
bool SectionWidget::hasTopBarShadow() const {
@ -73,7 +73,7 @@ void SectionWidget::doSetInnerFocus() {
}
void SectionWidget::showFinishedHook() {
_content->showFinished();
_content->showFast();
}
bool SectionWidget::showInternal(

View File

@ -47,7 +47,6 @@ public:
Wrap wrap,
not_null<MoveMemento*> memento);
not_null<PeerData*> peer() const;
PeerData *peerForDialogs() const override;
bool hasTopBarShadow() const override;

View File

@ -49,7 +49,7 @@ void TopBar::enableBackButton(bool enable) {
if (enable) {
_back.create(this, _st.back);
_back->clicks()
| rpl::start_to_stream(_backClicks, lifetime());
| rpl::start_to_stream(_backClicks, _back->lifetime());
} else {
_back.destroy();
}

View File

@ -50,9 +50,8 @@ WrapWidget::WrapWidget(
not_null<Window::Controller*> controller,
Wrap wrap,
not_null<Memento*> memento)
: RpWidget(parent)
: SectionWidget(parent, controller)
, _wrap(wrap)
, _controller(controller)
, _topShadow(this) {
_topShadow->toggleOn(topShadowToggledValue());
showNewContent(memento->content());
@ -89,6 +88,14 @@ void WrapWidget::createTabs() {
_topTabs->move(0, 0);
_topTabs->resizeToWidth(width());
_topTabs->show();
_topTabsBackground.create(this, st::profileBg);
_topTabsBackground->move(0, 0);
_topTabsBackground->resize(
width(),
_topTabs->height() - st::lineWidth);
_topTabsBackground->show();
}
void WrapWidget::showTab(Tab tab) {
@ -156,10 +163,9 @@ void WrapWidget::createTopBar(
auto close = _topBar->addButton(object_ptr<Ui::IconButton>(
_topBar,
st::infoLayerTopBarClose));
close->clicks()
| rpl::start_with_next([this] {
_controller->hideSpecialLayer();
}, close->lifetime());
close->addClickHandler([this] {
controller()->hideSpecialLayer();
});
}
_topBar->move(0, 0);
@ -178,39 +184,20 @@ void WrapWidget::showBackFromStack() {
last.section.get(),
params);
} else {
_controller->showBackFromStack(params);
controller()->showBackFromStack(params);
}
}
not_null<Ui::RpWidget*> WrapWidget::topWidget() const {
if (_topTabs) {
return _topTabs;
return _topTabsBackground;
}
return _topBar;
}
int WrapWidget::topHeightAddition() const {
return _topTabs ? -st::lineWidth : 0;
}
int WrapWidget::topHeight() const {
return topWidget()->height() + topHeightAddition();
}
rpl::producer<int> WrapWidget::topHeightValue() const {
using namespace rpl::mappers;
return topWidget()->heightValue()
| rpl::map($1 + topHeightAddition());
}
void WrapWidget::showContent(object_ptr<ContentWidget> content) {
_content = std::move(content);
_content->show();
_topShadow->raise();
if (_topTabs) {
_topTabs->raise();
}
finishShowContent();
}
@ -218,10 +205,12 @@ void WrapWidget::finishShowContent() {
updateContentGeometry();
_desiredHeights.fire(desiredHeightForContent());
_desiredShadowVisibilities.fire(_content->desiredShadowVisibility());
_topShadow->raise();
_topShadow->finishAnimating();
if (_topTabs) {
_topTabs->raise();
_topTabs->finishAnimating();
}
_topShadow->finishAnimating();
}
rpl::producer<bool> WrapWidget::topShadowToggledValue() const {
@ -236,7 +225,7 @@ rpl::producer<int> WrapWidget::desiredHeightForContent() const {
using namespace rpl::mappers;
return rpl::combine(
_content->desiredHeightValue(),
topHeightValue(),
topWidget()->heightValue(),
$1 + $2);
}
@ -282,17 +271,23 @@ bool WrapWidget::hasTopBarShadow() const {
QPixmap WrapWidget::grabForShowAnimation(
const Window::SectionSlideParams &params) {
if (params.withTopBarShadow) _topShadow->hide(anim::type::instant);
if (params.withTopBarShadow) {
_topShadow->setVisible(false);
} else {
_topShadow->toggle(_topShadow->toggled(), anim::type::instant);
}
auto result = myGrab(this);
if (params.withTopBarShadow) _topShadow->show(anim::type::instant);
if (params.withTopBarShadow) _topShadow->setVisible(true);
return result;
}
void WrapWidget::setInnerFocus() {
void WrapWidget::doSetInnerFocus() {
_content->setInnerFocus();
}
void WrapWidget::showFinished() {
void WrapWidget::showFinishedHook() {
// Restore shadow visibility after showChildren() call.
_topShadow->toggle(_topShadow->toggled(), anim::type::instant);
}
bool WrapWidget::showInternal(
@ -328,7 +323,7 @@ void WrapWidget::saveState(not_null<Memento*> memento) {
}
QRect WrapWidget::contentGeometry() const {
return rect().marginsRemoved({ 0, topHeight(), 0, 0 });
return rect().marginsRemoved({ 0, topWidget()->height(), 0, 0 });
}
void WrapWidget::showNewContent(
@ -336,14 +331,15 @@ void WrapWidget::showNewContent(
const Window::SectionShow &params) {
auto saveToStack = (_content != nullptr)
&& (params.way == Window::SectionShow::Way::Forward);
auto showAnimated = (_content != nullptr)
auto needAnimation = (_content != nullptr)
&& (params.animated != anim::type::instant);
if (showAnimated) {
auto animationParams = SectionSlideParams();
if (needAnimation) {
auto newContent = createContent(memento);
auto params = SectionSlideParams();
// params.withTopBarShadow = newContent;
} else {
animationParams.withTopBarShadow = hasTopBarShadow()
&& newContent->hasTopBarShadow();
animationParams.oldContentCache = grabForShowAnimation(
animationParams);
}
if (saveToStack) {
auto item = StackItem();
@ -356,6 +352,13 @@ void WrapWidget::showNewContent(
_historyStack.clear();
}
showNewContent(memento);
if (animationParams) {
showAnimated(
saveToStack
? SlideDirection::FromRight
: SlideDirection::FromLeft,
animationParams);
}
}
void WrapWidget::showNewContent(not_null<ContentMemento*> memento) {
@ -368,6 +371,7 @@ void WrapWidget::setupTabs(Tab tab) {
_tab = tab;
if (_tab == Tab::None) {
_topTabs.destroy();
_topTabsBackground.destroy();
} else if (!_topTabs) {
createTabs();
} else {
@ -376,23 +380,25 @@ void WrapWidget::setupTabs(Tab tab) {
}
void WrapWidget::resizeEvent(QResizeEvent *e) {
topWidget()->resizeToWidth(width());
if (_topTabs) {
_topTabs->resizeToWidth(width());
_topTabsBackground->resize(
width(),
_topTabs->height() - st::lineWidth);
} else if (_topBar) {
_topBar->resizeToWidth(width());
}
updateContentGeometry();
}
void WrapWidget::updateContentGeometry() {
if (_content) {
_topShadow->resizeToWidth(width());
_topShadow->moveToLeft(0, topHeight());
_topShadow->moveToLeft(0, topWidget()->height());
_content->setGeometry(contentGeometry());
}
}
void WrapWidget::paintEvent(QPaintEvent *e) {
Painter p(this);
p.fillRect(e->rect(), st::profileBg);
}
bool WrapWidget::wheelEventFromFloatPlayer(QEvent *e) {
return _content->wheelEventFromFloatPlayer(e);
}

View File

@ -27,6 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace Ui {
class SettingsSlider;
class FadeShadow;
class PlainShadow;
} // namespace Ui
namespace Window {
@ -86,7 +87,7 @@ private:
};
class WrapWidget final : public Ui::RpWidget {
class WrapWidget final : public Window::SectionWidget {
public:
WrapWidget(
QWidget *parent,
@ -95,39 +96,38 @@ public:
not_null<Memento*> memento);
not_null<PeerData*> peer() const;
PeerData *peerForDialogs() const override {
return peer();
}
Wrap wrap() const;
void setWrap(Wrap wrap);
bool hasTopBarShadow() const;
bool hasTopBarShadow() const override;
QPixmap grabForShowAnimation(
const Window::SectionSlideParams &params);
const Window::SectionSlideParams &params) override;
bool showInternal(
not_null<Window::SectionMemento*> memento,
const Window::SectionShow &params);
std::unique_ptr<Window::SectionMemento> createMemento();
const Window::SectionShow &params) override;
std::unique_ptr<Window::SectionMemento> createMemento() override;
rpl::producer<int> desiredHeightValue() const;
void setInnerFocus();
void showFinished();
void updateInternalState(not_null<Memento*> memento);
void saveState(not_null<Memento*> memento);
// Float player interface.
bool wheelEventFromFloatPlayer(QEvent *e);
QRect rectForFloatPlayer() const;
bool wheelEventFromFloatPlayer(QEvent *e) override;
QRect rectForFloatPlayer() const override;
~WrapWidget();
protected:
void resizeEvent(QResizeEvent *e);
void paintEvent(QPaintEvent *e);
not_null<Window::Controller*> controller() const {
return _controller;
}
void doSetInnerFocus() override;
void showFinishedHook() override;
private:
using SlideDirection = Window::SlideDirection;
@ -153,9 +153,6 @@ private:
PeerId peerId);
not_null<RpWidget*> topWidget() const;
int topHeightAddition() const;
int topHeight() const;
rpl::producer<int> topHeightValue() const;
QRect contentGeometry() const;
rpl::producer<int> desiredHeightForContent() const;
@ -172,8 +169,8 @@ private:
not_null<ContentMemento*> memento);
rpl::variable<Wrap> _wrap;
not_null<Window::Controller*> _controller;
object_ptr<ContentWidget> _content = { nullptr };
object_ptr<Ui::PlainShadow> _topTabsBackground = { nullptr };
object_ptr<Ui::SettingsSlider> _topTabs = { nullptr };
object_ptr<TopBar> _topBar = { nullptr };
object_ptr<Ui::FadeShadow> _topShadow;

View File

@ -51,10 +51,9 @@ Button *Button::toggleOn(rpl::producer<bool> &&toggled) {
isOver() ? _st.toggleOver : _st.toggle,
false,
[this] { rtlupdate(toggleRect()); });
clicks()
| rpl::start_with_next([this] {
_toggle->setCheckedAnimated(!_toggle->checked());
}, lifetime());
addClickHandler([this] {
_toggle->setCheckedAnimated(!_toggle->checked());
});
std::move(toggled)
| rpl::start_with_next([this](bool toggled) {
_toggle->setCheckedAnimated(toggled);

View File

@ -204,14 +204,13 @@ object_ptr<Ui::RpWidget> InnerWidget::setupMuteToggle(
st::infoNotificationsButton);
result->toggleOn(
NotificationsEnabledValue(_peer)
)->clicks()
| rpl::start_with_next([this] {
App::main()->updateNotifySetting(
_peer,
_peer->isMuted()
? NotifySettingSetNotify
: NotifySettingSetMuted);
}, result->lifetime());
)->addClickHandler([this] {
App::main()->updateNotifySetting(
_peer,
_peer->isMuted()
? NotifySettingSetNotify
: NotifySettingSetMuted);
});
object_ptr<FloatingIcon>(
result,
st::infoIconNotifications,
@ -240,26 +239,24 @@ void InnerWidget::setupUserButtons(
)->toggleOn(
_controller->historyPeer.value()
| rpl::map($1 != user)
)->entity()->clicks()
| rpl::start_with_next([this, user] {
_controller->showPeerHistory(
user,
Window::SectionShow::Way::Forward);
}, wrap->lifetime());
)->entity()->addClickHandler([this, user] {
_controller->showPeerHistory(
user,
Window::SectionShow::Way::Forward);
});
addButton(
Lang::Viewer(lng_info_add_as_contact) | ToUpperValue()
)->toggleOn(
CanAddContactValue(user)
)->entity()->clicks()
| rpl::start_with_next([user] {
auto firstName = user->firstName;
auto lastName = user->lastName;
auto phone = user->phone().isEmpty()
? App::phoneFromSharedContact(user->bareId())
: user->phone();
Ui::show(Box<AddContactBox>(firstName, lastName, phone));
}, wrap->lifetime());
)->entity()->addClickHandler([user] {
auto firstName = user->firstName;
auto lastName = user->lastName;
auto phone = user->phone().isEmpty()
? App::phoneFromSharedContact(user->bareId())
: user->phone();
Ui::show(Box<AddContactBox>(firstName, lastName, phone));
});
topSkip->toggleOn(std::move(tracker).atLeastOneShownValue());
}
@ -311,10 +308,9 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
[phrase = mediaText(type)](int count) {
return phrase(lt_count, count);
}
)->entity()->clicks()
| rpl::start_with_next([peer = _peer, type] {
SharedMediaShowOverview(type, App::history(peer));
}, content->lifetime());
)->entity()->addClickHandler([peer = _peer, type] {
SharedMediaShowOverview(type, App::history(peer));
});
};
auto addCommonGroupsButton = [&](not_null<UserData*> user) {
return addButton(
@ -322,12 +318,11 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
[](int count) {
return lng_profile_common_groups(lt_count, count);
}
)->entity()->clicks()
| rpl::start_with_next([this, peer = _peer] {
_controller->showSection(
::Profile::CommonGroups::SectionMemento(
peer->asUser()));
}, content->lifetime());
)->entity()->addClickHandler([this, peer = _peer] {
_controller->showSection(
::Profile::CommonGroups::SectionMemento(
peer->asUser()));
});
};
addMediaButton(MediaType::Photo);
addMediaButton(MediaType::Video);
@ -388,10 +383,7 @@ object_ptr<Ui::RpWidget> InnerWidget::setupUserActions(
st))
)->toggleOn(
std::move(toggleOn)
)->entity()->clicks()
| rpl::start_with_next([callback = std::move(callback)] {
callback();
}, result->lifetime());
)->entity()->addClickHandler(std::move(callback));
};
addButton(

View File

@ -117,24 +117,21 @@ void Members::setupButtons() {
newWidth);
}, _addMember->lifetime());
_addMember->showOn(rpl::duplicate(addMemberShown));
_addMember->clicks() // TODO throttle(ripple duration)
| rpl::start_with_next([this] {
this->addMember();
}, _addMember->lifetime());
_addMember->addClickHandler([this] { // TODO throttle(ripple duration)
this->addMember();
});
auto searchShown = MembersCountValue(_peer)
| rpl::map($1 >= kEnableSearchMembersAfterCount)
| rpl::distinct_until_changed()
| rpl::start_spawning(lifetime());
_search->showOn(rpl::duplicate(searchShown));
_search->clicks()
| rpl::start_with_next([this] {
this->showSearch();
}, _search->lifetime());
_cancelSearch->clicks()
| rpl::start_with_next([this] {
this->cancelSearch();
}, _cancelSearch->lifetime());
_search->addClickHandler([this] {
this->showSearch();
});
_cancelSearch->addClickHandler([this] {
this->cancelSearch();
});
rpl::combine(
std::move(addMemberShown),

View File

@ -310,6 +310,8 @@ void InnerWidget::mouseMoveEvent(QMouseEvent *e) {
}
void InnerWidget::mouseReleaseEvent(QMouseEvent *e) {
setCursor(_selected ? style::cur_pointer : style::cur_default);
updateRow(_selected);
updateRow(_pressed);
auto pressed = std::exchange(_pressed, -1);
if (pressed >= 0 && pressed < _items.size()) {
@ -322,8 +324,6 @@ void InnerWidget::mouseReleaseEvent(QMouseEvent *e) {
Window::SectionShow::Way::Forward);
}
}
setCursor(_selected ? style::cur_pointer : style::cur_default);
updateRow(_selected);
}
InnerWidget::Item *InnerWidget::computeItem(PeerData *group) {

View File

@ -118,9 +118,6 @@ void FadeAnimation::stopAnimation() {
}
if (_visible == _widget->isHidden()) {
_widget->setVisible(_visible);
if (_visible) {
_widget->showChildren();
}
}
}

View File

@ -84,8 +84,6 @@ void SectionWidget::showFast() {
}
void SectionWidget::paintEvent(QPaintEvent *e) {
if (Ui::skipPaintEvent(this, e)) return;
if (_showAnimation) {
Painter p(this);
_showAnimation->paintContents(p, e->rect());

View File

@ -396,6 +396,7 @@ void TopBarWidget::updateControlsVisibility() {
_call->hide();
_info->hide();
_menuToggle->hide();
_infoToggle->hide();
_menu.destroy();
}
if (_membersShowArea) {

View File

@ -72,7 +72,12 @@ void SlideAnimation::start() {
auto delta = st::slideShift;
auto fromLeft = (_direction == SlideDirection::FromLeft);
if (fromLeft) std::swap(_cacheUnder, _cacheOver);
_animation.start([this] { animationCallback(); }, fromLeft ? 1. : 0., fromLeft ? 0. : 1., st::slideDuration, transition());
_animation.start(
[this] { animationCallback(); },
fromLeft ? 1. : 0.,
fromLeft ? 0. : 1.,
st::slideDuration,
transition());
_repaintCallback();
}