From 9d59e42b522b9403994e5b704a4fe4004003c95d Mon Sep 17 00:00:00 2001 From: Dragoon Aethis Date: Tue, 8 Nov 2022 11:19:17 +0100 Subject: [PATCH] Add an experimental "small message radius" toggle (#25305) Add an experimental "small message radius" toggle. This toggle allows switching to the pre-4.3.0, smaller message bubble radius after an app restart. The message bubble radius styles now have to be referenced via the Ui::BubbleRadius* and Ui::MsgFileThumbRadius* wrappers to use the appropriate value. --- .../settings/settings_experimental.cpp | 2 + .../SourceFiles/ui/cached_round_corners.cpp | 10 +-- Telegram/SourceFiles/ui/chat/chat_style.cpp | 16 ++--- Telegram/SourceFiles/ui/chat/chat_style.h | 1 + .../SourceFiles/ui/chat/chat_style_radius.cpp | 61 +++++++++++++++++++ .../SourceFiles/ui/chat/chat_style_radius.h | 20 ++++++ .../SourceFiles/ui/chat/message_bubble.cpp | 8 +-- .../window/themes/window_theme_preview.cpp | 4 +- Telegram/cmake/td_ui.cmake | 2 + 9 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 Telegram/SourceFiles/ui/chat/chat_style_radius.cpp create mode 100644 Telegram/SourceFiles/ui/chat/chat_style_radius.h diff --git a/Telegram/SourceFiles/settings/settings_experimental.cpp b/Telegram/SourceFiles/settings/settings_experimental.cpp index e5d2e21ea1..b0313c6b8a 100644 --- a/Telegram/SourceFiles/settings/settings_experimental.cpp +++ b/Telegram/SourceFiles/settings/settings_experimental.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/gl/gl_detection.h" +#include "ui/chat/chat_style_radius.h" #include "base/options.h" #include "core/application.h" #include "chat_helpers/tabbed_panel.h" @@ -137,6 +138,7 @@ void SetupExperimental( addToggle(Window::kOptionViewProfileInChatsListContextMenu); addToggle(Dialogs::kOptionCtrlClickChatNewWindow); addToggle(Ui::GL::kOptionAllowLinuxNvidiaOpenGL); + addToggle(Ui::kOptionUseSmallMsgBubbleRadius); addToggle(Media::Player::kOptionDisableAutoplayNext); addToggle(Settings::kOptionMonoSettingsIcons); addToggle(Webview::kOptionWebviewDebugEnabled); diff --git a/Telegram/SourceFiles/ui/cached_round_corners.cpp b/Telegram/SourceFiles/ui/cached_round_corners.cpp index 683dbf8fb1..fc98b3e59c 100644 --- a/Telegram/SourceFiles/ui/cached_round_corners.cpp +++ b/Telegram/SourceFiles/ui/cached_round_corners.cpp @@ -6,7 +6,7 @@ For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/cached_round_corners.h" - +#include "ui/chat/chat_style.h" #include "ui/painter.h" #include "ui/ui_utility.h" #include "ui/image/image_prepare.h" @@ -244,10 +244,10 @@ CornersPixmaps PrepareCornerPixmaps(ImageRoundRadius radius, style::color bg, co using Radius = CachedCornerRadius; switch (tag) { case Radius::Small: return st::roundRadiusSmall; - case Radius::ThumbSmall: return st::msgFileThumbRadiusSmall; - case Radius::ThumbLarge: return st::msgFileThumbRadiusLarge; - case Radius::BubbleSmall: return st::bubbleRadiusSmall; - case Radius::BubbleLarge: return st::bubbleRadiusLarge; + case Radius::ThumbSmall: return MsgFileThumbRadiusSmall(); + case Radius::ThumbLarge: return MsgFileThumbRadiusLarge(); + case Radius::BubbleSmall: return BubbleRadiusSmall(); + case Radius::BubbleLarge: return BubbleRadiusLarge(); } Unexpected("Radius tag in CachedCornerRadiusValue."); } diff --git a/Telegram/SourceFiles/ui/chat/chat_style.cpp b/Telegram/SourceFiles/ui/chat/chat_style.cpp index bf37a73eec..7b246444f0 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_style.cpp @@ -502,12 +502,12 @@ const MessageStyle &ChatStyle::messageStyle(bool outbg, bool selected) const { auto &result = messageStyleRaw(outbg, selected); EnsureCorners( result.msgBgCornersSmall, - st::bubbleRadiusSmall, + BubbleRadiusSmall(), result.msgBg, &result.msgShadow); EnsureCorners( result.msgBgCornersLarge, - st::bubbleRadiusLarge, + BubbleRadiusLarge(), result.msgBg, &result.msgShadow); return result; @@ -521,19 +521,19 @@ const MessageImageStyle &ChatStyle::imageStyle(bool selected) const { result.msgDateImgBg); EnsureCorners( result.msgServiceBgCornersSmall, - st::bubbleRadiusSmall, + BubbleRadiusSmall(), result.msgServiceBg); EnsureCorners( result.msgServiceBgCornersLarge, - st::bubbleRadiusLarge, + BubbleRadiusLarge(), result.msgServiceBg); EnsureCorners( result.msgShadowCornersSmall, - st::bubbleRadiusSmall, + BubbleRadiusSmall(), result.msgShadow); EnsureCorners( result.msgShadowCornersLarge, - st::bubbleRadiusLarge, + BubbleRadiusLarge(), result.msgShadow); return result; } @@ -541,7 +541,7 @@ const MessageImageStyle &ChatStyle::imageStyle(bool selected) const { const CornersPixmaps &ChatStyle::msgBotKbOverBgAddCornersSmall() const { EnsureCorners( _msgBotKbOverBgAddCornersSmall, - st::bubbleRadiusSmall, + BubbleRadiusSmall(), msgBotKbOverBgAdd()); return _msgBotKbOverBgAddCornersSmall; } @@ -549,7 +549,7 @@ const CornersPixmaps &ChatStyle::msgBotKbOverBgAddCornersSmall() const { const CornersPixmaps &ChatStyle::msgBotKbOverBgAddCornersLarge() const { EnsureCorners( _msgBotKbOverBgAddCornersLarge, - st::bubbleRadiusLarge, + BubbleRadiusLarge(), msgBotKbOverBgAdd()); return _msgBotKbOverBgAddCornersLarge; } diff --git a/Telegram/SourceFiles/ui/chat/chat_style.h b/Telegram/SourceFiles/ui/chat/chat_style.h index 415a8b8964..234928f071 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.h +++ b/Telegram/SourceFiles/ui/chat/chat_style.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/cached_round_corners.h" #include "ui/chat/message_bubble.h" +#include "ui/chat/chat_style_radius.h" #include "ui/style/style_core_palette.h" #include "layout/layout_selection.h" #include "styles/style_basic.h" diff --git a/Telegram/SourceFiles/ui/chat/chat_style_radius.cpp b/Telegram/SourceFiles/ui/chat/chat_style_radius.cpp new file mode 100644 index 0000000000..0d54394fcc --- /dev/null +++ b/Telegram/SourceFiles/ui/chat/chat_style_radius.cpp @@ -0,0 +1,61 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "ui/chat/chat_style_radius.h" +#include "ui/chat/chat_style.h" +#include "base/options.h" + +#include "ui/chat/chat_theme.h" +#include "ui/painter.h" +#include "ui/ui_utility.h" +#include "styles/style_chat.h" + +namespace Ui { +namespace { + +base::options::toggle UseSmallMsgBubbleRadius({ + .id = kOptionUseSmallMsgBubbleRadius, + .name = "Use small message bubble radius", + .description = "Makes most message bubbles square-ish.", + .restartRequired = true, +}); + +} // namespace + +const char kOptionUseSmallMsgBubbleRadius[] = "use-small-msg-bubble-radius"; + +int BubbleRadiusSmall() { + return st::bubbleRadiusSmall; +} + +int BubbleRadiusLarge() { + static const auto result = [] { + if (UseSmallMsgBubbleRadius.value()) { + return st::bubbleRadiusSmall; + } else { + return st::bubbleRadiusLarge; + } + }(); + return result; +} + +int MsgFileThumbRadiusSmall() { + return st::msgFileThumbRadiusSmall; +} + +int MsgFileThumbRadiusLarge() { + static const auto result = [] { + if (UseSmallMsgBubbleRadius.value()) { + return st::msgFileThumbRadiusSmall; + } else { + return st::msgFileThumbRadiusLarge; + } + }(); + return result; +} + +} diff --git a/Telegram/SourceFiles/ui/chat/chat_style_radius.h b/Telegram/SourceFiles/ui/chat/chat_style_radius.h new file mode 100644 index 0000000000..d8c4b7d946 --- /dev/null +++ b/Telegram/SourceFiles/ui/chat/chat_style_radius.h @@ -0,0 +1,20 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Ui { + +[[nodiscard]] int BubbleRadiusSmall(); +[[nodiscard]] int BubbleRadiusLarge(); + +[[nodiscard]] int MsgFileThumbRadiusSmall(); +[[nodiscard]] int MsgFileThumbRadiusLarge(); + +extern const char kOptionUseSmallMsgBubbleRadius[]; + +} diff --git a/Telegram/SourceFiles/ui/chat/message_bubble.cpp b/Telegram/SourceFiles/ui/chat/message_bubble.cpp index 8459d6dd4d..8d398e51c5 100644 --- a/Telegram/SourceFiles/ui/chat/message_bubble.cpp +++ b/Telegram/SourceFiles/ui/chat/message_bubble.cpp @@ -48,8 +48,8 @@ void PaintBubbleGeneric( ? Corner::None : bottomWithTailRight; const auto rect = args.geometry; - const auto small = st::bubbleRadiusSmall; - const auto large = st::bubbleRadiusLarge; + const auto small = BubbleRadiusSmall(); + const auto large = BubbleRadiusLarge(); const auto cornerSize = [&](Corner corner) { return (corner == Corner::Large) ? large @@ -250,8 +250,8 @@ void PaintSolidBubble(QPainter &p, const SimpleBubble &args) { std::unique_ptr PrepareBubblePattern( not_null st) { auto result = std::make_unique(); - result->cornersSmall = Images::CornersMask(st::bubbleRadiusSmall); - result->cornersLarge = Images::CornersMask(st::bubbleRadiusLarge); + result->cornersSmall = Images::CornersMask(BubbleRadiusSmall()); + result->cornersLarge = Images::CornersMask(BubbleRadiusLarge()); const auto addShadow = [&](QImage &bottomCorner) { auto result = QImage( bottomCorner.width(), diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index 7972735047..1a6a294823 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -786,8 +786,8 @@ void Generator::paintBubble(const Bubble &bubble) { auto bubbleTop = y; auto bubbleHeight = height; if (isPhoto) { - bubbleTop -= st::bubbleRadiusLarge + 1; - bubbleHeight += st::bubbleRadiusLarge + 1; + bubbleTop -= Ui::BubbleRadiusLarge() + 1; + bubbleHeight += Ui::BubbleRadiusLarge() + 1; } auto left = bubble.outbg ? st::msgMargin.right() : st::msgMargin.left(); diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index 13e473c4fc..0465b7658f 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -188,6 +188,8 @@ PRIVATE ui/chat/attach/attach_single_media_preview.h ui/chat/chat_style.cpp ui/chat/chat_style.h + ui/chat/chat_style_radius.cpp + ui/chat/chat_style_radius.h ui/chat/chat_theme.cpp ui/chat/chat_theme.h ui/chat/continuous_scroll.cpp