diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 3530341c0..ae6faa563 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -609,7 +609,7 @@ rightsButton: SettingsButton(defaultSettingsButton) { toggle: rightsToggle; toggleOver: rightsToggle; - toggleSkip: 19px; + toggleSkip: 20px; } rightsButtonToggleWidth: 70px; rightsDividerMargin: margins(0px, 0px, 0px, 20px); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 0cce8689d..563cc3370 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -229,7 +229,7 @@ ChatRestrictions DisabledByAdminRights(not_null peer) { : Flag::ChangeInfo); } -not_null SendMediaToggle( +not_null SendMediaToggle( not_null container, rpl::producer checkedValue, int total, @@ -239,12 +239,24 @@ not_null SendMediaToggle( const auto &stButton = st::rightsButton; const auto button = container->add(object_ptr( container, - rpl::single(QString()), + nullptr, stButton)); const auto toggleButton = Ui::CreateChild( container.get(), - rpl::single(QString()), + nullptr, stButton); + + struct State final { + State(const style::Toggle &st, Fn c) + : checkView(st, false, c) { + } + Ui::ToggleView checkView; + Ui::Animations::Simple animation; + }; + const auto state = button->lifetime().make_state( + stButton.toggle, + [=] { toggleButton->update(); }); + const auto checkView = &state->checkView; { const auto separator = Ui::CreateChild(container.get()); separator->paintRequest( @@ -269,23 +281,28 @@ not_null SendMediaToggle( kLineWidth, separatorHeight); }, toggleButton->lifetime()); + + const auto checkWidget = Ui::CreateChild(toggleButton); + checkWidget->resize(checkView->getSize()); + checkWidget->paintRequest( + ) | rpl::start_with_next([=] { + auto p = QPainter(checkWidget); + checkView->paint(p, 0, 0, checkWidget->width()); + }, checkWidget->lifetime()); + toggleButton->sizeValue( + ) | rpl::start_with_next([=](const QSize &s) { + checkWidget->moveToRight( + stButton.toggleSkip, + (s.height() - checkWidget->height()) / 2); + }, toggleButton->lifetime()); } - using namespace rpl::mappers; - button->toggleOn(rpl::duplicate(checkedValue) | rpl::map(_1 > 0), true); - toggleButton->toggleOn(button->toggledValue(), true); - button->setToggleLocked(locked.has_value()); - toggleButton->setToggleLocked(locked.has_value()); - struct State final { - Ui::Animations::Simple animation; - rpl::lifetime finishAnimatingLifetime; - }; - const auto state = button->lifetime().make_state(); rpl::duplicate( checkedValue - ) | rpl::start_with_next([=] { - button->finishAnimating(); - toggleButton->finishAnimating(); - }, state->finishAnimatingLifetime); + ) | rpl::start_with_next([=](int count) { + checkView->setChecked(count > 0, anim::type::normal); + }, toggleButton->lifetime()); + checkView->setLocked(locked.has_value()); + checkView->finishAnimating(); const auto label = Ui::CreateChild( button, rpl::combine( @@ -323,7 +340,7 @@ not_null SendMediaToggle( } button->sizeValue( ) | rpl::start_with_next([=](const QSize &s) { - const auto labelLeft = st::rightsButton.padding.left(); + const auto labelLeft = stButton.padding.left(); const auto labelRight = s.width() - toggleButton->width(); label->resizeToWidth(labelRight - labelLeft - arrow->width()); @@ -366,71 +383,13 @@ not_null SendMediaToggle( toggleButton->clicks( ) | rpl::start_with_next([=] { if (!handleLocked()) { - toggleMedia(!button->toggled()); - state->finishAnimatingLifetime.destroy(); + toggleMedia(!checkView->checked()); } }, toggleButton->lifetime()); return button; } -not_null AddInnerCheckbox( - not_null container, - const QString &text, - bool toggled, - rpl::producer<> toggledChanges) { - class Button final : public Ui::SettingsButton { - public: - using Ui::SettingsButton::SettingsButton; - - protected: - void paintEvent(QPaintEvent *e) override { - Painter p(this); - - const auto paintOver = (isOver() || isDown()) && !isDisabled(); - Ui::SettingsButton::paintBg(p, e->rect(), paintOver); - Ui::SettingsButton::paintRipple(p, 0, 0); - } - - }; - - const auto checkbox = container->add( - object_ptr( - container, - text, - toggled, - st::settingsCheckbox), - st::rightsButton.padding); - const auto button = Ui::CreateChild