Improve lottie icon layout in group calls.

This commit is contained in:
John Preston 2024-09-03 11:50:39 +04:00
parent ab2e7f4c03
commit 4430bd0328
2 changed files with 43 additions and 21 deletions

View file

@ -82,6 +82,28 @@ constexpr auto kRadialFinishArcShift = 1200;
: type; : type;
}; };
[[nodiscard]] QSize AdjustedLottieSize(
not_null<const style::CallMuteButton*> st) {
const auto &button = st->active.button;
const auto left = (button.width - st->lottieSize.width()) / 2;
const auto size = button.width - 2 * left;
return QSize(size, size);
}
[[nodiscard]] int AdjustedBgSize(
not_null<const style::CallMuteButton*> st) {
const auto &button = st->active.button;
const auto left = (button.width - st->active.bgSize) / 2;
return button.width - 2 * left;
}
[[nodiscard]] int AdjustedBgSkip(
not_null<const style::CallMuteButton*> st) {
const auto &button = st->active.button;
const auto bgSize = AdjustedBgSize(st);
return (button.width - bgSize) / 2;
}
auto MuteBlobs() { auto MuteBlobs() {
return std::vector<Paint::Blobs::BlobData>{ return std::vector<Paint::Blobs::BlobData>{
{ {
@ -515,9 +537,12 @@ CallMuteButton::CallMuteButton(
CallMuteButtonState initial) CallMuteButtonState initial)
: _state(initial) : _state(initial)
, _st(&st) , _st(&st)
, _lottieSize(AdjustedLottieSize(_st))
, _bgSize(AdjustedBgSize(_st))
, _bgSkip(AdjustedBgSkip(_st))
, _blobs(base::make_unique_q<BlobsWidget>( , _blobs(base::make_unique_q<BlobsWidget>(
parent, parent,
_st->active.bgSize, _bgSize,
rpl::combine( rpl::combine(
PowerSaving::OnValue(PowerSaving::kCalls), PowerSaving::OnValue(PowerSaving::kCalls),
std::move(hideBlobs), std::move(hideBlobs),
@ -593,13 +618,13 @@ void CallMuteButton::refreshIcons() {
_icons[0].emplace(Lottie::IconDescriptor{ _icons[0].emplace(Lottie::IconDescriptor{
.path = u":/icons/calls/voice.lottie"_q, .path = u":/icons/calls/voice.lottie"_q,
.color = &st::groupCallIconFg, .color = &st::groupCallIconFg,
.sizeOverride = _st->lottieSize, .sizeOverride = _lottieSize,
.frame = (_iconState.index ? 0 : _iconState.frameTo), .frame = (_iconState.index ? 0 : _iconState.frameTo),
}); });
_icons[1].emplace(Lottie::IconDescriptor{ _icons[1].emplace(Lottie::IconDescriptor{
.path = u":/icons/calls/hands.lottie"_q, .path = u":/icons/calls/hands.lottie"_q,
.color = &st::groupCallIconFg, .color = &st::groupCallIconFg,
.sizeOverride = _st->lottieSize, .sizeOverride = _lottieSize,
.frame = (_iconState.index ? _iconState.frameTo : 0), .frame = (_iconState.index ? _iconState.frameTo : 0),
}); });
@ -813,7 +838,7 @@ void CallMuteButton::init() {
// Icon rect. // Icon rect.
_content->sizeValue( _content->sizeValue(
) | rpl::start_with_next([=](QSize size) { ) | rpl::start_with_next([=](QSize size) {
const auto icon = _st->lottieSize; const auto icon = _lottieSize;
_muteIconRect = QRect( _muteIconRect = QRect(
(size.width() - icon.width()) / 2, (size.width() - icon.width()) / 2,
_st->lottieTop, _st->lottieTop,
@ -858,8 +883,8 @@ void CallMuteButton::init() {
InfiniteRadialAnimation::Draw( InfiniteRadialAnimation::Draw(
p, p,
r, r,
_st->active.bgPosition, QPoint(_bgSkip, _bgSkip),
QSize(_st->active.bgSize, _st->active.bgSize), QSize(_bgSize, _bgSize),
_content->width(), _content->width(),
QPen(_radialInfo.st.color), QPen(_radialInfo.st.color),
_radialInfo.st.thickness); _radialInfo.st.thickness);
@ -870,8 +895,8 @@ void CallMuteButton::init() {
InfiniteRadialAnimation::Draw( InfiniteRadialAnimation::Draw(
p, p,
std::move(state), std::move(state),
_st->active.bgPosition, QPoint(_bgSkip, _bgSkip),
QSize(_st->active.bgSize, _st->active.bgSize), QSize(_bgSize, _bgSize),
_content->width(), _content->width(),
QPen(_radialInfo.st.color), QPen(_radialInfo.st.color),
_radialInfo.st.thickness); _radialInfo.st.thickness);
@ -1027,6 +1052,9 @@ void CallMuteButton::setStyle(const style::CallMuteButton &st) {
return; return;
} }
_st = &st; _st = &st;
_lottieSize = AdjustedLottieSize(_st);
_bgSize = AdjustedBgSize(_st);
_bgSkip = AdjustedBgSkip(_st);
const auto &button = _st->active.button; const auto &button = _st->active.button;
_content->resize(button.width, button.height); _content->resize(button.width, button.height);
_blobs->setDiameter(_st->active.bgSize); _blobs->setDiameter(_st->active.bgSize);
@ -1057,21 +1085,13 @@ rpl::producer<Qt::MouseButton> CallMuteButton::clicks() {
} }
QSize CallMuteButton::innerSize() const { QSize CallMuteButton::innerSize() const {
return innerGeometry().size(); return QSize(
} _content->width() - 2 * _bgSkip,
_content->width() - 2 * _bgSkip);
QRect CallMuteButton::innerGeometry() const {
const auto &skip = _st->active.outerRadius;
return QRect(
_content->x(),
_content->y(),
_content->width() - 2 * skip,
_content->width() - 2 * skip);
} }
void CallMuteButton::moveInner(QPoint position) { void CallMuteButton::moveInner(QPoint position) {
const auto &skip = _st->active.outerRadius; _content->move(position - QPoint(_bgSkip, _bgSkip));
_content->move(position - QPoint(skip, skip));
{ {
const auto offset = QPoint( const auto offset = QPoint(

View file

@ -73,7 +73,6 @@ public:
[[nodiscard]] rpl::producer<Qt::MouseButton> clicks(); [[nodiscard]] rpl::producer<Qt::MouseButton> clicks();
[[nodiscard]] QSize innerSize() const; [[nodiscard]] QSize innerSize() const;
[[nodiscard]] QRect innerGeometry() const;
void moveInner(QPoint position); void moveInner(QPoint position);
void shake(); void shake();
@ -165,6 +164,9 @@ private:
HandleMouseState _handleMouseState = HandleMouseState::Enabled; HandleMouseState _handleMouseState = HandleMouseState::Enabled;
not_null<const style::CallMuteButton*> _st; not_null<const style::CallMuteButton*> _st;
QSize _lottieSize;
int _bgSize = 0;
int _bgSkip = 0;
const base::unique_qptr<BlobsWidget> _blobs; const base::unique_qptr<BlobsWidget> _blobs;
const base::unique_qptr<AbstractButton> _content; const base::unique_qptr<AbstractButton> _content;