mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 07:33:52 +02:00
Allow playing single lottie icon repeatedly or once.
This commit is contained in:
parent
3ff4bf77e7
commit
f2b89445ae
7 changed files with 22 additions and 23 deletions
|
@ -510,7 +510,7 @@ void ChangePhone::setupContent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChangePhone::showFinished() {
|
void ChangePhone::showFinished() {
|
||||||
_animate();
|
_animate(anim::repeat::loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
|
@ -36,7 +36,7 @@ private:
|
||||||
void setupContent();
|
void setupContent();
|
||||||
|
|
||||||
const not_null<Window::SessionController*> _controller;
|
const not_null<Window::SessionController*> _controller;
|
||||||
Fn<void()> _animate;
|
Fn<void(anim::repeat)> _animate;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -171,13 +171,12 @@ void Blocked::setupContent() {
|
||||||
st::changePhoneIconSize,
|
st::changePhoneIconSize,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
st::blockedUsersListIconPadding,
|
st::blockedUsersListIconPadding);
|
||||||
true);
|
|
||||||
content->add(std::move(icon.widget));
|
content->add(std::move(icon.widget));
|
||||||
|
|
||||||
_showFinished.events(
|
_showFinished.events(
|
||||||
) | rpl::start_with_next([animate = std::move(icon.animate)] {
|
) | rpl::start_with_next([animate = std::move(icon.animate)] {
|
||||||
animate();
|
animate(anim::repeat::once);
|
||||||
}, content->lifetime());
|
}, content->lifetime());
|
||||||
|
|
||||||
content->add(
|
content->add(
|
||||||
|
|
|
@ -249,8 +249,7 @@ not_null<Ui::FlatLabel*> AddSubsectionTitle(
|
||||||
LottieIcon CreateLottieIcon(
|
LottieIcon CreateLottieIcon(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
Lottie::IconDescriptor &&descriptor,
|
Lottie::IconDescriptor &&descriptor,
|
||||||
style::margins padding,
|
style::margins padding) {
|
||||||
bool playOnce) {
|
|
||||||
auto object = object_ptr<Ui::RpWidget>(parent);
|
auto object = object_ptr<Ui::RpWidget>(parent);
|
||||||
const auto raw = object.data();
|
const auto raw = object.data();
|
||||||
|
|
||||||
|
@ -263,23 +262,22 @@ LottieIcon CreateLottieIcon(
|
||||||
const auto icon = owned.get();
|
const auto icon = owned.get();
|
||||||
|
|
||||||
raw->lifetime().add([kept = std::move(owned)]{});
|
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 = [=] {
|
const auto start = [=] {
|
||||||
if (playOnce) {
|
|
||||||
if (!base::take(*animationRequired)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
icon->animate([=] { raw->update(); }, 0, icon->framesCount() - 1);
|
icon->animate([=] { raw->update(); }, 0, icon->framesCount() - 1);
|
||||||
};
|
};
|
||||||
|
const auto animate = [=](anim::repeat repeat) {
|
||||||
|
*looped = (repeat == anim::repeat::loop);
|
||||||
|
start();
|
||||||
|
};
|
||||||
raw->paintRequest(
|
raw->paintRequest(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
auto p = QPainter(raw);
|
auto p = QPainter(raw);
|
||||||
const auto left = (raw->width() - width) / 2;
|
const auto left = (raw->width() - width) / 2;
|
||||||
icon->paint(p, left, padding.top());
|
icon->paint(p, left, padding.top());
|
||||||
if (!icon->animating() && icon->frameIndex() > 0) {
|
if (!icon->animating() && icon->frameIndex() > 0 && *looped) {
|
||||||
animate();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}, raw->lifetime());
|
}, raw->lifetime());
|
||||||
|
|
|
@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/object_ptr.h"
|
#include "base/object_ptr.h"
|
||||||
#include "settings/settings_type.h"
|
#include "settings/settings_type.h"
|
||||||
|
|
||||||
|
namespace anim {
|
||||||
|
enum class repeat : uchar;
|
||||||
|
} // namespace anim
|
||||||
|
|
||||||
namespace Main {
|
namespace Main {
|
||||||
class Session;
|
class Session;
|
||||||
} // namespace Main
|
} // namespace Main
|
||||||
|
@ -180,13 +184,12 @@ not_null<Ui::FlatLabel*> AddSubsectionTitle(
|
||||||
|
|
||||||
struct LottieIcon {
|
struct LottieIcon {
|
||||||
object_ptr<Ui::RpWidget> widget;
|
object_ptr<Ui::RpWidget> widget;
|
||||||
Fn<void()> animate;
|
Fn<void(anim::repeat repeat)> animate;
|
||||||
};
|
};
|
||||||
[[nodiscard]] LottieIcon CreateLottieIcon(
|
[[nodiscard]] LottieIcon CreateLottieIcon(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
Lottie::IconDescriptor &&descriptor,
|
Lottie::IconDescriptor &&descriptor,
|
||||||
style::margins padding = {},
|
style::margins padding = {});
|
||||||
bool playOnce = false);
|
|
||||||
|
|
||||||
void FillMenu(
|
void FillMenu(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
|
|
|
@ -613,11 +613,10 @@ QPointer<Ui::RpWidget> Folders::createPinnedToTop(not_null<QWidget*> parent) {
|
||||||
st::settingsFilterIconSize,
|
st::settingsFilterIconSize,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
st::settingsFilterIconPadding,
|
st::settingsFilterIconPadding);
|
||||||
true);
|
|
||||||
_showFinished.events(
|
_showFinished.events(
|
||||||
) | rpl::start_with_next([animate = std::move(icon.animate)] {
|
) | rpl::start_with_next([animate = std::move(icon.animate)] {
|
||||||
animate();
|
animate(anim::repeat::once);
|
||||||
}, verticalLayout->lifetime());
|
}, verticalLayout->lifetime());
|
||||||
verticalLayout->add(std::move(icon.widget));
|
verticalLayout->add(std::move(icon.widget));
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9d07d6a476f057c55af9392804c3e8b6246c637c
|
Subproject commit 9b6e11db62810626a56431cdc8eeb771817f6560
|
Loading…
Add table
Reference in a new issue