diff --git a/ui/widgets/checkbox.cpp b/ui/widgets/checkbox.cpp index 450810a..c589dcf 100644 --- a/ui/widgets/checkbox.cpp +++ b/ui/widgets/checkbox.cpp @@ -10,6 +10,7 @@ #include "ui/basic_click_handlers.h" #include "ui/ui_utility.h" #include "ui/painter.h" +#include "styles/palette.h" #include #include @@ -290,6 +291,47 @@ void CheckView::setUntoggledOverride( update(); } +Fn CheckView::PrepareNonToggledError( + not_null view, + rpl::lifetime &lifetime) { + struct State { + bool error = false; + Ui::Animations::Simple errorAnimation; + }; + const auto state = lifetime.make_state(); + + view->checkedChanges( + ) | rpl::filter([=](bool checked) { + return checked; + }) | rpl::start_with_next([=] { + state->error = false; + view->setUntoggledOverride(std::nullopt); + }, lifetime); + + return [=] { + const auto callback = [=] { + const auto error = state->errorAnimation.value( + state->error ? 1. : 0.); + if (error == 0.) { + view->setUntoggledOverride(std::nullopt); + } else { + const auto color = anim::color( + st::defaultCheck.untoggledFg, + st::boxTextFgError, + error); + view->setUntoggledOverride(color); + } + }; + state->error = true; + state->errorAnimation.stop(); + state->errorAnimation.start( + callback, + 0., + 1., + st::defaultCheck.duration); + }; +} + RadioView::RadioView( const style::Radio &st, bool checked, diff --git a/ui/widgets/checkbox.h b/ui/widgets/checkbox.h index 5ec517f..79fa5f4 100644 --- a/ui/widgets/checkbox.h +++ b/ui/widgets/checkbox.h @@ -75,6 +75,10 @@ public: void setUntoggledOverride( std::optional untoggledOverride); + [[nodiscard]] static Fn PrepareNonToggledError( + not_null view, + rpl::lifetime &lifetime); + private: QSize rippleSize() const;