[Option][GUI] Adaptive chat bubbles

This commit is contained in:
Eric Kotato 2022-08-26 16:10:02 +03:00
parent 8f91762576
commit 09c94b2a56
18 changed files with 214 additions and 26 deletions

View file

@ -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": ""

View file

@ -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"
@ -2613,7 +2614,7 @@ void HistoryInner::recountHistoryGeometry() {
updateBotInfo(false);
if (_botAbout && !_botAbout->info->text.isEmpty()) {
int32 tw = _scroll->width() - st::msgMargin.left() - st::msgMargin.right();
if (tw > st::msgMaxWidth) tw = st::msgMaxWidth;
if (!::Kotato::JsonSettings::GetBool("adaptive_bubbles") && tw > st::msgMaxWidth) tw = st::msgMaxWidth;
tw -= st::msgPadding.left() + st::msgPadding.right();
const auto descriptionWidth = _history->peer->isRepliesChat()
? 0
@ -2629,7 +2630,7 @@ void HistoryInner::recountHistoryGeometry() {
: (st::msgNameFont->height + st::botDescSkip);
int32 descH = st::msgMargin.top() + st::msgPadding.top() + descriptionHeight + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
int32 descMaxWidth = _scroll->width();
if (_isChatWide) {
if (_isChatWide && !::Kotato::JsonSettings::GetBool("adaptive_bubbles")) {
descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
}
int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
@ -2666,7 +2667,7 @@ void HistoryInner::updateBotInfo(bool recount) {
Ui::ItemTextBotNoMonoOptions());
if (recount) {
int32 tw = _scroll->width() - st::msgMargin.left() - st::msgMargin.right();
if (tw > st::msgMaxWidth) tw = st::msgMaxWidth;
if (!::Kotato::JsonSettings::GetBool("adaptive_bubbles") && tw > st::msgMaxWidth) tw = st::msgMaxWidth;
tw -= st::msgPadding.left() + st::msgPadding.right();
const auto descriptionWidth = _history->peer->isRepliesChat()
? 0
@ -2854,7 +2855,7 @@ void HistoryInner::updateSize() {
: (st::msgNameFont->height + st::botDescSkip);
int32 descH = st::msgMargin.top() + st::msgPadding.top() + descriptionHeight + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
int32 descMaxWidth = _scroll->width();
if (_isChatWide) {
if (_isChatWide && !::Kotato::JsonSettings::GetBool("adaptive_bubbles")) {
descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
}
int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
@ -3313,7 +3314,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();

View file

@ -554,6 +554,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().animationPlayInlineRequest(
) | rpl::start_with_next([=](not_null<HistoryItem*> item) {
if (const auto view = item->mainView()) {

View file

@ -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"
@ -302,7 +303,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
@ -499,6 +500,10 @@ int Element::infoWidth() const {
return 0;
}
int Element::plainMaxWidth() const {
return 0;
}
int Element::bottomInfoFirstLineWidth() const {
return 0;
}

View file

@ -283,6 +283,7 @@ public:
int skipBlockWidth() const;
int skipBlockHeight() const;
virtual int infoWidth() const;
virtual int plainMaxWidth() const;
virtual int bottomInfoFirstLineWidth() const;
virtual bool bottomInfoIsWide() const;

View file

@ -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 "history/history_message.h"
@ -2699,7 +2700,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();

View file

@ -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 "history/view/history_view_cursor_state.h"
#include "history/history_item_components.h"
@ -2772,7 +2773,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
@ -2782,7 +2785,9 @@ QRect Message::countGeometry() const {
contentWidth = mediaWidth;
}
}
if (contentWidth < availableWidth && !delegate()->elementIsChatWide()) {
if (contentWidth < availableWidth
&& (!delegate()->elementIsChatWide()
|| (commentsRoot && ::Kotato::JsonSettings::GetBool("adaptive_bubbles")))) {
if (outbg) {
contentLeft += availableWidth - contentWidth;
} else if (commentsRoot) {
@ -2826,8 +2831,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) {
@ -2860,7 +2869,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);

View file

@ -124,6 +124,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;
@ -228,7 +229,7 @@ private:
[[nodiscard]] ClickHandlerPtr fastReplyLink() const;
void refreshInfoSkipBlock();
[[nodiscard]] int plainMaxWidth() const;
//[[nodiscard]] int plainMaxWidth() const;
[[nodiscard]] int monospaceMaxWidth() const;
void updateViewButtonExistence();

View file

@ -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/history.h"
#include "history/history_service.h"
#include "history/view/media/history_view_media.h"
@ -140,7 +141,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();
@ -395,7 +396,7 @@ not_null<HistoryService*> Service::message() 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);
@ -418,7 +419,7 @@ QSize Service::performCountCurrentSize(int newWidth) {
item->_textHeight = 0;
} else {
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

View file

@ -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 "lang/lang_keys.h"
#include "storage/localstorage.h"
#include "media/audio/media_audio.h"
@ -262,7 +263,11 @@ QSize Document::countOptimalSize() {
if (auto named = Get<HistoryDocumentNamed>()) {
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);
}
}
auto minHeight = st.padding.top() + st.thumbSize + st.padding.bottom();

View file

@ -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 "lang/lang_keys.h"
#include "mainwindow.h"
#include "main/main_session.h"
@ -132,6 +133,11 @@ 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->sticker()
? Sticker::Size().width()
: _data->isVideoFile()
@ -139,7 +145,8 @@ QSize Gif::countThumbSize(int &inOutWidthMax) const {
: _data->isVideoMessage()
? st::maxVideoMessageSize
: st::maxGifSize;
const auto useMaxSize = std::max(maxSize, st::minPhotoSize);
const auto maxSizeWithCaption = std::max(captionWithPaddings, maxSize);
const auto useMaxSize = std::max(maxSizeWithCaption, st::minPhotoSize);
const auto size = _data->sticker()
? videoSize()
: style::ConvertScale(videoSize());
@ -171,6 +178,14 @@ QSize Gif::countOptimalSize() {
if (_parent->hasBubble()) {
accumulate_max(maxWidth, _parent->minWidthForMedia());
if (!_caption.isEmpty()) {
if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) {
const auto captionWithPaddings = ::Kotato::JsonSettings::GetBool("adaptive_bubbles")
? _caption.maxWidth()
+ st::msgPadding.left()
+ st::msgPadding.right()
: 0;
accumulate_max(maxWidth, captionWithPaddings);
}
auto captionw = maxWidth - st::msgPadding.left() - st::msgPadding.right();
minHeight += st::mediaCaptionSkip + _caption.countHeight(captionw);
if (isBubbleBottom()) {
@ -210,6 +225,15 @@ QSize Gif::countCurrentSize(int newWidth) {
if (_parent->hasBubble()) {
accumulate_max(newWidth, _parent->minWidthForMedia());
if (!_caption.isEmpty()) {
if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) {
const auto captionWithPaddings = ::Kotato::JsonSettings::GetBool("adaptive_bubbles")
? _caption.maxWidth()
+ st::msgPadding.left()
+ st::msgPadding.right()
: 0;
accumulate_max(newWidth, captionWithPaddings);
accumulate_min(newWidth, availableWidth);
}
auto captionw = newWidth - st::msgPadding.left() - st::msgPadding.right();
newHeight += st::mediaCaptionSkip + _caption.countHeight(captionw);
if (isBubbleBottom()) {

View file

@ -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"
@ -91,9 +92,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()) {
@ -118,8 +125,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(),

View file

@ -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_message.h"
#include "history/history.h"
@ -124,10 +125,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);
@ -143,6 +152,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()) {

View file

@ -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"
@ -147,14 +148,21 @@ QSize Photo::countOptimalSize() {
auto maxWidth = 0;
auto minHeight = 0;
const auto captionWithPaddings = _caption.maxWidth()
+ st::msgPadding.left()
+ st::msgPadding.right();
auto inWebPage = (_parent->media() != this);
auto tw = style::ConvertScale(_data->width());
auto th = style::ConvertScale(_data->height());
if (!tw || !th) {
tw = th = 1;
}
if (tw > st::maxMediaSize) {
if ((!::Kotato::JsonSettings::GetBool("adaptive_bubbles") || (captionWithPaddings <= st::maxMediaSize && !inWebPage)) && tw > st::maxMediaSize) {
th = (st::maxMediaSize * th) / tw;
tw = st::maxMediaSize;
} else if (::Kotato::JsonSettings::GetBool("adaptive_bubbles") && captionWithPaddings > st::maxMediaSize && tw > captionWithPaddings) {
th = (captionWithPaddings * th) / tw;
tw = captionWithPaddings;
}
if (th > st::maxMediaSize) {
tw = (st::maxMediaSize * tw) / th;
@ -168,10 +176,14 @@ QSize Photo::countOptimalSize() {
_parent->minWidthForMedia(),
(_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize),
st::maxMediaSize);
const auto maxActualWidth = qMax(tw, minWidth);
auto maxActualWidth = qMax(tw, minWidth);
maxWidth = qMax(maxActualWidth, th);
minHeight = qMax(th, st::minPhotoSize);
if (_parent->hasBubble() && !_caption.isEmpty()) {
if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) {
maxActualWidth = qMax(maxActualWidth, captionWithPaddings);
maxWidth = qMax(maxWidth, captionWithPaddings);
}
auto captionw = maxActualWidth - st::msgPadding.left() - st::msgPadding.right();
minHeight += st::mediaCaptionSkip + _caption.countHeight(captionw);
if (isBubbleBottom()) {
@ -182,11 +194,20 @@ QSize Photo::countOptimalSize() {
}
QSize Photo::countCurrentSize(int newWidth) {
auto availableWidth = newWidth;
const auto captionWithPaddings = _caption.maxWidth()
+ st::msgPadding.left()
+ st::msgPadding.right();
auto inWebPage = (_parent->media() != this);
auto tw = style::ConvertScale(_data->width());
auto th = style::ConvertScale(_data->height());
if (tw > st::maxMediaSize) {
if ((!::Kotato::JsonSettings::GetBool("adaptive_bubbles") || (captionWithPaddings <= st::maxMediaSize && !inWebPage)) && tw > st::maxMediaSize) {
th = (st::maxMediaSize * th) / tw;
tw = st::maxMediaSize;
} else if (::Kotato::JsonSettings::GetBool("adaptive_bubbles") && captionWithPaddings > st::maxMediaSize && tw > captionWithPaddings) {
th = (captionWithPaddings * th) / tw;
tw = captionWithPaddings;
}
if (th > st::maxMediaSize) {
tw = (st::maxMediaSize * tw) / th;
@ -214,6 +235,10 @@ QSize Photo::countCurrentSize(int newWidth) {
newWidth = qMax(_pixw, minWidth);
auto newHeight = qMax(_pixh, st::minPhotoSize);
if (_parent->hasBubble() && !_caption.isEmpty()) {
if (::Kotato::JsonSettings::GetBool("adaptive_bubbles")) {
newWidth = qMax(newWidth, captionWithPaddings);
newWidth = qMin(newWidth, availableWidth);
}
const auto captionw = newWidth
- st::msgPadding.left()
- st::msgPadding.right();

View file

@ -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"
@ -306,6 +307,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();
@ -320,6 +325,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;

View file

@ -254,12 +254,19 @@ const std::map<QString, Definition, std::greater<QString>> 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<OldOptionKey, NewOptionKey, std::greater<OldOptionKey>> ReplacedOptionsMap {
{ "adaptive_baloons", "adaptive_bubbles" },
};
QString DefaultFilePath() {

View file

@ -132,6 +132,45 @@ void SetupKotatoMessages(not_null<Ui::VerticalLayout*> container) {
AddDividerText(container, rktr("ktg_settings_sticker_scale_both_about"));
AddSkip(container);
auto adaptiveBubblesButton = AddButton(
container,
rktr("ktg_settings_adaptive_bubbles"),
st::settingsButton
);
auto monospaceLargeBubblesButton = container->add(
object_ptr<Ui::SlideWrap<Button>>(
container,
CreateButton(
container,
rktr("ktg_settings_monospace_large_bubbles"),
st::settingsButton)));
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);

View file

@ -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"
@ -260,7 +261,9 @@ void Generator::addAudioBubble(QVector<int> waveform, int waveactive, QString wa
const auto &st = st::msgFileLayout;
auto tleft = st.padding.left() + st.thumbSize + st.padding.right();
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);
@ -293,7 +296,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);
@ -322,7 +327,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);