Slightly refactored text drawing in VoiceRecordBar.

This commit is contained in:
23rd 2020-10-10 15:03:28 +03:00 committed by John Preston
parent b6743feec1
commit cdb77d46b1
3 changed files with 54 additions and 20 deletions

View file

@ -253,18 +253,27 @@ void VoiceRecordBar::updateControlsGeometry(QSize size) {
_cancelFont->width(FormatVoiceDuration(kMaxSamples)), _cancelFont->width(FormatVoiceDuration(kMaxSamples)),
_redCircleRect.height()); _redCircleRect.height());
} }
{ updateMessageGeometry();
const auto left = _durationRect.x() }
+ _durationRect.width()
+ ((_send->width() - st::historyRecordVoice.width()) / 2); void VoiceRecordBar::updateMessageGeometry() {
const auto right = width() - _send->width(); const auto left = _durationRect.x()
const auto width = _cancelFont->width(cancelMessage()); + _durationRect.width()
_messageRect = QRect( + st::historyRecordTextLeft;
left + (right - left - width) / 2, const auto right = width()
st::historyRecordTextTop, - _send->width()
width + st::historyRecordDurationSkip, - st::historyRecordTextRight;
_cancelFont->height); const auto textWidth = _message.maxWidth();
} const auto width = ((right - left) < textWidth)
? st::historyRecordTextWidthForWrap
: textWidth;
const auto countLines = std::ceil((float)textWidth / width);
const auto textHeight = _message.minHeight() * countLines;
_messageRect = QRect(
left + (right - left - width) / 2,
(height() - textHeight) / 2,
width,
textHeight);
} }
void VoiceRecordBar::init() { void VoiceRecordBar::init() {
@ -334,10 +343,6 @@ void VoiceRecordBar::init() {
_lock->hide(); _lock->hide();
_lock->locks( _lock->locks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
updateControlsGeometry(rect().size());
update(_messageRect);
installClickOutsideFilter(); installClickOutsideFilter();
_send->clicks( _send->clicks(
@ -365,6 +370,22 @@ void VoiceRecordBar::init() {
_inField = enter; _inField = enter;
}, _recordingLifetime); }, _recordingLifetime);
}, lifetime()); }, lifetime());
rpl::merge(
_lock->locks(),
shownValue() | rpl::to_empty
) | rpl::start_with_next([=] {
const auto direction = Qt::LayoutDirectionAuto;
_message.setText(
st::historyRecordTextStyle,
_lock->isLocked()
? tr::lng_record_lock_cancel(tr::now)
: tr::lng_record_cancel(tr::now),
TextParseOptions{ TextParseMultiline, 0, 0, direction });
updateMessageGeometry();
update(_messageRect);
}, lifetime());
} }
void VoiceRecordBar::activeAnimate(bool active) { void VoiceRecordBar::activeAnimate(bool active) {
@ -563,10 +584,13 @@ void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) {
st::historyRecordCancel, st::historyRecordCancel,
st::historyRecordCancelActive, st::historyRecordCancelActive,
1. - recordActive)); 1. - recordActive));
p.drawText(
_message.draw(
p,
_messageRect.x(), _messageRect.x(),
_messageRect.y() + _cancelFont->ascent, _messageRect.y(),
cancelMessage()); _messageRect.width(),
style::al_center);
} }
rpl::producer<SendActionUpdate> VoiceRecordBar::sendActionUpdates() const { rpl::producer<SendActionUpdate> VoiceRecordBar::sendActionUpdates() const {

View file

@ -55,6 +55,7 @@ private:
void init(); void init();
void updateControlsGeometry(QSize size); void updateControlsGeometry(QSize size);
void updateMessageGeometry();
void recordError(); void recordError();
void recordUpdated(quint16 level, int samples); void recordUpdated(quint16 level, int samples);
@ -94,6 +95,8 @@ private:
QRect _durationRect; QRect _durationRect;
QRect _messageRect; QRect _messageRect;
Ui::Text::String _message;
Fn<bool()> _escFilter; Fn<bool()> _escFilter;
rpl::variable<bool> _recording = false; rpl::variable<bool> _recording = false;

View file

@ -344,7 +344,14 @@ historyRecordCancelActive: windowActiveTextFg;
historyRecordFont: font(13px); historyRecordFont: font(13px);
historyRecordDurationSkip: 12px; historyRecordDurationSkip: 12px;
historyRecordDurationFg: historyComposeAreaFg; historyRecordDurationFg: historyComposeAreaFg;
historyRecordTextTop: 14px;
historyRecordTextStyle: TextStyle(defaultTextStyle) {
font: historyRecordFont;
}
historyRecordTextWidthForWrap: 210px;
historyRecordTextLeft: 15px;
historyRecordTextRight: 25px;
historyRecordLockShowDuration: historyToDownDuration; historyRecordLockShowDuration: historyToDownDuration;
historyRecordLockSize: size(75px, 150px); historyRecordLockSize: size(75px, 150px);