From f4d59609539c1cccb632d1ce7374fdd95910b898 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 12 Aug 2016 19:24:59 +0300 Subject: [PATCH] Improved design of the bot command autocomplete. --- .../history/field_autocomplete.cpp | 35 ++++++------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/Telegram/SourceFiles/history/field_autocomplete.cpp b/Telegram/SourceFiles/history/field_autocomplete.cpp index a814fa9bd4..bf8687542c 100644 --- a/Telegram/SourceFiles/history/field_autocomplete.cpp +++ b/Telegram/SourceFiles/history/field_autocomplete.cpp @@ -677,32 +677,19 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { user->loadUserpic(); user->paintUserpicLeft(p, st::mentionPhotoSize, st::mentionPadding.left(), i * st::mentionHeight + st::mentionPadding.top(), width()); - int32 addleft = 0, widthleft = mentionwidth; - QString first = filterIsEmpty ? QString() : ('/' + toHighlight.mid(0, filterSize)); - QString second = filterIsEmpty ? ('/' + toHighlight) : toHighlight.mid(filterSize); - int32 firstwidth = st::mentionFont->width(first), secondwidth = st::mentionFont->width(second); - if (widthleft < firstwidth + secondwidth) { - if (widthleft < firstwidth + st::mentionFont->elidew) { - first = st::mentionFont->elided(first + second, widthleft); - second = QString(); - } else { - second = st::mentionFont->elided(second, widthleft - firstwidth); - } - } - p.setFont(st::mentionFont->f); - if (!first.isEmpty()) { - p.setPen((selected ? st::mentionFgOverActive : st::mentionFgActive)->p); - p.drawText(mentionleft, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, first); - } - if (!second.isEmpty()) { - p.setPen((selected ? st::mentionFgOver : st::mentionFg)->p); - p.drawText(mentionleft + firstwidth, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, second); - } - addleft += firstwidth + secondwidth + st::mentionPadding.left(); - widthleft -= firstwidth + secondwidth + st::mentionPadding.left(); + auto commandText = '/' + toHighlight; + + p.setPen(st::windowTextFg); + p.setFont(st::semiboldFont); + p.drawText(2 * st::mentionPadding.left() + st::mentionPhotoSize, i * st::mentionHeight + st::mentionTop + st::semiboldFont->ascent, commandText); + + auto commandTextWidth = st::semiboldFont->width(commandText); + auto addleft = commandTextWidth + st::mentionPadding.left(); + auto widthleft = mentionwidth - addleft; + if (widthleft > st::mentionFont->elidew && !command->descriptionText().isEmpty()) { p.setPen((selected ? st::mentionFgOver : st::mentionFg)->p); - command->descriptionText().drawElided(p, mentionleft + addleft, i * st::mentionHeight + st::mentionTop, widthleft, 1, style::al_right); + command->descriptionText().drawElided(p, mentionleft + addleft, i * st::mentionHeight + st::mentionTop, widthleft); } } }