mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Adjust outgoing bubble text and icon colors.
This commit is contained in:
parent
c318f57fc0
commit
4273167aa2
11 changed files with 155 additions and 36 deletions
|
@ -421,8 +421,6 @@ void CloudThemes::parseChatThemes(const QVector<MTPChatTheme> &list) {
|
||||||
.light = CloudTheme::Parse(_session, data.vtheme(), true),
|
.light = CloudTheme::Parse(_session, data.vtheme(), true),
|
||||||
.dark = CloudTheme::Parse(_session, data.vdark_theme(), true),
|
.dark = CloudTheme::Parse(_session, data.vdark_theme(), true),
|
||||||
});
|
});
|
||||||
AssertIsDebug();
|
|
||||||
std::swap(_chatThemes.back().light, _chatThemes.back().dark);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,11 +180,6 @@ const auto kPsaAboutPrefix = "cloud_lng_about_psa_";
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
struct HistoryWidget::CustomStyles {
|
|
||||||
style::TwoIconButton historyToDown;
|
|
||||||
style::TwoIconButton historyUnreadMentions;
|
|
||||||
};
|
|
||||||
|
|
||||||
HistoryWidget::HistoryWidget(
|
HistoryWidget::HistoryWidget(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
not_null<Window::SessionController*> controller)
|
not_null<Window::SessionController*> controller)
|
||||||
|
@ -192,17 +187,23 @@ HistoryWidget::HistoryWidget(
|
||||||
parent,
|
parent,
|
||||||
controller,
|
controller,
|
||||||
ActivePeerValue(controller))
|
ActivePeerValue(controller))
|
||||||
, _styles(MakeCustomStyles(controller))
|
|
||||||
, _api(&controller->session().mtp())
|
, _api(&controller->session().mtp())
|
||||||
, _updateEditTimeLeftDisplay([=] { updateField(); })
|
, _updateEditTimeLeftDisplay([=] { updateField(); })
|
||||||
, _fieldBarCancel(this, st::historyReplyCancel)
|
, _fieldBarCancel(this, st::historyReplyCancel)
|
||||||
, _previewTimer([=] { requestPreview(); })
|
, _previewTimer([=] { requestPreview(); })
|
||||||
, _previewState(Data::PreviewState::Allowed)
|
, _previewState(Data::PreviewState::Allowed)
|
||||||
, _topBar(this, controller)
|
, _topBar(this, controller)
|
||||||
, _scroll(this, st::historyScroll, false)
|
, _scroll(
|
||||||
|
this,
|
||||||
|
controller->chatStyle()->value(lifetime(), st::historyScroll),
|
||||||
|
false)
|
||||||
, _updateHistoryItems([=] { updateHistoryItemsByTimer(); })
|
, _updateHistoryItems([=] { updateHistoryItemsByTimer(); })
|
||||||
, _historyDown(_scroll, _styles->historyToDown)
|
, _historyDown(
|
||||||
, _unreadMentions(_scroll, _styles->historyUnreadMentions)
|
_scroll,
|
||||||
|
controller->chatStyle()->value(lifetime(), st::historyToDown))
|
||||||
|
, _unreadMentions(
|
||||||
|
_scroll,
|
||||||
|
controller->chatStyle()->value(lifetime(), st::historyUnreadMentions))
|
||||||
, _fieldAutocomplete(this, controller)
|
, _fieldAutocomplete(this, controller)
|
||||||
, _supportAutocomplete(session().supportMode()
|
, _supportAutocomplete(session().supportMode()
|
||||||
? object_ptr<Support::Autocomplete>(this, &session())
|
? object_ptr<Support::Autocomplete>(this, &session())
|
||||||
|
@ -323,7 +324,7 @@ HistoryWidget::HistoryWidget(
|
||||||
_scroll->hide();
|
_scroll->hide();
|
||||||
_kbScroll->hide();
|
_kbScroll->hide();
|
||||||
|
|
||||||
style::PaletteChanged(
|
controller->chatStyle()->paletteChanged(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
_scroll->updateBars();
|
_scroll->updateBars();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
@ -3991,17 +3992,6 @@ bool HistoryWidget::kbWasHidden() const {
|
||||||
return _history && (_keyboard->forMsgId() == FullMsgId(_history->channelId(), _history->lastKeyboardHiddenId));
|
return _history && (_keyboard->forMsgId() == FullMsgId(_history->channelId(), _history->lastKeyboardHiddenId));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto HistoryWidget::MakeCustomStyles(
|
|
||||||
not_null<Window::SessionController*> controller)
|
|
||||||
-> std::unique_ptr<CustomStyles> {
|
|
||||||
const auto st = controller->chatStyle();
|
|
||||||
|
|
||||||
auto result = std::make_unique<CustomStyles>();
|
|
||||||
result->historyToDown = st->value(st::historyToDown);
|
|
||||||
result->historyUnreadMentions = st->value(st::historyUnreadMentions);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HistoryWidget::toggleKeyboard(bool manual) {
|
void HistoryWidget::toggleKeyboard(bool manual) {
|
||||||
auto fieldEnabled = canWriteMessage() && !_a_show.animating();
|
auto fieldEnabled = canWriteMessage() && !_a_show.animating();
|
||||||
if (_kbShown || _kbReplyTo) {
|
if (_kbShown || _kbReplyTo) {
|
||||||
|
|
|
@ -300,7 +300,6 @@ protected:
|
||||||
private:
|
private:
|
||||||
using TabbedPanel = ChatHelpers::TabbedPanel;
|
using TabbedPanel = ChatHelpers::TabbedPanel;
|
||||||
using TabbedSelector = ChatHelpers::TabbedSelector;
|
using TabbedSelector = ChatHelpers::TabbedSelector;
|
||||||
struct CustomStyles;
|
|
||||||
enum ScrollChangeType {
|
enum ScrollChangeType {
|
||||||
ScrollChangeNone,
|
ScrollChangeNone,
|
||||||
|
|
||||||
|
@ -604,11 +603,6 @@ private:
|
||||||
|
|
||||||
bool kbWasHidden() const;
|
bool kbWasHidden() const;
|
||||||
|
|
||||||
[[nodiscard]] static std::unique_ptr<CustomStyles> MakeCustomStyles(
|
|
||||||
not_null<Window::SessionController*> controller);
|
|
||||||
|
|
||||||
const std::unique_ptr<CustomStyles> _styles;
|
|
||||||
|
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
MsgId _replyToId = 0;
|
MsgId _replyToId = 0;
|
||||||
Ui::Text::String _replyToName;
|
Ui::Text::String _replyToName;
|
||||||
|
|
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/shadow.h"
|
#include "ui/widgets/shadow.h"
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
#include "ui/item_text_options.h"
|
#include "ui/item_text_options.h"
|
||||||
|
#include "ui/chat/chat_style.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
#include "ui/text/format_values.h"
|
#include "ui/text/format_values.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
|
@ -95,12 +96,22 @@ PinnedWidget::PinnedWidget(
|
||||||
, _migratedPeer(_history->peer->migrateFrom())
|
, _migratedPeer(_history->peer->migrateFrom())
|
||||||
, _topBar(this, controller)
|
, _topBar(this, controller)
|
||||||
, _topBarShadow(this)
|
, _topBarShadow(this)
|
||||||
, _scroll(std::make_unique<Ui::ScrollArea>(this, st::historyScroll, false))
|
, _scroll(std::make_unique<Ui::ScrollArea>(
|
||||||
|
this,
|
||||||
|
controller->chatStyle()->value(lifetime(), st::historyScroll),
|
||||||
|
false))
|
||||||
, _clearButton(std::make_unique<Ui::FlatButton>(
|
, _clearButton(std::make_unique<Ui::FlatButton>(
|
||||||
this,
|
this,
|
||||||
QString(),
|
QString(),
|
||||||
st::historyComposeButton))
|
st::historyComposeButton))
|
||||||
, _scrollDown(_scroll.get(), st::historyToDown) {
|
, _scrollDown(
|
||||||
|
_scroll.get(),
|
||||||
|
controller->chatStyle()->value(lifetime(), st::historyToDown)) {
|
||||||
|
controller->chatStyle()->paletteChanged(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
_scroll->updateBars();
|
||||||
|
}, _scroll->lifetime());
|
||||||
|
|
||||||
Window::ChatThemeValueFromPeer(
|
Window::ChatThemeValueFromPeer(
|
||||||
controller,
|
controller,
|
||||||
history->peer
|
history->peer
|
||||||
|
|
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "chat_helpers/send_context_menu.h" // SendMenu::Type.
|
#include "chat_helpers/send_context_menu.h" // SendMenu::Type.
|
||||||
#include "ui/chat/pinned_bar.h"
|
#include "ui/chat/pinned_bar.h"
|
||||||
|
#include "ui/chat/chat_style.h"
|
||||||
#include "ui/widgets/scroll_area.h"
|
#include "ui/widgets/scroll_area.h"
|
||||||
#include "ui/widgets/shadow.h"
|
#include "ui/widgets/shadow.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
|
@ -162,9 +163,19 @@ RepliesWidget::RepliesWidget(
|
||||||
controller,
|
controller,
|
||||||
ComposeControls::Mode::Normal,
|
ComposeControls::Mode::Normal,
|
||||||
SendMenu::Type::SilentOnly))
|
SendMenu::Type::SilentOnly))
|
||||||
, _scroll(std::make_unique<Ui::ScrollArea>(this, st::historyScroll, false))
|
, _scroll(std::make_unique<Ui::ScrollArea>(
|
||||||
, _scrollDown(_scroll.get(), st::historyToDown)
|
this,
|
||||||
|
controller->chatStyle()->value(lifetime(), st::historyScroll),
|
||||||
|
false))
|
||||||
|
, _scrollDown(
|
||||||
|
_scroll.get(),
|
||||||
|
controller->chatStyle()->value(lifetime(), st::historyToDown))
|
||||||
, _readRequestTimer([=] { sendReadTillRequest(); }) {
|
, _readRequestTimer([=] { sendReadTillRequest(); }) {
|
||||||
|
controller->chatStyle()->paletteChanged(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
_scroll->updateBars();
|
||||||
|
}, _scroll->lifetime());
|
||||||
|
|
||||||
Window::ChatThemeValueFromPeer(
|
Window::ChatThemeValueFromPeer(
|
||||||
controller,
|
controller,
|
||||||
history->peer
|
history->peer
|
||||||
|
|
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
#include "ui/item_text_options.h"
|
#include "ui/item_text_options.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
|
#include "ui/chat/chat_style.h"
|
||||||
#include "ui/chat/attach/attach_prepare.h"
|
#include "ui/chat/attach/attach_prepare.h"
|
||||||
#include "ui/chat/attach/attach_send_files_way.h"
|
#include "ui/chat/attach/attach_send_files_way.h"
|
||||||
#include "ui/special_buttons.h"
|
#include "ui/special_buttons.h"
|
||||||
|
@ -91,7 +92,10 @@ ScheduledWidget::ScheduledWidget(
|
||||||
not_null<History*> history)
|
not_null<History*> history)
|
||||||
: Window::SectionWidget(parent, controller, history->peer)
|
: Window::SectionWidget(parent, controller, history->peer)
|
||||||
, _history(history)
|
, _history(history)
|
||||||
, _scroll(this, st::historyScroll, false)
|
, _scroll(
|
||||||
|
this,
|
||||||
|
controller->chatStyle()->value(lifetime(), st::historyScroll),
|
||||||
|
false)
|
||||||
, _topBar(this, controller)
|
, _topBar(this, controller)
|
||||||
, _topBarShadow(this)
|
, _topBarShadow(this)
|
||||||
, _composeControls(std::make_unique<ComposeControls>(
|
, _composeControls(std::make_unique<ComposeControls>(
|
||||||
|
@ -99,7 +103,14 @@ ScheduledWidget::ScheduledWidget(
|
||||||
controller,
|
controller,
|
||||||
ComposeControls::Mode::Scheduled,
|
ComposeControls::Mode::Scheduled,
|
||||||
SendMenu::Type::Disabled))
|
SendMenu::Type::Disabled))
|
||||||
, _scrollDown(_scroll, st::historyToDown) {
|
, _scrollDown(
|
||||||
|
_scroll,
|
||||||
|
controller->chatStyle()->value(lifetime(), st::historyToDown)) {
|
||||||
|
controller->chatStyle()->paletteChanged(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
_scroll->updateBars();
|
||||||
|
}, _scroll->lifetime());
|
||||||
|
|
||||||
Window::ChatThemeValueFromPeer(
|
Window::ChatThemeValueFromPeer(
|
||||||
controller,
|
controller,
|
||||||
history->peer
|
history->peer
|
||||||
|
|
|
@ -472,6 +472,8 @@ void ChatStyle::assignPalette(not_null<const style::palette*> palette) {
|
||||||
_msgBotKbOverBgAddCorners = {};
|
_msgBotKbOverBgAddCorners = {};
|
||||||
_msgSelectOverlayCornersSmall = {};
|
_msgSelectOverlayCornersSmall = {};
|
||||||
_msgSelectOverlayCornersLarge = {};
|
_msgSelectOverlayCornersLarge = {};
|
||||||
|
|
||||||
|
_paletteChanged.fire({});
|
||||||
}
|
}
|
||||||
|
|
||||||
const CornersPixmaps &ChatStyle::serviceBgCornersNormal() const {
|
const CornersPixmaps &ChatStyle::serviceBgCornersNormal() const {
|
||||||
|
@ -616,6 +618,17 @@ void ChatStyle::make(
|
||||||
make(my.ripple.color, original.ripple.color);
|
make(my.ripple.color, original.ripple.color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatStyle::make(
|
||||||
|
style::ScrollArea &my,
|
||||||
|
const style::ScrollArea &original) const {
|
||||||
|
my = original;
|
||||||
|
make(my.bg, original.bg);
|
||||||
|
make(my.bgOver, original.bgOver);
|
||||||
|
make(my.barBg, original.barBg);
|
||||||
|
make(my.barBgOver, original.barBgOver);
|
||||||
|
make(my.shColor, original.shColor);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
void ChatStyle::make(
|
void ChatStyle::make(
|
||||||
Type MessageStyle::*my,
|
Type MessageStyle::*my,
|
||||||
|
|
|
@ -15,6 +15,7 @@ enum class ImageRoundRadius;
|
||||||
|
|
||||||
namespace style {
|
namespace style {
|
||||||
struct TwoIconButton;
|
struct TwoIconButton;
|
||||||
|
struct ScrollArea;
|
||||||
} // namespace style
|
} // namespace style
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
@ -138,6 +139,10 @@ public:
|
||||||
|
|
||||||
void apply(not_null<ChatTheme*> theme);
|
void apply(not_null<ChatTheme*> theme);
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<> paletteChanged() const {
|
||||||
|
return _paletteChanged.events();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
[[nodiscard]] Type value(const Type &original) const {
|
[[nodiscard]] Type value(const Type &original) const {
|
||||||
auto my = Type();
|
auto my = Type();
|
||||||
|
@ -145,6 +150,15 @@ public:
|
||||||
return my;
|
return my;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
|
[[nodiscard]] const Type &value(
|
||||||
|
rpl::lifetime &parentLifetime,
|
||||||
|
const Type &original) const {
|
||||||
|
const auto my = parentLifetime.make_state<Type>();
|
||||||
|
make(*my, original);
|
||||||
|
return *my;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] const CornersPixmaps &serviceBgCornersNormal() const;
|
[[nodiscard]] const CornersPixmaps &serviceBgCornersNormal() const;
|
||||||
[[nodiscard]] const CornersPixmaps &serviceBgCornersInverted() const;
|
[[nodiscard]] const CornersPixmaps &serviceBgCornersInverted() const;
|
||||||
|
|
||||||
|
@ -241,6 +255,9 @@ private:
|
||||||
void make(
|
void make(
|
||||||
style::TwoIconButton &my,
|
style::TwoIconButton &my,
|
||||||
const style::TwoIconButton &original) const;
|
const style::TwoIconButton &original) const;
|
||||||
|
void make(
|
||||||
|
style::ScrollArea &my,
|
||||||
|
const style::ScrollArea &original) const;
|
||||||
|
|
||||||
[[nodiscard]] MessageStyle &messageStyleRaw(
|
[[nodiscard]] MessageStyle &messageStyleRaw(
|
||||||
bool outbg,
|
bool outbg,
|
||||||
|
@ -303,6 +320,8 @@ private:
|
||||||
style::icon _historyPollChoiceRight = { Qt::Uninitialized };
|
style::icon _historyPollChoiceRight = { Qt::Uninitialized };
|
||||||
style::icon _historyPollChoiceWrong = { Qt::Uninitialized };
|
style::icon _historyPollChoiceWrong = { Qt::Uninitialized };
|
||||||
|
|
||||||
|
rpl::event_stream<> _paletteChanged;
|
||||||
|
|
||||||
rpl::lifetime _defaultPaletteChangeLifetime;
|
rpl::lifetime _defaultPaletteChangeLifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,6 +25,8 @@ constexpr auto kCacheBackgroundFastTimeout = crl::time(200);
|
||||||
constexpr auto kBackgroundFadeDuration = crl::time(200);
|
constexpr auto kBackgroundFadeDuration = crl::time(200);
|
||||||
constexpr auto kMinimumTiledSize = 512;
|
constexpr auto kMinimumTiledSize = 512;
|
||||||
constexpr auto kMaxSize = 2960;
|
constexpr auto kMaxSize = 2960;
|
||||||
|
constexpr auto kMaxContrastValue = 21.;
|
||||||
|
constexpr auto kMinAcceptableContrast = 1.14;// 4.5;
|
||||||
|
|
||||||
[[nodiscard]] QColor DefaultBackgroundColor() {
|
[[nodiscard]] QColor DefaultBackgroundColor() {
|
||||||
return QColor(213, 223, 233);
|
return QColor(213, 223, 233);
|
||||||
|
@ -133,6 +135,25 @@ constexpr auto kMaxSize = 2960;
|
||||||
return Images::GenerateLinearGradient(QSize(kSize, kSize), data.colors);
|
return Images::GenerateLinearGradient(QSize(kSize, kSize), data.colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/9733420
|
||||||
|
[[nodiscard]] float64 CountContrast(const QColor &a, const QColor &b) {
|
||||||
|
const auto luminance = [](const QColor &c) {
|
||||||
|
const auto map = [](double value) {
|
||||||
|
return (value <= 0.03928)
|
||||||
|
? (value / 12.92)
|
||||||
|
: std::pow((value + 0.055) / 1.055, 2.4);
|
||||||
|
};
|
||||||
|
return map(c.redF()) * 0.2126
|
||||||
|
+ map(c.greenF()) * 0.7152
|
||||||
|
+ map(c.blueF()) * 0.0722;
|
||||||
|
};
|
||||||
|
const auto luminance1 = luminance(a);
|
||||||
|
const auto luminance2 = luminance(b);
|
||||||
|
const auto brightest = std::max(luminance1, luminance2);
|
||||||
|
const auto darkest = std::min(luminance1, luminance2);
|
||||||
|
return (brightest + 0.05) / (darkest + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
bool operator==(const ChatThemeBackground &a, const ChatThemeBackground &b) {
|
bool operator==(const ChatThemeBackground &a, const ChatThemeBackground &b) {
|
||||||
|
@ -201,7 +222,7 @@ void ChatTheme::adjustPalette(const ChatThemeDescriptor &descriptor) {
|
||||||
}
|
}
|
||||||
const auto bubblesAccent = descriptor.bubblesData.accent
|
const auto bubblesAccent = descriptor.bubblesData.accent
|
||||||
? descriptor.bubblesData.accent
|
? descriptor.bubblesData.accent
|
||||||
: !descriptor.bubblesData.colors.empty()
|
: (!descriptor.bubblesData.colors.empty())
|
||||||
? ThemeAdjustedColor(
|
? ThemeAdjustedColor(
|
||||||
p.msgOutReplyBarColor()->c,
|
p.msgOutReplyBarColor()->c,
|
||||||
CountAverageColor(descriptor.bubblesData.colors))
|
CountAverageColor(descriptor.bubblesData.colors))
|
||||||
|
@ -230,6 +251,55 @@ void ChatTheme::adjustPalette(const ChatThemeDescriptor &descriptor) {
|
||||||
adjust(p.historyCallArrowOutFg(), by);
|
adjust(p.historyCallArrowOutFg(), by);
|
||||||
adjust(p.historyFileOutIconFg(), by);
|
adjust(p.historyFileOutIconFg(), by);
|
||||||
}
|
}
|
||||||
|
auto outBgColors = descriptor.bubblesData.colors;
|
||||||
|
if (outBgColors.empty()) {
|
||||||
|
outBgColors.push_back(p.msgOutBg()->c);
|
||||||
|
}
|
||||||
|
const auto colors = {
|
||||||
|
p.msgOutServiceFg(),
|
||||||
|
p.msgOutDateFg(),
|
||||||
|
p.msgFileThumbLinkOutFg(),
|
||||||
|
p.msgFileOutBg(),
|
||||||
|
p.msgOutReplyBarColor(),
|
||||||
|
p.msgWaveformOutActive(),
|
||||||
|
p.historyTextOutFg(),
|
||||||
|
p.mediaOutFg(),
|
||||||
|
p.historyLinkOutFg(),
|
||||||
|
p.msgOutMonoFg(),
|
||||||
|
p.historyOutIconFg(),
|
||||||
|
p.historyCallArrowOutFg(),
|
||||||
|
};
|
||||||
|
const auto minimal = [&](const QColor &with) {
|
||||||
|
auto result = kMaxContrastValue;
|
||||||
|
for (const auto &color : colors) {
|
||||||
|
result = std::min(result, CountContrast(color->c, with));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
const auto withBg = [&](auto &&count) {
|
||||||
|
auto result = kMaxContrastValue;
|
||||||
|
for (const auto &bg : outBgColors) {
|
||||||
|
result = std::min(result, count(bg));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
const auto singleWithBg = [&](const QColor &c) {
|
||||||
|
return withBg([&](const QColor &with) {
|
||||||
|
return CountContrast(c, with);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (withBg(minimal) < kMinAcceptableContrast) {
|
||||||
|
const auto white = QColor(255, 255, 255);
|
||||||
|
const auto black = QColor(0, 0, 0);
|
||||||
|
// This one always gives black :)
|
||||||
|
//const auto now = (singleWithBg(white) >= singleWithBg(black))
|
||||||
|
// ? white
|
||||||
|
// : black;
|
||||||
|
const auto now = descriptor.basedOnDark ? white : black;
|
||||||
|
for (const auto &color : colors) {
|
||||||
|
set(color, now);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatTheme::set(const style::color &my, const QColor &color) {
|
void ChatTheme::set(const style::color &my, const QColor &color) {
|
||||||
|
|
|
@ -101,6 +101,7 @@ struct ChatThemeDescriptor {
|
||||||
Fn<void(style::palette&)> preparePalette;
|
Fn<void(style::palette&)> preparePalette;
|
||||||
ChatThemeBackgroundData backgroundData;
|
ChatThemeBackgroundData backgroundData;
|
||||||
ChatThemeBubblesData bubblesData;
|
ChatThemeBubblesData bubblesData;
|
||||||
|
bool basedOnDark = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChatTheme final : public base::has_weak_ptr {
|
class ChatTheme final : public base::has_weak_ptr {
|
||||||
|
|
|
@ -1452,6 +1452,7 @@ void SessionController::cacheChatTheme(const Data::CloudTheme &data) {
|
||||||
data.accentColor),
|
data.accentColor),
|
||||||
.backgroundData = backgroundData(theme),
|
.backgroundData = backgroundData(theme),
|
||||||
.bubblesData = PrepareBubblesData(data),
|
.bubblesData = PrepareBubblesData(data),
|
||||||
|
.basedOnDark = data.basedOnDark,
|
||||||
};
|
};
|
||||||
crl::async([
|
crl::async([
|
||||||
this,
|
this,
|
||||||
|
|
Loading…
Add table
Reference in a new issue