mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improve bottom label color in mini apps.
This commit is contained in:
parent
5c62ba0835
commit
1438046dd4
2 changed files with 44 additions and 5 deletions
|
@ -783,6 +783,8 @@ void Panel::createWebviewBottom() {
|
||||||
_webviewBottom.get(),
|
_webviewBottom.get(),
|
||||||
_bottomText.value(),
|
_bottomText.value(),
|
||||||
st::paymentsWebviewBottom);
|
st::paymentsWebviewBottom);
|
||||||
|
_webviewBottomLabel = label;
|
||||||
|
|
||||||
const auto height = padding.top()
|
const auto height = padding.top()
|
||||||
+ label->heightNoMargins()
|
+ label->heightNoMargins()
|
||||||
+ padding.bottom();
|
+ padding.bottom();
|
||||||
|
@ -840,6 +842,7 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_webviewBottom.get() == bottom) {
|
if (_webviewBottom.get() == bottom) {
|
||||||
|
_webviewBottomLabel = nullptr;
|
||||||
_webviewBottom = nullptr;
|
_webviewBottom = nullptr;
|
||||||
_secondaryButton = nullptr;
|
_secondaryButton = nullptr;
|
||||||
_mainButton = nullptr;
|
_mainButton = nullptr;
|
||||||
|
@ -1596,20 +1599,53 @@ void Panel::processHeaderColor(const QJsonObject &args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Panel::overrideBodyColor(std::optional<QColor> color) {
|
||||||
|
_widget->overrideBodyColor(color);
|
||||||
|
const auto raw = _webviewBottomLabel.data();
|
||||||
|
if (!raw) {
|
||||||
|
return;
|
||||||
|
} else if (!color) {
|
||||||
|
raw->setTextColorOverride(std::nullopt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto set = [](const style::color &color, QColor value) {
|
||||||
|
color.set(
|
||||||
|
uchar(value.red()),
|
||||||
|
uchar(value.green()),
|
||||||
|
uchar(value.blue()),
|
||||||
|
uchar(value.alpha()));
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto contrast = 2.5;
|
||||||
|
const auto luminance = 0.2126 * color->redF()
|
||||||
|
+ 0.7152 * color->greenF()
|
||||||
|
+ 0.0722 * color->blueF();
|
||||||
|
const auto textColor = (luminance > 0.5)
|
||||||
|
? QColor(0, 0, 0)
|
||||||
|
: QColor(255, 255, 255);
|
||||||
|
const auto textLuminance = (luminance > 0.5) ? 0 : 1;
|
||||||
|
const auto adaptiveOpacity = (luminance - textLuminance + contrast)
|
||||||
|
/ contrast;
|
||||||
|
const auto opacity = std::clamp(adaptiveOpacity, 0.5, 0.64);
|
||||||
|
auto buttonColor = textColor;
|
||||||
|
buttonColor.setAlphaF(opacity);
|
||||||
|
raw->setTextColorOverride(buttonColor);
|
||||||
|
}
|
||||||
|
|
||||||
void Panel::processBackgroundColor(const QJsonObject &args) {
|
void Panel::processBackgroundColor(const QJsonObject &args) {
|
||||||
_bodyColorReceived = true;
|
_bodyColorReceived = true;
|
||||||
if (const auto color = ParseColor(args["color"].toString())) {
|
if (const auto color = ParseColor(args["color"].toString())) {
|
||||||
_widget->overrideBodyColor(color);
|
overrideBodyColor(*color);
|
||||||
_bodyColorLifetime.destroy();
|
_bodyColorLifetime.destroy();
|
||||||
} else if (const auto color = LookupNamedColor(
|
} else if (const auto color = LookupNamedColor(
|
||||||
args["color_key"].toString())) {
|
args["color_key"].toString())) {
|
||||||
_widget->overrideBodyColor((*color)->c);
|
overrideBodyColor((*color)->c);
|
||||||
_bodyColorLifetime = style::PaletteChanged(
|
_bodyColorLifetime = style::PaletteChanged(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
_widget->overrideBodyColor((*color)->c);
|
overrideBodyColor((*color)->c);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
_widget->overrideBodyColor(std::nullopt);
|
overrideBodyColor(std::nullopt);
|
||||||
_bodyColorLifetime.destroy();
|
_bodyColorLifetime.destroy();
|
||||||
}
|
}
|
||||||
if (const auto raw = _bottomButtonsBg.get()) {
|
if (const auto raw = _bottomButtonsBg.get()) {
|
||||||
|
@ -1923,7 +1959,7 @@ void Panel::updateColorOverrides(const Webview::ThemeParams ¶ms) {
|
||||||
_widget->overrideTitleColor(params.titleBg);
|
_widget->overrideTitleColor(params.titleBg);
|
||||||
}
|
}
|
||||||
if (!_bodyColorReceived && params.bodyBg.alpha() == 255) {
|
if (!_bodyColorReceived && params.bodyBg.alpha() == 255) {
|
||||||
_widget->overrideBodyColor(params.bodyBg);
|
overrideBodyColor(params.bodyBg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ class QJsonObject;
|
||||||
class QJsonValue;
|
class QJsonValue;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
class FlatLabel;
|
||||||
class BoxContent;
|
class BoxContent;
|
||||||
class RpWidget;
|
class RpWidget;
|
||||||
class SeparatePanel;
|
class SeparatePanel;
|
||||||
|
@ -196,6 +197,7 @@ private:
|
||||||
void sendFullScreen();
|
void sendFullScreen();
|
||||||
|
|
||||||
void updateColorOverrides(const Webview::ThemeParams ¶ms);
|
void updateColorOverrides(const Webview::ThemeParams ¶ms);
|
||||||
|
void overrideBodyColor(std::optional<QColor> color);
|
||||||
|
|
||||||
using EventData = std::variant<QString, QJsonObject>;
|
using EventData = std::variant<QString, QJsonObject>;
|
||||||
void postEvent(const QString &event);
|
void postEvent(const QString &event);
|
||||||
|
@ -216,6 +218,7 @@ private:
|
||||||
std::unique_ptr<SeparatePanel> _widget;
|
std::unique_ptr<SeparatePanel> _widget;
|
||||||
std::unique_ptr<WebviewWithLifetime> _webview;
|
std::unique_ptr<WebviewWithLifetime> _webview;
|
||||||
std::unique_ptr<RpWidget> _webviewBottom;
|
std::unique_ptr<RpWidget> _webviewBottom;
|
||||||
|
QPointer<FlatLabel> _webviewBottomLabel;
|
||||||
rpl::variable<QString> _bottomText;
|
rpl::variable<QString> _bottomText;
|
||||||
QPointer<RpWidget> _webviewParent;
|
QPointer<RpWidget> _webviewParent;
|
||||||
std::unique_ptr<RpWidget> _bottomButtonsBg;
|
std::unique_ptr<RpWidget> _bottomButtonsBg;
|
||||||
|
|
Loading…
Add table
Reference in a new issue