mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Changed behavior of bot menu button to decrease size to first emoji.
This commit is contained in:
parent
2e7323d484
commit
6c083e88a3
2 changed files with 60 additions and 31 deletions
|
@ -203,6 +203,18 @@ const auto kPsaAboutPrefix = "cloud_lng_about_psa_";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QString FirstEmoji(const QString &s) {
|
||||||
|
const auto begin = s.data();
|
||||||
|
const auto end = begin + s.size();
|
||||||
|
for (auto ch = begin; ch != end; ch++) {
|
||||||
|
auto length = 0;
|
||||||
|
if (const auto e = Ui::Emoji::Find(ch, end, &length)) {
|
||||||
|
return e->text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
HistoryWidget::HistoryWidget(
|
HistoryWidget::HistoryWidget(
|
||||||
|
@ -2908,8 +2920,8 @@ void HistoryWidget::updateControlsVisibility() {
|
||||||
_botKeyboardShow->hide();
|
_botKeyboardShow->hide();
|
||||||
_botKeyboardHide->hide();
|
_botKeyboardHide->hide();
|
||||||
_botCommandStart->hide();
|
_botCommandStart->hide();
|
||||||
if (_botMenuButton) {
|
if (_botMenu.button) {
|
||||||
_botMenuButton->hide();
|
_botMenu.button->hide();
|
||||||
}
|
}
|
||||||
if (_tabbedPanel) {
|
if (_tabbedPanel) {
|
||||||
_tabbedPanel->hide();
|
_tabbedPanel->hide();
|
||||||
|
@ -2977,8 +2989,8 @@ void HistoryWidget::updateControlsVisibility() {
|
||||||
} else {
|
} else {
|
||||||
_attachToggle->show();
|
_attachToggle->show();
|
||||||
}
|
}
|
||||||
if (_botMenuButton) {
|
if (_botMenu.button) {
|
||||||
_botMenuButton->show();
|
_botMenu.button->show();
|
||||||
}
|
}
|
||||||
if (_sendRestriction) {
|
if (_sendRestriction) {
|
||||||
_sendRestriction->hide();
|
_sendRestriction->hide();
|
||||||
|
@ -3055,8 +3067,8 @@ void HistoryWidget::updateControlsVisibility() {
|
||||||
if (_sendAs) {
|
if (_sendAs) {
|
||||||
_sendAs->hide();
|
_sendAs->hide();
|
||||||
}
|
}
|
||||||
if (_botMenuButton) {
|
if (_botMenu.button) {
|
||||||
_botMenuButton->hide();
|
_botMenu.button->hide();
|
||||||
}
|
}
|
||||||
_kbScroll->hide();
|
_kbScroll->hide();
|
||||||
if (_replyTo || readyToForward() || _kbReplyTo) {
|
if (_replyTo || readyToForward() || _kbReplyTo) {
|
||||||
|
@ -4803,28 +4815,35 @@ bool HistoryWidget::updateCmdStartShown() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
constexpr auto kSmallMenuAfter = 10;
|
||||||
const auto commandsChanged = (_cmdStartShown != cmdStartShown);
|
const auto commandsChanged = (_cmdStartShown != cmdStartShown);
|
||||||
auto buttonChanged = false;
|
auto buttonChanged = false;
|
||||||
if (!bot
|
if (!bot
|
||||||
|| (bot->botInfo->botMenuButtonUrl.isEmpty()
|
|| (bot->botInfo->botMenuButtonUrl.isEmpty()
|
||||||
&& bot->botInfo->commands.empty())) {
|
&& bot->botInfo->commands.empty())) {
|
||||||
buttonChanged = (_botMenuButton != nullptr);
|
buttonChanged = (_botMenu.button != nullptr);
|
||||||
_botMenuButton.destroy();
|
_botMenu.button.destroy();
|
||||||
} else if (!_botMenuButton) {
|
} else if (!_botMenu.button) {
|
||||||
buttonChanged = true;
|
buttonChanged = true;
|
||||||
_botMenuButtonText = bot->botInfo->botMenuButtonText;
|
_botMenu.text = bot->botInfo->botMenuButtonText;
|
||||||
_botMenuButton.create(
|
_botMenu.small = (Ui::FieldCharacterCount(_field) > kSmallMenuAfter);
|
||||||
|
if (_botMenu.small) {
|
||||||
|
if (const auto e = FirstEmoji(_botMenu.text); !e.isEmpty()) {
|
||||||
|
_botMenu.text = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_botMenu.button.create(
|
||||||
this,
|
this,
|
||||||
(_botMenuButtonText.isEmpty()
|
(_botMenu.text.isEmpty()
|
||||||
? tr::lng_bot_menu_button()
|
? tr::lng_bot_menu_button()
|
||||||
: rpl::single(_botMenuButtonText)),
|
: rpl::single(_botMenu.text)),
|
||||||
st::historyBotMenuButton);
|
st::historyBotMenuButton);
|
||||||
orderWidgets();
|
orderWidgets();
|
||||||
|
|
||||||
_botMenuButton->setTextTransform(
|
_botMenu.button->setTextTransform(
|
||||||
Ui::RoundButton::TextTransform::NoTransform);
|
Ui::RoundButton::TextTransform::NoTransform);
|
||||||
_botMenuButton->setFullRadius(true);
|
_botMenu.button->setFullRadius(true);
|
||||||
_botMenuButton->setClickedCallback([=] {
|
_botMenu.button->setClickedCallback([=] {
|
||||||
const auto user = _peer ? _peer->asUser() : nullptr;
|
const auto user = _peer ? _peer->asUser() : nullptr;
|
||||||
const auto bot = (user && user->isBot()) ? user : nullptr;
|
const auto bot = (user && user->isBot()) ? user : nullptr;
|
||||||
if (bot && !bot->botInfo->botMenuButtonUrl.isEmpty()) {
|
if (bot && !bot->botInfo->botMenuButtonUrl.isEmpty()) {
|
||||||
|
@ -4835,22 +4854,29 @@ bool HistoryWidget::updateCmdStartShown() {
|
||||||
_fieldAutocomplete->showFiltered(_peer, "/", true);
|
_fieldAutocomplete->showFiltered(_peer, "/", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_botMenuButton->widthValue(
|
_botMenu.button->widthValue(
|
||||||
) | rpl::start_with_next([=](int width) {
|
) | rpl::start_with_next([=](int width) {
|
||||||
if (width > st::historyBotMenuMaxWidth) {
|
if (width > st::historyBotMenuMaxWidth) {
|
||||||
_botMenuButton->setFullWidth(st::historyBotMenuMaxWidth);
|
_botMenu.button->setFullWidth(st::historyBotMenuMaxWidth);
|
||||||
} else {
|
} else {
|
||||||
updateFieldSize();
|
updateFieldSize();
|
||||||
}
|
}
|
||||||
}, _botMenuButton->lifetime());
|
}, _botMenu.button->lifetime());
|
||||||
}
|
}
|
||||||
const auto textChanged = _botMenuButton
|
const auto textSmall = Ui::FieldCharacterCount(_field) > kSmallMenuAfter;
|
||||||
&& (_botMenuButtonText != bot->botInfo->botMenuButtonText);
|
const auto textChanged = _botMenu.button
|
||||||
|
&& ((_botMenu.text != bot->botInfo->botMenuButtonText)
|
||||||
|
|| (_botMenu.small != textSmall));
|
||||||
if (textChanged) {
|
if (textChanged) {
|
||||||
_botMenuButtonText = bot->botInfo->botMenuButtonText;
|
_botMenu.text = bot->botInfo->botMenuButtonText;
|
||||||
_botMenuButton->setText(_botMenuButtonText.isEmpty()
|
if (_botMenu.small = textSmall) {
|
||||||
|
if (const auto e = FirstEmoji(_botMenu.text); !e.isEmpty()) {
|
||||||
|
_botMenu.text = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_botMenu.button->setText(_botMenu.text.isEmpty()
|
||||||
? tr::lng_bot_menu_button()
|
? tr::lng_bot_menu_button()
|
||||||
: rpl::single(_botMenuButtonText));
|
: rpl::single(_botMenu.text));
|
||||||
}
|
}
|
||||||
_cmdStartShown = cmdStartShown;
|
_cmdStartShown = cmdStartShown;
|
||||||
return commandsChanged || buttonChanged || textChanged;
|
return commandsChanged || buttonChanged || textChanged;
|
||||||
|
@ -5166,15 +5192,15 @@ void HistoryWidget::moveFieldControls() {
|
||||||
_kbScroll->setGeometryToLeft(0, bottom, width(), keyboardHeight);
|
_kbScroll->setGeometryToLeft(0, bottom, width(), keyboardHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// (_botMenuButton) (_attachToggle|_replaceMedia) (_sendAs) ---- _inlineResults ------------------------------ _tabbedPanel ------ _fieldBarCancel
|
// (_botMenu.button) (_attachToggle|_replaceMedia) (_sendAs) ---- _inlineResults ------------------------------ _tabbedPanel ------ _fieldBarCancel
|
||||||
// (_attachDocument|_attachPhoto) _field (_ttlInfo) (_scheduled) (_silent|_cmdStart|_kbShow) (_kbHide|_tabbedSelectorToggle) _send
|
// (_attachDocument|_attachPhoto) _field (_ttlInfo) (_scheduled) (_silent|_cmdStart|_kbShow) (_kbHide|_tabbedSelectorToggle) _send
|
||||||
// (_botStart|_unblock|_joinChannel|_muteUnmute|_reportMessages)
|
// (_botStart|_unblock|_joinChannel|_muteUnmute|_reportMessages)
|
||||||
|
|
||||||
auto buttonsBottom = bottom - _attachToggle->height();
|
auto buttonsBottom = bottom - _attachToggle->height();
|
||||||
auto left = st::historySendRight;
|
auto left = st::historySendRight;
|
||||||
if (_botMenuButton) {
|
if (_botMenu.button) {
|
||||||
const auto skip = st::historyBotMenuSkip;
|
const auto skip = st::historyBotMenuSkip;
|
||||||
_botMenuButton->moveToLeft(left + skip, buttonsBottom + skip); left += skip + _botMenuButton->width();
|
_botMenu.button->moveToLeft(left + skip, buttonsBottom + skip); left += skip + _botMenu.button->width();
|
||||||
}
|
}
|
||||||
if (_replaceMedia) {
|
if (_replaceMedia) {
|
||||||
_replaceMedia->moveToLeft(left, buttonsBottom);
|
_replaceMedia->moveToLeft(left, buttonsBottom);
|
||||||
|
@ -5246,8 +5272,8 @@ void HistoryWidget::updateFieldSize() {
|
||||||
- st::historySendRight
|
- st::historySendRight
|
||||||
- _send->width()
|
- _send->width()
|
||||||
- _tabbedSelectorToggle->width();
|
- _tabbedSelectorToggle->width();
|
||||||
if (_botMenuButton) {
|
if (_botMenu.button) {
|
||||||
fieldWidth -= st::historyBotMenuSkip + _botMenuButton->width();
|
fieldWidth -= st::historyBotMenuSkip + _botMenu.button->width();
|
||||||
}
|
}
|
||||||
if (_sendAs) {
|
if (_sendAs) {
|
||||||
fieldWidth -= _sendAs->width();
|
fieldWidth -= _sendAs->width();
|
||||||
|
|
|
@ -748,8 +748,11 @@ private:
|
||||||
object_ptr<Ui::FlatButton> _joinChannel;
|
object_ptr<Ui::FlatButton> _joinChannel;
|
||||||
object_ptr<Ui::FlatButton> _muteUnmute;
|
object_ptr<Ui::FlatButton> _muteUnmute;
|
||||||
object_ptr<Ui::FlatButton> _reportMessages;
|
object_ptr<Ui::FlatButton> _reportMessages;
|
||||||
object_ptr<Ui::RoundButton> _botMenuButton = { nullptr };
|
struct {
|
||||||
QString _botMenuButtonText;
|
object_ptr<Ui::RoundButton> button = { nullptr };
|
||||||
|
QString text;
|
||||||
|
bool small = false;
|
||||||
|
} _botMenu;
|
||||||
object_ptr<Ui::IconButton> _attachToggle;
|
object_ptr<Ui::IconButton> _attachToggle;
|
||||||
object_ptr<Ui::IconButton> _replaceMedia = { nullptr };
|
object_ptr<Ui::IconButton> _replaceMedia = { nullptr };
|
||||||
object_ptr<Ui::SendAsButton> _sendAs = { nullptr };
|
object_ptr<Ui::SendAsButton> _sendAs = { nullptr };
|
||||||
|
|
Loading…
Add table
Reference in a new issue