From 7be286751b4f1374334db55df48ea3a5f5b303e2 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 24 Aug 2019 13:24:49 +0300 Subject: [PATCH] Fixed text width in toast widget. - Fixed #6381. --- Telegram/SourceFiles/ui/toast/toast_widget.cpp | 6 +++--- Telegram/SourceFiles/ui/toast/toast_widget.h | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/ui/toast/toast_widget.cpp b/Telegram/SourceFiles/ui/toast/toast_widget.cpp index 480358ed9..b1e4ec7af 100644 --- a/Telegram/SourceFiles/ui/toast/toast_widget.cpp +++ b/Telegram/SourceFiles/ui/toast/toast_widget.cpp @@ -17,10 +17,10 @@ Widget::Widget(QWidget *parent, const Config &config) : TWidget(parent) , _multiline(config.multiline) , _maxWidth((config.maxWidth > 0) ? config.maxWidth : st::toastMaxWidth) , _padding((config.padding.left() > 0) ? config.padding : st::toastPadding) -, _maxTextWidth(_maxWidth - _padding.left() - _padding.right()) +, _maxTextWidth(widthWithoutPadding(_maxWidth)) , _maxTextHeight( st::toastTextStyle.font->height * (_multiline ? config.maxLines : 1)) -, _text(_multiline ? config.minWidth : QFIXED_MAX) { +, _text(_multiline ? widthWithoutPadding(config.minWidth) : QFIXED_MAX) { const auto toastOptions = TextParseOptions{ TextParseMultiline, _maxTextWidth, @@ -42,7 +42,7 @@ void Widget::onParentResized() { auto newWidth = _maxWidth; accumulate_min(newWidth, _padding.left() + _text.maxWidth() + _padding.right()); accumulate_min(newWidth, parentWidget()->width() - 2 * st::toastMinMargin); - _textWidth = newWidth - _padding.left() - _padding.right(); + _textWidth = widthWithoutPadding(newWidth); const auto textHeight = _multiline ? qMin(_text.countHeight(_textWidth), _maxTextHeight) : _text.minHeight(); diff --git a/Telegram/SourceFiles/ui/toast/toast_widget.h b/Telegram/SourceFiles/ui/toast/toast_widget.h index 17804ef07..9879ab780 100644 --- a/Telegram/SourceFiles/ui/toast/toast_widget.h +++ b/Telegram/SourceFiles/ui/toast/toast_widget.h @@ -28,6 +28,10 @@ protected: void paintEvent(QPaintEvent *e) override; private: + inline int widthWithoutPadding(int w) { + return w - _padding.left() - _padding.right(); + } + float64 _shownLevel = 0; bool _multiline = false; int _maxWidth = 0;