mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Allow playing single lottie icon repeatedly or once.
This commit is contained in:
@@ -249,8 +249,7 @@ not_null<Ui::FlatLabel*> AddSubsectionTitle(
|
||||
LottieIcon CreateLottieIcon(
|
||||
not_null<QWidget*> parent,
|
||||
Lottie::IconDescriptor &&descriptor,
|
||||
style::margins padding,
|
||||
bool playOnce) {
|
||||
style::margins padding) {
|
||||
auto object = object_ptr<Ui::RpWidget>(parent);
|
||||
const auto raw = object.data();
|
||||
|
||||
@@ -263,23 +262,22 @@ LottieIcon CreateLottieIcon(
|
||||
const auto icon = owned.get();
|
||||
|
||||
raw->lifetime().add([kept = std::move(owned)]{});
|
||||
const auto animationRequired = raw->lifetime().make_state<bool>(true);
|
||||
const auto looped = raw->lifetime().make_state<bool>(true);
|
||||
|
||||
const auto animate = [=] {
|
||||
if (playOnce) {
|
||||
if (!base::take(*animationRequired)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const auto start = [=] {
|
||||
icon->animate([=] { raw->update(); }, 0, icon->framesCount() - 1);
|
||||
};
|
||||
const auto animate = [=](anim::repeat repeat) {
|
||||
*looped = (repeat == anim::repeat::loop);
|
||||
start();
|
||||
};
|
||||
raw->paintRequest(
|
||||
) | rpl::start_with_next([=] {
|
||||
auto p = QPainter(raw);
|
||||
const auto left = (raw->width() - width) / 2;
|
||||
icon->paint(p, left, padding.top());
|
||||
if (!icon->animating() && icon->frameIndex() > 0) {
|
||||
animate();
|
||||
if (!icon->animating() && icon->frameIndex() > 0 && *looped) {
|
||||
start();
|
||||
}
|
||||
|
||||
}, raw->lifetime());
|
||||
|
Reference in New Issue
Block a user