mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
feat: add fade animation for icon picker
This commit is contained in:
parent
a48534b51a
commit
299833ca3d
3 changed files with 36 additions and 13 deletions
|
@ -33,18 +33,19 @@ const QVector<QString> icons{
|
|||
|
||||
const auto rows = static_cast<int>(icons.size()) / 4 + std::min(1, static_cast<int>(icons.size()) % 4);
|
||||
|
||||
void drawIcon(QPainter &p, const QImage &icon, int xOffset, int yOffset, bool selected) {
|
||||
void drawIcon(QPainter &p, const QImage &icon, int xOffset, int yOffset, float strokeOpacity) {
|
||||
xOffset += st::cpPadding;
|
||||
|
||||
if (selected) {
|
||||
p.save();
|
||||
p.setPen(QPen(st::iconPreviewStroke, st::cpPenSize));
|
||||
p.drawEllipse(xOffset + st::cpSelectedPadding,
|
||||
yOffset + st::cpSelectedPadding,
|
||||
st::cpIconSize + st::cpSelectedPadding * 2,
|
||||
st::cpIconSize + st::cpSelectedPadding * 2);
|
||||
p.restore();
|
||||
}
|
||||
// stroke
|
||||
p.save();
|
||||
p.setPen(QPen(st::iconPreviewStroke, st::cpPenSize));
|
||||
p.setOpacity(strokeOpacity);
|
||||
p.drawEllipse(xOffset + st::cpSelectedPadding,
|
||||
yOffset + st::cpSelectedPadding,
|
||||
st::cpIconSize + st::cpSelectedPadding * 2,
|
||||
st::cpIconSize + st::cpSelectedPadding * 2);
|
||||
p.restore();
|
||||
// /stroke
|
||||
|
||||
auto rect = QRect(xOffset + st::cpImagePadding, yOffset + st::cpImagePadding, st::cpIconSize, st::cpIconSize);
|
||||
p.drawImage(rect, icon);
|
||||
|
@ -81,11 +82,19 @@ void IconPicker::paintEvent(QPaintEvent *e) {
|
|||
const auto &iconName = icons[idx];
|
||||
auto icon = AyuAssets::loadPreview(iconName)
|
||||
.scaled(st::cpIconSize, st::cpIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
auto opacity = 0.0f;
|
||||
if (iconName == wasSelected) {
|
||||
opacity = 1.0f - animation.value(1.0f);
|
||||
} else if (iconName == AyuAssets::currentAppLogoName()) {
|
||||
opacity = wasSelected.isEmpty() ? 1.0f : animation.value(1.0f);
|
||||
}
|
||||
|
||||
drawIcon(p,
|
||||
icon,
|
||||
(st::cpIconSize + st::cpSpacingX) * i + offset,
|
||||
row * (st::cpIconSize + st::cpSpacingY),
|
||||
AyuAssets::currentAppLogoName() == iconName);
|
||||
opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +115,17 @@ void IconPicker::mousePressEvent(QMouseEvent *e) {
|
|||
&& e->pos().y() <= yOffset + st::cpIconSize) {
|
||||
const auto &iconName = icons[idx];
|
||||
if (settings->appIcon != iconName) {
|
||||
wasSelected = settings->appIcon;
|
||||
animation.start(
|
||||
[=]
|
||||
{
|
||||
update();
|
||||
},
|
||||
0.0,
|
||||
1.0,
|
||||
200,
|
||||
anim::easeOutCubic);
|
||||
|
||||
settings->set_appIcon(iconName);
|
||||
changed = true;
|
||||
break;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/effects/animations.h"
|
||||
|
||||
class IconPicker : public Ui::RpWidget
|
||||
{
|
||||
|
@ -16,4 +17,7 @@ public:
|
|||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
|
||||
Ui::Animations::Simple animation;
|
||||
QString wasSelected;
|
||||
};
|
||||
|
|
|
@ -1008,7 +1008,7 @@ void SetupRecentStickersLimitSlider(not_null<Ui::VerticalLayout*> container) {
|
|||
st::autoDownloadLimitSlider,
|
||||
st::settingsScaleLabel,
|
||||
0,
|
||||
st::settingsScaleLabel.style.font->width("30%"));
|
||||
st::settingsScaleLabel.style.font->width("8%%"));
|
||||
container->add(std::move(recentStickersLimitSlider.widget), st::recentStickersLimitPadding);
|
||||
const auto slider = recentStickersLimitSlider.slider;
|
||||
const auto label = recentStickersLimitSlider.label;
|
||||
|
@ -1331,7 +1331,6 @@ void SetupAyuGramSettings(not_null<Ui::VerticalLayout*> container,
|
|||
AddSkip(container);
|
||||
SetupSendConfirmations(container);
|
||||
AddSkip(container);
|
||||
AddDivider(container);
|
||||
|
||||
AddDividerText(container, tr::ayu_SettingsWatermark());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue