diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp index 8ddb642d38..d5917354a9 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp @@ -327,7 +327,7 @@ int InnerWidget::resizeGetHeight(int newWidth) { } void InnerWidget::enableBackButton() { - _backToggles = true; + _backToggles.force_assign(true); } bool InnerWidget::hasFlexibleTopBar() const { @@ -341,46 +341,7 @@ base::weak_qptr InnerWidget::createPinnedToTop( TopBar::Descriptor{ .controller = _controller, }); - struct State { - base::unique_qptr close; - base::unique_qptr> back; - }; - const auto state = content->lifetime().make_state(); - const auto controller = _controller; - controller->wrapValue() | rpl::start_with_next([=](Wrap wrap) { - const auto isLayer = (wrap == Wrap::Layer); - content->setRoundEdges(isLayer); - - state->back = base::make_unique_q>( - content, - object_ptr( - content, - (isLayer ? st::infoTopBarBack : st::infoLayerTopBarBack)), - st::infoTopBarScale); - state->back->setDuration(0); - state->back->toggleOn(isLayer - ? _backToggles.value() | rpl::type_erased() - : rpl::single(true)); - content->setEnableBackButtonValue(state->back->toggledValue()); - state->back->entity()->addClickHandler([=] { - controller->showBackFromStack(); - }); - - if (!isLayer) { - state->close = nullptr; - } else { - state->close = base::make_unique_q( - content, - st::infoTopBarClose); - state->close->addClickHandler([=] { - controller->parentController()->hideLayer(); - controller->parentController()->hideSpecialLayer(); - }); - content->widthValue() | rpl::start_with_next([=] { - state->close->moveToRight(0, 0); - }, state->close->lifetime()); - } - }, content->lifetime()); + content->setupButtons(_controller, _backToggles.value()); return base::make_weak(not_null{ content }); } diff --git a/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp b/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp index 34fc741f2d..9a0299c461 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp @@ -9,13 +9,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_changes.h" #include "data/data_peer.h" +#include "info/info_controller.h" +#include "info/info_memento.h" #include "info_profile_actions.h" #include "info/profile/info_profile_status_label.h" #include "info/profile/info_profile_values.h" #include "main/main_session.h" #include "ui/effects/animations.h" #include "ui/painter.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" +#include "ui/wrap/fade_wrap.h" #include "styles/style_boxes.h" #include "styles/style_info.h" #include "styles/style_layers.h" @@ -146,4 +150,46 @@ void TopBar::paintEvent(QPaintEvent *e) { paintUserpic(p); } +void TopBar::setupButtons( + not_null controller, + rpl::producer backToggles) { + controller->wrapValue() | rpl::start_with_next([=, + backToggles = std::move(backToggles)](Wrap wrap) mutable { + const auto isLayer = (wrap == Wrap::Layer); + setRoundEdges(isLayer); + + _back = base::make_unique_q>( + this, + object_ptr( + this, + (isLayer + ? st::infoTopBarBack + : st::infoLayerTopBarBack)), + st::infoTopBarScale); + _back->setDuration(0); + _back->toggleOn(isLayer + ? rpl::duplicate(backToggles) | rpl::type_erased() + : rpl::single(true)); + setEnableBackButtonValue(_back->toggledValue()); + _back->entity()->addClickHandler([=] { + controller->showBackFromStack(); + }); + + if (!isLayer) { + _close = nullptr; + } else { + _close = base::make_unique_q( + this, + st::infoTopBarClose); + _close->addClickHandler([=] { + controller->parentController()->hideLayer(); + controller->parentController()->hideSpecialLayer(); + }); + widthValue() | rpl::start_with_next([=] { + _close->moveToRight(0, 0); + }, _close->lifetime()); + } + }, lifetime()); +} + } // namespace Info::Profile diff --git a/Telegram/SourceFiles/info/profile/info_profile_top_bar.h b/Telegram/SourceFiles/info/profile/info_profile_top_bar.h index 4b6d056eba..a3924e670e 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_top_bar.h +++ b/Telegram/SourceFiles/info/profile/info_profile_top_bar.h @@ -19,6 +19,9 @@ struct InfoTopBar; namespace Ui { class FlatLabel; +class IconButton; +template +class FadeWrap; } //namespace Ui namespace Info { @@ -40,6 +43,9 @@ public: void setRoundEdges(bool value); void setEnableBackButtonValue(rpl::producer &&producer); + void setupButtons( + not_null controller, + rpl::producer backToggles); protected: void resizeEvent(QResizeEvent *e) override; @@ -66,6 +72,9 @@ private: InMemoryKey _userpicUniqueKey; QImage _cachedUserpic; + base::unique_qptr _close; + base::unique_qptr> _back; + }; } // namespace Info::Profile