From 241798ac2902a73b90a42176138313c3c0802c2b Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 3 Sep 2021 18:51:48 +0300 Subject: [PATCH] Custom colors in historyDown/unreadMentions buttons. --- .../history/history_item_components.cpp | 3 +- .../SourceFiles/history/history_widget.cpp | 21 ++++++++++-- Telegram/SourceFiles/history/history_widget.h | 6 ++++ .../history/view/history_view_message.cpp | 7 ++-- .../history/view/media/history_view_poll.cpp | 33 +++++++++++++------ Telegram/SourceFiles/ui/chat/chat.style | 10 +----- Telegram/SourceFiles/ui/chat/chat_style.cpp | 18 ++++++++-- Telegram/SourceFiles/ui/chat/chat_style.h | 22 +++++++++++-- Telegram/codegen | 2 +- Telegram/lib_ui | 2 +- 10 files changed, 90 insertions(+), 34 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index c257d1291..715a98549 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -803,7 +803,8 @@ void ReplyKeyboard::Style::paintButton( const QRect &rect = button.rect; paintButtonBg(p, st, rect, button.howMuchOver); if (button.ripple) { - button.ripple->paint(p, rect.x(), rect.y(), outerWidth); + const auto color = st ? &st->msgBotKbRippleBg()->c : nullptr; + button.ripple->paint(p, rect.x(), rect.y(), outerWidth, color); if (button.ripple->empty()) { button.ripple.reset(); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 907eb243c..981c1c4a2 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -180,6 +180,11 @@ const auto kPsaAboutPrefix = "cloud_lng_about_psa_"; } // namespace +struct HistoryWidget::CustomStyles { + style::TwoIconButton historyToDown; + style::TwoIconButton historyUnreadMentions; +}; + HistoryWidget::HistoryWidget( QWidget *parent, not_null controller) @@ -187,6 +192,7 @@ HistoryWidget::HistoryWidget( parent, controller, ActivePeerValue(controller)) +, _styles(MakeCustomStyles(controller)) , _api(&controller->session().mtp()) , _updateEditTimeLeftDisplay([=] { updateField(); }) , _fieldBarCancel(this, st::historyReplyCancel) @@ -195,8 +201,8 @@ HistoryWidget::HistoryWidget( , _topBar(this, controller) , _scroll(this, st::historyScroll, false) , _updateHistoryItems([=] { updateHistoryItemsByTimer(); }) -, _historyDown(_scroll, st::historyToDown) -, _unreadMentions(_scroll, st::historyUnreadMentions) +, _historyDown(_scroll, _styles->historyToDown) +, _unreadMentions(_scroll, _styles->historyUnreadMentions) , _fieldAutocomplete(this, controller) , _supportAutocomplete(session().supportMode() ? object_ptr(this, &session()) @@ -3984,6 +3990,17 @@ bool HistoryWidget::kbWasHidden() const { return _history && (_keyboard->forMsgId() == FullMsgId(_history->channelId(), _history->lastKeyboardHiddenId)); } +auto HistoryWidget::MakeCustomStyles( + not_null controller) +-> std::unique_ptr { + const auto st = controller->chatStyle(); + + auto result = std::make_unique(); + result->historyToDown = st->value(st::historyToDown); + result->historyUnreadMentions = st->value(st::historyUnreadMentions); + return result; +} + void HistoryWidget::toggleKeyboard(bool manual) { auto fieldEnabled = canWriteMessage() && !_a_show.animating(); if (_kbShown || _kbReplyTo) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index ae3ff7bd8..1a3798080 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -300,6 +300,7 @@ protected: private: using TabbedPanel = ChatHelpers::TabbedPanel; using TabbedSelector = ChatHelpers::TabbedSelector; + struct CustomStyles; enum ScrollChangeType { ScrollChangeNone, @@ -603,6 +604,11 @@ private: bool kbWasHidden() const; + [[nodiscard]] static std::unique_ptr MakeCustomStyles( + not_null controller); + + const std::unique_ptr _styles; + MTP::Sender _api; MsgId _replyToId = 0; Ui::Text::String _replyToName; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index c691c91f4..df06a5cb7 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -727,7 +727,8 @@ void Message::paintCommentsButton( if (_comments->ripple) { p.setOpacity(st::historyPollRippleOpacity); - _comments->ripple->paint(p, left, top, width); + const auto colorOverride = &stm->msgWaveformInactive->c; + _comments->ripple->paint(p, left, top, width, colorOverride); if (_comments->ripple->empty()) { _comments->ripple.reset(); } @@ -1098,9 +1099,7 @@ void Message::toggleCommentsButtonRipple(bool pressed) { false, drawMask); _comments->ripple = std::make_unique( - (hasOutLayout() - ? st::historyPollRippleOut - : st::historyPollRippleIn), + st::defaultRippleAnimation, std::move(mask), [=] { history()->owner().requestViewRepaint(this); }); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index 786156459..7a7b3c900 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -806,7 +806,9 @@ void Poll::paintBottom( int top, int paintw, const PaintContext &context) const { - const auto stringtop = top + st::msgPadding.bottom() + st::historyPollBottomButtonTop; + const auto stringtop = top + + st::msgPadding.bottom() + + st::historyPollBottomButtonTop; const auto stm = context.messageStyle(); if (showVotersCount()) { p.setPen(stm->msgDateFg); @@ -820,7 +822,12 @@ void Poll::paintBottom( if (_linkRipple) { const auto linkHeight = bottomButtonHeight(); p.setOpacity(st::historyPollRippleOpacity); - _linkRipple->paint(p, left - st::msgPadding.left(), height() - linkHeight, width()); + _linkRipple->paint( + p, + left - st::msgPadding.left(), + height() - linkHeight, + width(), + &stm->msgWaveformInactive->c); if (_linkRipple->empty()) { _linkRipple.reset(); } @@ -832,7 +839,12 @@ void Poll::paintBottom( ? tr::lng_polls_view_results(tr::now, Ui::Text::Upper) : tr::lng_polls_submit_votes(tr::now, Ui::Text::Upper); const auto stringw = st::semiboldFont->width(string); - p.drawTextLeft(left + (paintw - stringw) / 2, stringtop, width(), string, stringw); + p.drawTextLeft( + left + (paintw - stringw) / 2, + stringtop, + width(), + string, + stringw); } } @@ -1018,7 +1030,12 @@ int Poll::paintAnswer( if (answer.ripple) { p.setOpacity(st::historyPollRippleOpacity); - answer.ripple->paint(p, left - st::msgPadding.left(), top, outerWidth); + answer.ripple->paint( + p, + left - st::msgPadding.left(), + top, + outerWidth, + &stm->msgWaveformInactive->c); if (answer.ripple->empty()) { answer.ripple.reset(); } @@ -1445,9 +1462,7 @@ void Poll::toggleRipple(Answer &answer, bool pressed) { outerWidth, countAnswerHeight(answer, innerWidth))); answer.ripple = std::make_unique( - (_parent->hasOutLayout() - ? st::historyPollRippleOut - : st::historyPollRippleIn), + st::defaultRippleAnimation, std::move(mask), [=] { history()->owner().requestViewRepaint(_parent); }); } @@ -1510,9 +1525,7 @@ void Poll::toggleLinkRipple(bool pressed) { drawMask) : Ui::RippleAnimation::rectMask({ linkWidth, linkHeight }); _linkRipple = std::make_unique( - (_parent->hasOutLayout() - ? st::historyPollRippleOut - : st::historyPollRippleIn), + st::defaultRippleAnimation, std::move(mask), [=] { history()->owner().requestViewRepaint(_parent); }); } diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 87dc22149..4f13f5f41 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -461,9 +461,7 @@ msgBotKbButton: BotKeyboardButton { padding: 10px; height: 36px; textTop: 8px; - ripple: RippleAnimation(defaultRippleAnimation) { - color: msgBotKbRippleBg; - } + ripple: defaultRippleAnimation; } botKbDuration: 200; @@ -738,12 +736,6 @@ historyPollRadialAnimation: InfiniteRadialAnimation(defaultInfiniteRadialAnimati thickness: 2px; size: size(18px, 18px); } -historyPollRippleIn: RippleAnimation(defaultRippleAnimation) { - color: msgWaveformInInactive; -} -historyPollRippleOut: RippleAnimation(defaultRippleAnimation) { - color: msgWaveformOutInactive; -} historyPollRippleOpacity: 0.3; historyPollRecentVotersSkip: 4px; historyPollRecentVoterSize: 18px; diff --git a/Telegram/SourceFiles/ui/chat/chat_style.cpp b/Telegram/SourceFiles/ui/chat/chat_style.cpp index db9ace7ef..f0db31446 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_style.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/ui_utility.h" #include "styles/style_chat.h" #include "styles/style_dialogs.h" +#include "styles/style_widgets.h" namespace Ui { namespace { @@ -596,17 +597,17 @@ MessageImageStyle &ChatStyle::imageSelected() { return imageStyleRaw(true); } -void ChatStyle::make(style::color &my, const style::color &original) { +void ChatStyle::make(style::color &my, const style::color &original) const { my = _colors[style::main_palette::indexOfColor(original)]; } -void ChatStyle::make(style::icon &my, const style::icon &original) { +void ChatStyle::make(style::icon &my, const style::icon &original) const { my = original.withPalette(*this); } void ChatStyle::make( style::TextPalette &my, - const style::TextPalette &original) { + const style::TextPalette &original) const { make(my.linkFg, original.linkFg); make(my.monoFg, original.monoFg); make(my.selectBg, original.selectBg); @@ -616,6 +617,17 @@ void ChatStyle::make( make(my.selectOverlay, original.selectOverlay); } +void ChatStyle::make( + style::TwoIconButton &my, + const style::TwoIconButton &original) const { + my = original; + make(my.iconBelow, original.iconBelow); + make(my.iconAbove, original.iconAbove); + make(my.iconBelowOver, original.iconBelowOver); + make(my.iconAboveOver, original.iconAboveOver); + make(my.ripple.color, original.ripple.color); +} + template void ChatStyle::make( Type MessageStyle::*my, diff --git a/Telegram/SourceFiles/ui/chat/chat_style.h b/Telegram/SourceFiles/ui/chat/chat_style.h index 59a6fb4cd..b930d6b3a 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.h +++ b/Telegram/SourceFiles/ui/chat/chat_style.h @@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL enum class ImageRoundRadius; +namespace style { +struct TwoIconButton; +} // namespace style + namespace Ui { class ChatTheme; @@ -136,6 +140,13 @@ public: void apply(not_null theme); + template + [[nodiscard]] Type value(const Type &original) const { + auto my = Type(); + make(my, original); + return my; + } + [[nodiscard]] const CornersPixmaps &serviceBgCornersNormal() const; [[nodiscard]] const CornersPixmaps &serviceBgCornersInverted() const; @@ -224,9 +235,14 @@ public: private: void assignPalette(not_null palette); - void make(style::color &my, const style::color &original); - void make(style::icon &my, const style::icon &original); - void make(style::TextPalette &my, const style::TextPalette &original); + void make(style::color &my, const style::color &original) const; + void make(style::icon &my, const style::icon &original) const; + void make( + style::TextPalette &my, + const style::TextPalette &original) const; + void make( + style::TwoIconButton &my, + const style::TwoIconButton &original) const; [[nodiscard]] MessageStyle &messageStyleRaw( bool outbg, diff --git a/Telegram/codegen b/Telegram/codegen index aaa64e67c..b1c206550 160000 --- a/Telegram/codegen +++ b/Telegram/codegen @@ -1 +1 @@ -Subproject commit aaa64e67cb247112dad396fd75f8ef3c1849aed3 +Subproject commit b1c206550eeba4bac6f4f5a1699a6b199f7af4ac diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 1180d13a5..a8ce22fd7 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 1180d13a5c654b517901d6bdab030f17ff314ff6 +Subproject commit a8ce22fd75d8f53449aae6319d5503f7e8967f5e