Added colors overriding for call settings button from mute button.

This commit is contained in:
23rd 2020-11-30 12:38:22 +03:00 committed by John Preston
parent 07359392c2
commit 5897e357bf
2 changed files with 49 additions and 1 deletions

View file

@ -37,6 +37,9 @@ constexpr auto kGlowPaddingFactor = 1.2;
constexpr auto kGlowMinScale = 0.6;
constexpr auto kGlowAlpha = 150;
constexpr auto kOverrideColorBgAlpha = 76;
constexpr auto kOverrideColorRippleAlpha = 50;
constexpr auto kSwitchStateDuration = 120;
auto MuteBlobs() -> std::array<Paint::Blobs::BlobData, 3> {
@ -111,6 +114,10 @@ bool IsConnecting(CallMuteButtonType type) {
return (type == CallMuteButtonType::Connecting);
}
bool IsInactive(CallMuteButtonType type) {
return IsConnecting(type) || (type == CallMuteButtonType::ForceMuted);
}
} // namespace
class BlobsWidget final : public RpWidget {
@ -280,7 +287,7 @@ void CallMuteButton::init() {
lifetime().make_state<CallMuteButtonType>(_state.current().type);
const auto glowColor = [=](CallMuteButtonType type) {
if (IsConnecting(type) || (type == CallMuteButtonType::ForceMuted)) {
if (IsInactive(type)) {
return st::groupCallBg->c;
}
auto c = _colors.at(type)[0];
@ -336,6 +343,8 @@ void CallMuteButton::init() {
if (radialShowProgress != _radialShowProgress.current()) {
_radialShowProgress = radialShowProgress;
}
overridesColors(previous, type, value);
};
_switchAnimation.stop();
@ -451,6 +460,37 @@ void CallMuteButton::lower() {
_blobs->lower();
}
void CallMuteButton::overridesColors(
CallMuteButtonType fromType,
CallMuteButtonType toType,
float64 progress) {
const auto toInactive = IsInactive(toType);
const auto fromInactive = IsInactive(fromType);
if (toInactive && (progress == 1)) {
_colorOverrides.fire({ std::nullopt, std::nullopt });
return;
}
auto from = _colors.at(fromType)[0];
auto to = _colors.at(toType)[0];
auto fromRipple = from;
auto toRipple = to;
if (!toInactive) {
toRipple.setAlpha(kOverrideColorRippleAlpha);
to.setAlpha(kOverrideColorBgAlpha);
}
if (!fromInactive) {
fromRipple.setAlpha(kOverrideColorRippleAlpha);
from.setAlpha(kOverrideColorBgAlpha);
}
const auto resultBg = anim::color(from, to, progress);
const auto resultRipple = anim::color(fromRipple, toRipple, progress);
_colorOverrides.fire({ resultBg, resultRipple });
}
rpl::producer<CallButtonColors> CallMuteButton::colorOverrides() const {
return _colorOverrides.events();
}
rpl::lifetime &CallMuteButton::lifetime() {
return _blobs->lifetime();
}

View file

@ -55,11 +55,17 @@ public:
void raise();
void lower();
[[nodiscard]] rpl::producer<CallButtonColors> colorOverrides() const;
[[nodiscard]] rpl::lifetime &lifetime();
private:
void init();
void contentPaint();
void overridesColors(
CallMuteButtonType fromType,
CallMuteButtonType toType,
float64 progress);
rpl::variable<CallMuteButtonState> _state;
float _level = 0.;
@ -76,6 +82,8 @@ private:
CrossLineAnimation _crossLineMuteAnimation;
Animations::Simple _switchAnimation;
rpl::event_stream<CallButtonColors> _colorOverrides;
};
} // namespace Ui