From 5baeb464362bf33a6321da173f1e24788f602e6e Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Fri, 26 Aug 2022 16:10:02 +0300 Subject: [PATCH] [Option][GUI] Adaptive chat bubbles --- Telegram/Resources/langs/rewrites/en.json | 2 + .../history/history_inner_widget.cpp | 3 +- .../SourceFiles/history/history_widget.cpp | 30 ++++++++++++++ .../history/view/history_view_element.cpp | 7 +++- .../history/view/history_view_element.h | 1 + .../history/view/history_view_list_widget.cpp | 3 +- .../history/view/history_view_message.cpp | 21 +++++++--- .../history/view/history_view_message.h | 3 +- .../view/history_view_service_message.cpp | 7 ++-- .../view/media/history_view_document.cpp | 7 +++- .../history/view/media/history_view_gif.cpp | 14 ++++++- .../view/media/history_view_location.cpp | 11 +++++- .../view/media/history_view_media_grouped.cpp | 14 ++++++- .../history/view/media/history_view_photo.cpp | 14 +++++-- .../view/media/history_view_web_page.cpp | 9 +++++ .../SourceFiles/kotato/kotato_settings.cpp | 7 ++++ .../kotato/kotato_settings_menu.cpp | 39 +++++++++++++++++++ .../window/themes/window_theme_preview.cpp | 13 +++++-- 18 files changed, 182 insertions(+), 23 deletions(-) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index aabef3f54..eadf8ae16 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -46,8 +46,10 @@ "ktg_settings_network": "Network", "ktg_settings_system": "System", "ktg_settings_other": "Other", + "ktg_settings_adaptive_bubbles": "Adaptive bubbles", "ktg_settings_filters": "Folders", "ktg_settings_messages": "Messages", + "ktg_settings_monospace_large_bubbles": "Expand bubbles with monospace", "ktg_settings_forward": "Forward", "ktg_in_app_update_disabled": "In-app updater is disabled.", "dummy_last_string": "" diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index e719d9716..142f72ff9 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/history_inner_widget.h" +#include "kotato/kotato_settings.h" #include "core/file_utilities.h" #include "core/crash_reports.h" #include "core/click_handler_types.h" @@ -3641,7 +3642,7 @@ void HistoryInner::mouseActionUpdate() { dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right(); auto dateLeft = st::msgServiceMargin.left(); auto maxwidth = _contentWidth; - if (_isChatWide) { + if (_isChatWide && !::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 98ea9f8f3..516fab4e8 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -598,6 +598,36 @@ HistoryWidget::HistoryWidget( }); }, lifetime()); + ::Kotato::JsonSettings::Events( + "adaptive_bubbles" + ) | rpl::start_with_next([=] { + crl::on_main(this, [=] { + if (_history) { + _history->forceFullResize(); + if (_migrated) { + _migrated->forceFullResize(); + } + updateHistoryGeometry(); + update(); + } + }); + }, lifetime()); + + ::Kotato::JsonSettings::Events( + "monospace_large_bubbles" + ) | rpl::start_with_next([=] { + crl::on_main(this, [=] { + if (_history) { + _history->forceFullResize(); + if (_migrated) { + _migrated->forceFullResize(); + } + updateHistoryGeometry(); + update(); + } + }); + }, lifetime()); + session().data().webPageUpdates( ) | rpl::filter([=](not_null page) { return (_previewData == page.get()); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index d6e7c4099..8b60bfb33 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/history_view_element.h" +#include "kotato/kotato_settings.h" #include "api/api_chat_invite.h" #include "history/view/history_view_service_message.h" #include "history/view/history_view_message.h" @@ -312,7 +313,7 @@ void UnreadBar::paint( p.setPen(st->historyUnreadBarFg()); int maxwidth = w; - if (chatWide) { + if (chatWide && !::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { maxwidth = qMin( maxwidth, st::msgMaxWidth @@ -589,6 +590,10 @@ int Element::infoWidth() const { return 0; } +int Element::plainMaxWidth() const { + return 0; +} + int Element::bottomInfoFirstLineWidth() const { return 0; } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index a2b9cb049..7ac4a256f 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -305,6 +305,7 @@ public: [[nodiscard]] int skipBlockWidth() const; [[nodiscard]] int skipBlockHeight() const; [[nodiscard]] virtual int infoWidth() const; + [[nodiscard]] virtual int plainMaxWidth() const; [[nodiscard]] virtual int bottomInfoFirstLineWidth() const; [[nodiscard]] virtual bool bottomInfoIsWide() const; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index f45f4f62b..e3742b11e 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/history_view_list_widget.h" +#include "kotato/kotato_settings.h" #include "base/unixtime.h" #include "base/qt/qt_key_modifiers.h" #include "base/qt/qt_common_adapters.h" @@ -3431,7 +3432,7 @@ void ListWidget::mouseActionUpdate() { dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right(); auto dateLeft = st::msgServiceMargin.left(); auto maxwidth = view->width(); - if (_isChatWide) { + if (_isChatWide && !::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 5e0f36ddf..b2cd40716 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/history_view_message.h" +#include "kotato/kotato_settings.h" #include "core/click_handler_types.h" // ClickHandlerContext #include "core/ui_integration.h" #include "history/view/history_view_cursor_state.h" @@ -3423,7 +3424,9 @@ QRect Message::countGeometry() const { // contentLeft += st::msgPhotoSkip - (hmaxwidth - hwidth); } accumulate_min(contentWidth, maxWidth()); - accumulate_min(contentWidth, _bubbleWidthLimit); + if (!::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + accumulate_min(contentWidth, _bubbleWidthLimit); + } if (mediaWidth < contentWidth) { const auto textualWidth = plainMaxWidth(); if (mediaWidth < textualWidth @@ -3433,7 +3436,11 @@ QRect Message::countGeometry() const { contentWidth = mediaWidth; } } - if (contentWidth < availableWidth && !delegate()->elementIsChatWide()) { + if (contentWidth < availableWidth + && (!delegate()->elementIsChatWide() + || (context() == Context::Replies + && item->isDiscussionPost() + && ::Kotato::JsonSettings::GetBool("adaptive_bubbles")))) { if (outbg) { contentLeft += availableWidth - contentWidth; } else if (centeredView) { @@ -3525,8 +3532,12 @@ int Message::resizeContentGetHeight(int newWidth) { } } accumulate_min(contentWidth, maxWidth()); - _bubbleWidthLimit = std::max(st::msgMaxWidth, monospaceMaxWidth()); - accumulate_min(contentWidth, _bubbleWidthLimit); + _bubbleWidthLimit = (::Kotato::JsonSettings::GetBool("monospace_large_bubbles") + ? std::max(st::msgMaxWidth, monospaceMaxWidth()) + : st::msgMaxWidth); + if (!::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + accumulate_min(contentWidth, _bubbleWidthLimit); + } if (mediaDisplayed) { media->resizeGetHeight(contentWidth); if (media->width() < contentWidth) { @@ -3559,7 +3570,7 @@ int Message::resizeContentGetHeight(int newWidth) { _reactions->resizeGetHeight(textWidth); } - if (contentWidth == maxWidth()) { + if (!::Kotato::JsonSettings::GetBool("adaptive_bubbles") && contentWidth == maxWidth()) { if (mediaDisplayed) { if (entry) { newHeight += entry->resizeGetHeight(contentWidth); diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index f9fd8afa7..b6bc0aa55 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -141,6 +141,7 @@ public: [[nodiscard]] bool toggleSelectionByHandlerClick( const ClickHandlerPtr &handler) const override; [[nodiscard]] int infoWidth() const override; + [[nodiscard]] int plainMaxWidth() const override; [[nodiscard]] int bottomInfoFirstLineWidth() const override; [[nodiscard]] bool bottomInfoIsWide() const override; [[nodiscard]] bool isSignedAuthorElided() const override; @@ -276,7 +277,7 @@ private: void ensureRightAction() const; void refreshTopicButton(); void refreshInfoSkipBlock(); - [[nodiscard]] int plainMaxWidth() const; + //[[nodiscard]] int plainMaxWidth() const; [[nodiscard]] int monospaceMaxWidth() const; void validateInlineKeyboard(HistoryMessageReplyMarkup *markup); diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index d1d7953a6..804ae1168 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/history_view_service_message.h" +#include "kotato/kotato_settings.h" #include "history/view/media/history_view_media.h" #include "history/view/history_view_cursor_state.h" #include "history/history.h" @@ -154,7 +155,7 @@ void PaintPreparedDate( int w, bool chatWide) { int left = st::msgServiceMargin.left(); - const auto maxwidth = chatWide + const auto maxwidth = (chatWide && !::Kotato::JsonSettings::GetBool("adaptive_bubbles")) ? std::min(w, WideChatWidth()) : w; w = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); @@ -413,7 +414,7 @@ QRect Service::innerGeometry() const { QRect Service::countGeometry() const { auto result = QRect(0, 0, width(), height()); - if (delegate()->elementIsChatWide()) { + if (delegate()->elementIsChatWide() && !::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { result.setWidth(qMin(result.width(), st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); } return result.marginsRemoved(st::msgServiceMargin); @@ -435,7 +436,7 @@ QSize Service::performCountCurrentSize(int newWidth) { + st::msgServiceMargin.bottom(); } else if (!text().isEmpty()) { auto contentWidth = newWidth; - if (delegate()->elementIsChatWide()) { + if (delegate()->elementIsChatWide() && !::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { accumulate_min(contentWidth, st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()); } contentWidth -= st::msgServiceMargin.left() + st::msgServiceMargin.left(); // two small margins diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 19832fc23..81bf404df 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/media/history_view_document.h" +#include "kotato/kotato_settings.h" #include "base/random.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" @@ -384,7 +385,11 @@ QSize Document::countOptimalSize() { if (auto named = Get()) { accumulate_max(maxWidth, tleft + named->namew + tright); - accumulate_min(maxWidth, st::msgMaxWidth); + if (::Kotato::JsonSettings::GetBool("adaptive_bubbles") && captioned) { + accumulate_max(maxWidth, captioned->caption.maxWidth() + st::msgPadding.left() + st::msgPadding.right()); + } else { + accumulate_min(maxWidth, st::msgMaxWidth); + } } if (voice && voice->transcribe) { maxWidth += st::historyTranscribeSkip diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index a395f8f09..a45e85daf 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/media/history_view_gif.h" +#include "kotato/kotato_settings.h" #include "apiwrap.h" #include "api/api_transcribes.h" #include "lang/lang_keys.h" @@ -150,13 +151,19 @@ QSize Gif::sizeForAspectRatio() const { } QSize Gif::countThumbSize(int &inOutWidthMax) const { + const auto captionWithPaddings = ::Kotato::JsonSettings::GetBool("adaptive_bubbles") + ? _caption.maxWidth() + + st::msgPadding.left() + + st::msgPadding.right() + : 0; const auto maxSize = _data->isVideoFile() ? st::maxMediaSize : _data->isVideoMessage() ? st::maxVideoMessageSize : st::maxGifSize; + const auto maxSizeWithCaption = std::max(captionWithPaddings, maxSize); const auto size = style::ConvertScale(videoSize()); - accumulate_min(inOutWidthMax, maxSize); + accumulate_min(inOutWidthMax, maxSizeWithCaption); return DownscaledSize(size, { inOutWidthMax, maxSize }); } @@ -193,6 +200,11 @@ QSize Gif::countOptimalSize() { } if (_parent->hasBubble()) { if (!_caption.isEmpty()) { + if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + accumulate_max(maxWidth, _caption.maxWidth() + + st::msgPadding.left() + + st::msgPadding.right()); + } maxWidth = qMax(maxWidth, st::msgPadding.left() + _caption.maxWidth() + st::msgPadding.right()); diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.cpp b/Telegram/SourceFiles/history/view/media/history_view_location.cpp index ab75f2051..947a41ebc 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_location.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_location.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/media/history_view_location.h" +#include "kotato/kotato_settings.h" #include "history/history.h" #include "history/history_item_components.h" #include "history/history_item.h" @@ -92,9 +93,15 @@ QSize Location::countOptimalSize() { if (_parent->hasBubble()) { if (!_title.isEmpty()) { + if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + maxWidth = qMax(maxWidth, _title.maxWidth() + st::msgPadding.left() + st::msgPadding.right()); + } minHeight += qMin(_title.countHeight(maxWidth - st::msgPadding.left() - st::msgPadding.right()), 2 * st::webPageTitleFont->height); } if (!_description.isEmpty()) { + if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + maxWidth = qMax(maxWidth, _description.maxWidth() + st::msgPadding.left() + st::msgPadding.right()); + } minHeight += qMin(_description.countHeight(maxWidth - st::msgPadding.left() - st::msgPadding.right()), 3 * st::webPageDescriptionFont->height); } if (!_title.isEmpty() || !_description.isEmpty()) { @@ -119,8 +126,10 @@ QSize Location::countCurrentSize(int newWidth) { auto newHeight = th; if (tw > newWidth) { newHeight = (newWidth * newHeight / tw); - } else { + } else if (!::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { newWidth = tw; + } else { + newHeight = (newWidth * newHeight / tw); } auto minWidth = std::clamp( _parent->minWidthForMedia(), diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp index e20cf8f1e..c0b6a84ee 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/media/history_view_media_grouped.h" +#include "kotato/kotato_settings.h" #include "history/history_item_components.h" #include "history/history_item.h" #include "history/history.h" @@ -127,10 +128,18 @@ QSize GroupedMedia::countOptimalSize() { sizes.push_back(part.content->sizeForGroupingOptimal(maxWidth)); } + const auto captionWithPaddings = _caption.maxWidth() + + st::msgPadding.left() + + st::msgPadding.right(); + auto groupMaxWidth = st::historyGroupWidthMax; + if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + accumulate_max(groupMaxWidth, captionWithPaddings); + } + const auto layout = (_mode == Mode::Grid) ? Ui::LayoutMediaGroup( sizes, - st::historyGroupWidthMax, + groupMaxWidth, st::historyGroupWidthMin, st::historyGroupSkip) : LayoutPlaylist(sizes); @@ -146,6 +155,9 @@ QSize GroupedMedia::countOptimalSize() { } if (!_caption.isEmpty()) { + if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + maxWidth = qMax(maxWidth, captionWithPaddings); + } auto captionw = maxWidth - st::msgPadding.left() - st::msgPadding.right(); minHeight += st::mediaCaptionSkip + _caption.countHeight(captionw); if (isBubbleBottom()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index 78c4be6f3..4c57802fd 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/media/history_view_photo.h" +#include "kotato/kotato_settings.h" #include "history/history_item_components.h" #include "history/history_item.h" #include "history/history.h" @@ -175,15 +176,20 @@ QSize Photo::countOptimalSize() { ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), st::maxMediaSize); - const auto maxActualWidth = qMax(scaled.width(), minWidth); + auto maxActualWidth = qMax(scaled.width(), minWidth); auto maxWidth = qMax(maxActualWidth, scaled.height()); auto minHeight = qMax(scaled.height(), st::minPhotoSize); if (_parent->hasBubble() && !_caption.isEmpty()) { + const auto captionWithPaddings = (st::msgPadding.left() + + _caption.maxWidth() + + st::msgPadding.right()); + if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + maxActualWidth = qMax(maxActualWidth, captionWithPaddings); + maxWidth = qMax(maxWidth, captionWithPaddings); + } maxWidth = qMax( maxWidth, - (st::msgPadding.left() - + _caption.maxWidth() - + st::msgPadding.right())); + captionWithPaddings); minHeight = adjustHeightForLessCrop( dimensions, { maxWidth, minHeight }); diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index 3b909485f..cce97310d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/media/history_view_web_page.h" +#include "kotato/kotato_settings.h" #include "core/click_handler_types.h" #include "core/ui_integration.h" #include "lang/lang_keys.h" @@ -317,6 +318,10 @@ QSize WebPage::countOptimalSize() { _durationWidth = st::msgDateFont->width(_duration); } maxWidth += st::msgPadding.left() + st::webPageLeft + st::msgPadding.right(); + if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + accumulate_min(maxWidth, st::msgMaxWidth); + accumulate_max(maxWidth, _parent->plainMaxWidth()); + } auto padding = inBubblePadding(); minHeight += padding.top() + padding.bottom(); @@ -331,6 +336,10 @@ QSize WebPage::countCurrentSize(int newWidth) { return { newWidth, minHeight() }; } + if (::Kotato::JsonSettings::GetBool("adaptive_bubbles") && !asArticle()) { + accumulate_min(newWidth, maxWidth()); + } + auto innerWidth = newWidth - st::msgPadding.left() - st::webPageLeft - st::msgPadding.right(); auto newHeight = 0; diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp index b399e5817..022ca0592 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -253,12 +253,19 @@ const std::map> DefinitionMap { { "sticker_scale_both", { .type = SettingType::BoolSetting, .defaultValue = true, }}, + { "adaptive_bubbles", { + .type = SettingType::BoolSetting, + .defaultValue = false, }}, + { "monospace_large_bubbles", { + .type = SettingType::BoolSetting, + .defaultValue = false, }}, }; using OldOptionKey = QString; using NewOptionKey = QString; const std::map> ReplacedOptionsMap { + { "adaptive_baloons", "adaptive_bubbles" }, }; QString DefaultFilePath() { diff --git a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp index 18f4a7537..a505399da 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp @@ -134,6 +134,45 @@ void SetupKotatoMessages(not_null container) { AddDividerText(container, rktr("ktg_settings_sticker_scale_both_about")); AddSkip(container); + auto adaptiveBubblesButton = AddButton( + container, + rktr("ktg_settings_adaptive_bubbles"), + st::settingsButtonNoIcon + ); + + auto monospaceLargeBubblesButton = container->add( + object_ptr>( + container, + CreateButton( + container, + rktr("ktg_settings_monospace_large_bubbles"), + st::settingsButtonNoIcon))); + + adaptiveBubblesButton->toggleOn( + rpl::single(::Kotato::JsonSettings::GetBool("adaptive_bubbles")) + )->toggledValue( + ) | rpl::filter([](bool enabled) { + return (enabled != ::Kotato::JsonSettings::GetBool("adaptive_bubbles")); + }) | rpl::start_with_next([monospaceLargeBubblesButton](bool enabled) { + monospaceLargeBubblesButton->toggle(!enabled, anim::type::normal); + ::Kotato::JsonSettings::Set("adaptive_bubbles", enabled); + ::Kotato::JsonSettings::Write(); + }, container->lifetime()); + + monospaceLargeBubblesButton->entity()->toggleOn( + rpl::single(::Kotato::JsonSettings::GetBool("monospace_large_bubbles")) + )->toggledValue( + ) | rpl::filter([](bool enabled) { + return (enabled != ::Kotato::JsonSettings::GetBool("monospace_large_bubbles")); + }) | rpl::start_with_next([](bool enabled) { + ::Kotato::JsonSettings::Set("monospace_large_bubbles", enabled); + ::Kotato::JsonSettings::Write(); + }, container->lifetime()); + + if (adaptiveBubblesButton->toggled()) { + monospaceLargeBubblesButton->hide(anim::type::instant); + } + SettingsMenuJsonSwitch(ktg_settings_emoji_outline, big_emoji_outline); AddSkip(container); diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index f30c88d8f..c4838b02c 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "window/themes/window_theme_preview.h" +#include "kotato/kotato_settings.h" #include "lang/lang_keys.h" #include "platform/platform_window_title.h" #include "ui/text/text_options.h" @@ -266,7 +267,9 @@ void Generator::addAudioBubble(QVector waveform, int waveactive, QString wa const auto &st = st::msgFileLayout; auto tleft = st.padding.left() + st.thumbSize + st.thumbSkip; accumulate_max(width, tleft + st::normalFont->width(wavestatus) + skipBlock.width() + st::msgPadding.right()); - accumulate_min(width, st::msgMaxWidth); + if (!::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + accumulate_min(width, st::msgMaxWidth); + } auto height = st.padding.top() + st.thumbSize + st.padding.bottom(); addBubble(std::move(bubble), width, height, date, status); @@ -299,7 +302,9 @@ void Generator::addTextBubble(QString text, QString date, Status status) { auto width = _history.width() - st::msgMargin.left() - st::msgMargin.right(); accumulate_min(width, st::msgPadding.left() + bubble.text.maxWidth() + st::msgPadding.right()); - accumulate_min(width, st::msgMaxWidth); + if (!::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + accumulate_min(width, st::msgMaxWidth); + } auto textWidth = qMax(width - st::msgPadding.left() - st::msgPadding.right(), 1); auto textHeight = bubble.text.countHeight(textWidth); @@ -328,7 +333,9 @@ void Generator::addPhotoBubble(QString image, QString caption, QString date, Sta auto width = _history.width() - st::msgMargin.left() - st::msgMargin.right(); accumulate_min(width, bubble.photoWidth); - accumulate_min(width, st::msgMaxWidth); + if (!::Kotato::JsonSettings::GetBool("adaptive_bubbles")) { + accumulate_min(width, st::msgMaxWidth); + } auto textWidth = qMax(width - st::msgPadding.left() - st::msgPadding.right(), 1); auto textHeight = bubble.text.countHeight(textWidth);