Moved out close and back buttons within profile top bar class.

This commit is contained in:
23rd
2025-10-08 17:51:16 +03:00
parent b8ccf7b3d4
commit 9876aa64e0
3 changed files with 57 additions and 41 deletions
@@ -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<Ui::RpWidget> InnerWidget::createPinnedToTop(
TopBar::Descriptor{
.controller = _controller,
});
struct State {
base::unique_qptr<Ui::IconButton> close;
base::unique_qptr<Ui::FadeWrap<Ui::IconButton>> back;
};
const auto state = content->lifetime().make_state<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<Ui::FadeWrap<Ui::IconButton>>(
content,
object_ptr<Ui::IconButton>(
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<Ui::IconButton>(
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<Ui::RpWidget*>{ content });
}
@@ -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*> controller,
rpl::producer<bool> 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<Ui::FadeWrap<Ui::IconButton>>(
this,
object_ptr<Ui::IconButton>(
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<Ui::IconButton>(
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
@@ -19,6 +19,9 @@ struct InfoTopBar;
namespace Ui {
class FlatLabel;
class IconButton;
template <typename Widget>
class FadeWrap;
} //namespace Ui
namespace Info {
@@ -40,6 +43,9 @@ public:
void setRoundEdges(bool value);
void setEnableBackButtonValue(rpl::producer<bool> &&producer);
void setupButtons(
not_null<Controller*> controller,
rpl::producer<bool> backToggles);
protected:
void resizeEvent(QResizeEvent *e) override;
@@ -66,6 +72,9 @@ private:
InMemoryKey _userpicUniqueKey;
QImage _cachedUserpic;
base::unique_qptr<Ui::IconButton> _close;
base::unique_qptr<Ui::FadeWrap<Ui::IconButton>> _back;
};
} // namespace Info::Profile