Make IV internal links bg semi-transparent.

This commit is contained in:
John Preston 2024-07-31 13:05:54 +02:00
parent bb6c94ef4f
commit 8959679b3c
3 changed files with 64 additions and 15 deletions

View file

@ -65,7 +65,7 @@ namespace {
{ "box-divider-bg", &st::boxDividerBg },
{ "box-divider-fg", &st::boxDividerFg },
{ "light-button-fg", &st::lightButtonFg },
{ "light-button-bg-over", &st::lightButtonBgOver },
//{ "light-button-bg-over", &st::lightButtonBgOver },
{ "menu-icon-fg", &st::menuIconFg },
{ "menu-icon-fg-over", &st::menuIconFgOver },
{ "menu-bg", &st::menuBg },
@ -82,7 +82,12 @@ namespace {
static const auto phrases = base::flat_map<QByteArray, tr::phrase<>>{
{ "iv-join-channel", tr::lng_iv_join_channel },
};
return Ui::ComputeStyles(map, phrases);
return Ui::ComputeStyles(map, phrases)
+ ';'
+ Ui::ComputeSemiTransparentOverStyle(
"light-button-bg-over",
st::lightButtonBgOver,
st::windowBg);
}
[[nodiscard]] QByteArray WrapPage(const Prepared &page) {

View file

@ -10,24 +10,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h"
namespace Ui {
namespace {
[[nodiscard]] QByteArray ComputeStyles(
[[nodiscard]] QByteArray Serialize(const QColor &qt) {
if (qt.alpha() == 255) {
return '#'
+ QByteArray::number(qt.red(), 16).right(2)
+ QByteArray::number(qt.green(), 16).right(2)
+ QByteArray::number(qt.blue(), 16).right(2);
}
return "rgba("
+ QByteArray::number(qt.red()) + ","
+ QByteArray::number(qt.green()) + ","
+ QByteArray::number(qt.blue()) + ","
+ QByteArray::number(qt.alpha() / 255.) + ")";
}
} // namespace
QByteArray ComputeStyles(
const base::flat_map<QByteArray, const style::color*> &colors,
const base::flat_map<QByteArray, tr::phrase<>> &phrases,
bool nightTheme) {
static const auto serialize = [](const style::color *color) {
const auto qt = (*color)->c;
if (qt.alpha() == 255) {
return '#'
+ QByteArray::number(qt.red(), 16).right(2)
+ QByteArray::number(qt.green(), 16).right(2)
+ QByteArray::number(qt.blue(), 16).right(2);
}
return "rgba("
+ QByteArray::number(qt.red()) + ","
+ QByteArray::number(qt.green()) + ","
+ QByteArray::number(qt.blue()) + ","
+ QByteArray::number(qt.alpha() / 255.) + ")";
return Serialize((*color)->c);
};
static const auto escape = [](tr::phrase<> phrase) {
const auto text = phrase(tr::now);
@ -63,6 +69,40 @@ namespace Ui {
return result;
}
QByteArray ComputeSemiTransparentOverStyle(
const QByteArray &name,
const style::color &over,
const style::color &bg) {
const auto result = [&](const QColor &c) {
return "--td-"_q + name + ':' + Serialize(c) + ';';
};
if (over->c.alpha() < 255) {
return result(over->c);
}
// The most transparent color that will still give the same result.
const auto r0 = bg->c.red();
const auto g0 = bg->c.green();
const auto b0 = bg->c.blue();
const auto r1 = over->c.red();
const auto g1 = over->c.green();
const auto b1 = over->c.blue();
const auto mina = [](int c0, int c1) {
return (c0 == c1)
? 0
: (c0 > c1)
? (((c0 - c1) * 255) / c0)
: (((c1 - c0) * 255) / (255 - c0));
};
const auto rmina = mina(r0, r1);
const auto gmina = mina(g0, g1);
const auto bmina = mina(b0, b1);
const auto a = std::max({ rmina, gmina, bmina });
const auto r = (r1 * 255 - r0 * (255 - a)) / a;
const auto g = (g1 * 255 - g0 * (255 - a)) / a;
const auto b = (b1 * 255 - b0 * (255 - a)) / a;
return result(QColor(r, g, b, a));
}
QByteArray EscapeForAttribute(QByteArray value) {
return value
.replace('&', "&amp;")

View file

@ -20,6 +20,10 @@ namespace Ui {
const base::flat_map<QByteArray, const style::color*> &colors,
const base::flat_map<QByteArray, tr::phrase<>> &phrases,
bool nightTheme = false);
[[nodiscard]] QByteArray ComputeSemiTransparentOverStyle(
const QByteArray &name,
const style::color &over,
const style::color &bg);
[[nodiscard]] QByteArray EscapeForAttribute(QByteArray value);
[[nodiscard]] QByteArray EscapeForScriptString(QByteArray value);