diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 6a30d790c5..9c8b6c3f95 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -2445,21 +2445,6 @@ int BotKeyboard::Style::minButtonWidth(HistoryMessageReplyMarkup::Button::Type t return result; } -void BotKeyboard::resizeEvent(QResizeEvent *e) { - if (!_impl) return; - - updateStyle(); - - _height = _impl->naturalHeight() + st::botKbScroll.deltat + st::botKbScroll.deltab; - if (_maximizeSize) _height = qMax(_height, _maxOuterHeight); - if (height() != _height) { - resize(width(), _height); - return; - } - - _impl->resize(width() - _st->margin - st::botKbScroll.width, _height - (st::botKbScroll.deltat + st::botKbScroll.deltab)); -} - void BotKeyboard::mousePressEvent(QMouseEvent *e) { _lastMousePos = e->globalPos(); updateSelected(); @@ -2529,14 +2514,8 @@ bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) { } } - updateStyle(); - _height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0); - if (_maximizeSize) _height = qMax(_height, _maxOuterHeight); - if (height() != _height) { - resize(width(), _height); - } else { - resizeEvent(nullptr); - } + resizeToWidth(width(), _maxOuterHeight); + return true; } @@ -2548,13 +2527,23 @@ bool BotKeyboard::forceReply() const { return _forceReply; } -void BotKeyboard::resizeToWidth(int width, int maxOuterHeight) { - updateStyle(width); - _height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0); +void BotKeyboard::resizeToWidth(int newWidth, int maxOuterHeight) { _maxOuterHeight = maxOuterHeight; - if (_maximizeSize) _height = qMax(_height, _maxOuterHeight); - resize(width, _height); + updateStyle(newWidth); + _height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0); + if (_maximizeSize) { + accumulate_max(_height, _maxOuterHeight); + } + if (_impl) { + int implWidth = newWidth - _st->margin - st::botKbScroll.width; + int implHeight = _height - (st::botKbScroll.deltat + st::botKbScroll.deltab); + _impl->resize(implWidth, implHeight); + } + QSize newSize(newWidth, _height); + if (newSize != size()) { + resize(newSize); + } } bool BotKeyboard::maximizeSize() const { @@ -2565,10 +2554,10 @@ bool BotKeyboard::singleUse() const { return _singleUse; } -void BotKeyboard::updateStyle(int32 w) { +void BotKeyboard::updateStyle(int newWidth) { if (!_impl) return; - int implWidth = ((w < 0) ? width() : w) - st::botKbButton.margin - st::botKbScroll.width; + int implWidth = newWidth - st::botKbButton.margin - st::botKbScroll.width; _st = _impl->isEnoughSpace(implWidth, st::botKbButton) ? &st::botKbButton : &st::botKbTinyButton; _impl->setStyle(std_::make_unique