From 95bdb925d5424f1126560b5975aea3db434784eb Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 20 Aug 2024 16:10:27 +0200 Subject: [PATCH] Fix paddings in text messages disabler. --- .../chat_helpers/message_field.cpp | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index b3c53942d..8c4a86ea1 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -1063,10 +1063,26 @@ base::unique_qptr CreateDisabledFieldView( st::historySendDisabled); label->setAttribute(Qt::WA_TransparentForMouseEvents); raw->setPointerCursor(false); + + const auto &st = st::historyComposeField; + + const auto metrics = QFontMetricsF(st.style.font->f); + const auto realAscent = int(base::SafeRound(metrics.ascent())); + const auto ascentAdd = st.style.font->ascent - realAscent; + const auto customFontMarginTop = ascentAdd; + const auto leading = qMax(metrics.leading(), qreal(0.0)); + const auto adjustment = (metrics.ascent() + leading) + - ((st.style.font->height * 4) / 5); + const auto placeholderCustomFontSkip = int(base::SafeRound(-adjustment)); + + const auto margins = st.textMargins + + st.placeholderMargins + + QMargins(0, style::ConvertScale(4) + + placeholderCustomFontSkip + + customFontMarginTop, 0, 0); + raw->widthValue( ) | rpl::start_with_next([=](int width) { - const auto &st = st::historyComposeField; - const auto margins = (st.textMargins + st.placeholderMargins); const auto available = width - margins.left() - margins.right(); const auto skip = st::historySendDisabledIconSkip; label->resizeToWidth(available - skip); @@ -1075,8 +1091,6 @@ base::unique_qptr CreateDisabledFieldView( raw->paintRequest( ) | rpl::start_with_next([=] { auto p = QPainter(raw); - const auto &st = st::historyComposeField; - const auto margins = (st.textMargins + st.placeholderMargins); const auto &icon = st::historySendDisabledIcon; icon.paint( p,