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)),
_redCircleRect.height());
}
{
updateMessageGeometry();
}
void VoiceRecordBar::updateMessageGeometry() {
const auto left = _durationRect.x()
+ _durationRect.width()
+ ((_send->width() - st::historyRecordVoice.width()) / 2);
const auto right = width() - _send->width();
const auto width = _cancelFont->width(cancelMessage());
+ st::historyRecordTextLeft;
const auto right = width()
- _send->width()
- st::historyRecordTextRight;
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,
st::historyRecordTextTop,
width + st::historyRecordDurationSkip,
_cancelFont->height);
}
(height() - textHeight) / 2,
width,
textHeight);
}
void VoiceRecordBar::init() {
@ -334,10 +343,6 @@ void VoiceRecordBar::init() {
_lock->hide();
_lock->locks(
) | rpl::start_with_next([=] {
updateControlsGeometry(rect().size());
update(_messageRect);
installClickOutsideFilter();
_send->clicks(
@ -365,6 +370,22 @@ void VoiceRecordBar::init() {
_inField = enter;
}, _recordingLifetime);
}, 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) {
@ -563,10 +584,13 @@ void VoiceRecordBar::drawMessage(Painter &p, float64 recordActive) {
st::historyRecordCancel,
st::historyRecordCancelActive,
1. - recordActive));
p.drawText(
_message.draw(
p,
_messageRect.x(),
_messageRect.y() + _cancelFont->ascent,
cancelMessage());
_messageRect.y(),
_messageRect.width(),
style::al_center);
}
rpl::producer<SendActionUpdate> VoiceRecordBar::sendActionUpdates() const {

View File

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

View File

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