Add slide animation to Info::TopBarOverride.

This commit is contained in:
John Preston 2017-11-24 18:12:23 +04:00
parent 9eacb11f3c
commit 9dc39cb758
2 changed files with 44 additions and 26 deletions

View File

@ -46,6 +46,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "styles/style_info.h" #include "styles/style_info.h"
#include "styles/style_profile.h" #include "styles/style_profile.h"
#include "styles/style_window.h"
namespace Info { namespace Info {
namespace { namespace {
@ -329,7 +330,7 @@ void WrapWidget::createTopBar() {
// addProfileNotificationsButton(); // addProfileNotificationsButton();
} }
_topBar->move(0, 0); _topBar->lower();
_topBar->resizeToWidth(width()); _topBar->resizeToWidth(width());
_topBar->show(); _topBar->show();
} }
@ -419,46 +420,58 @@ void WrapWidget::showProfileMenu() {
} }
void WrapWidget::refreshTopBarOverride(SelectedItems &&items) { void WrapWidget::refreshTopBarOverride(SelectedItems &&items) {
if (items.list.empty()) { auto empty = items.list.empty();
destroyTopBarOverride(); if (!empty) {
} else if (_topBarOverride) { if (_topBarOverride) {
_topBarOverride->setItems(std::move(items)); _topBarOverride->setItems(std::move(items));
} else { } else {
createTopBarOverride(std::move(items)); createTopBarOverride(std::move(items));
}
} }
toggleTopBarOverride(!empty);
} }
void WrapWidget::refreshTopBarOverride() { void WrapWidget::refreshTopBarOverride() {
if (_topBarOverride) { if (_topBarOverride) {
auto items = _topBarOverride->takeItems(); auto items = _topBarOverride->takeItems();
destroyTopBarOverride();
createTopBarOverride(std::move(items)); createTopBarOverride(std::move(items));
topBarOverrideStep();
} }
} }
void WrapWidget::destroyTopBarOverride() { void WrapWidget::toggleTopBarOverride(bool shown) {
if (!_topBarOverride) { if (_topBarOverrideShown == shown) {
return; return;
} }
auto widget = std::exchange(_topBarOverride, nullptr); _topBarOverrideShown = shown;
auto handle = weak(widget.data()); _topBar->show();
_topBarOverrideAnimation.start([this, handle] { _topBarOverrideAnimation.start(
}, 1., 0., st::slideWrapDuration); [this] { topBarOverrideStep(); },
widget.destroy(); _topBarOverrideShown ? 0. : 1.,
_topBarOverrideShown ? 1. : 0.,
st::topBarSlideDuration,
anim::easeOutCirc);
}
// This was done for tabs support. void WrapWidget::topBarOverrideStep() {
// auto shown = _topBarOverrideAnimation.current(
//if (_topTabs) { _topBarOverrideShown ? 1. : 0.);
// _topTabs->show(); auto topBarTop = anim::interpolate(0, _topBar->height(), shown);
//} auto overrideTop = anim::interpolate(-_topBar->height(), 0, shown);
_topBar->moveToLeft(0, topBarTop);
if (_topBar) { if (_topBarOverride) {
_topBar->show(); _topBarOverride->moveToLeft(0, overrideTop);
}
if (!_topBarOverrideAnimation.animating()) {
if (_topBarOverrideShown) {
_topBar->hide();
} else {
_topBarOverride = nullptr;
}
} }
} }
void WrapWidget::createTopBarOverride(SelectedItems &&items) { void WrapWidget::createTopBarOverride(SelectedItems &&items) {
Expects(_topBarOverride == nullptr);
_topBarOverride.create( _topBarOverride.create(
this, this,
TopBarStyle(wrap()), TopBarStyle(wrap()),
@ -477,7 +490,6 @@ void WrapWidget::createTopBarOverride(SelectedItems &&items) {
| rpl::start_with_next([this](auto) { | rpl::start_with_next([this](auto) {
_content->cancelSelection(); _content->cancelSelection();
}, _topBarOverride->lifetime()); }, _topBarOverride->lifetime());
_topBarOverride->moveToLeft(0, 0);
_topBarOverride->resizeToWidth(width()); _topBarOverride->resizeToWidth(width());
_topBarOverride->show(); _topBarOverride->show();
} }
@ -821,6 +833,10 @@ void WrapWidget::showNewContent(
showNewContent(memento); showNewContent(memento);
} }
if (animationParams) { if (animationParams) {
refreshTopBarOverride(SelectedItems(Section::MediaType::kCount));
_topBarOverrideAnimation.finish();
topBarOverrideStep();
showAnimated( showAnimated(
saveToStack saveToStack
? SlideDirection::FromRight ? SlideDirection::FromRight

View File

@ -193,7 +193,8 @@ private:
void refreshTopBarOverride(); void refreshTopBarOverride();
void refreshTopBarOverride(SelectedItems &&items); void refreshTopBarOverride(SelectedItems &&items);
void createTopBarOverride(SelectedItems &&items); void createTopBarOverride(SelectedItems &&items);
void destroyTopBarOverride(); void toggleTopBarOverride(bool shown);
void topBarOverrideStep();
bool requireTopBarSearch() const; bool requireTopBarSearch() const;
void addProfileMenuButton(); void addProfileMenuButton();
@ -210,6 +211,7 @@ private:
object_ptr<Ui::RpWidget> _topBarSurrogate = { nullptr }; object_ptr<Ui::RpWidget> _topBarSurrogate = { nullptr };
object_ptr<TopBarOverride> _topBarOverride = { nullptr }; object_ptr<TopBarOverride> _topBarOverride = { nullptr };
Animation _topBarOverrideAnimation; Animation _topBarOverrideAnimation;
bool _topBarOverrideShown = false;
object_ptr<Ui::FadeShadow> _topShadow; object_ptr<Ui::FadeShadow> _topShadow;
base::unique_qptr<Ui::IconButton> _topBarMenuToggle; base::unique_qptr<Ui::IconButton> _topBarMenuToggle;
base::unique_qptr<Ui::DropdownMenu> _topBarMenu; base::unique_qptr<Ui::DropdownMenu> _topBarMenu;