mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Slightly refactored text drawing in VoiceRecordBar.
This commit is contained in:
parent
b6743feec1
commit
cdb77d46b1
3 changed files with 54 additions and 20 deletions
|
@ -253,18 +253,27 @@ void VoiceRecordBar::updateControlsGeometry(QSize size) {
|
||||||
_cancelFont->width(FormatVoiceDuration(kMaxSamples)),
|
_cancelFont->width(FormatVoiceDuration(kMaxSamples)),
|
||||||
_redCircleRect.height());
|
_redCircleRect.height());
|
||||||
}
|
}
|
||||||
{
|
updateMessageGeometry();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoiceRecordBar::updateMessageGeometry() {
|
||||||
const auto left = _durationRect.x()
|
const auto left = _durationRect.x()
|
||||||
+ _durationRect.width()
|
+ _durationRect.width()
|
||||||
+ ((_send->width() - st::historyRecordVoice.width()) / 2);
|
+ st::historyRecordTextLeft;
|
||||||
const auto right = width() - _send->width();
|
const auto right = width()
|
||||||
const auto width = _cancelFont->width(cancelMessage());
|
- _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(
|
_messageRect = QRect(
|
||||||
left + (right - left - width) / 2,
|
left + (right - left - width) / 2,
|
||||||
st::historyRecordTextTop,
|
(height() - textHeight) / 2,
|
||||||
width + st::historyRecordDurationSkip,
|
width,
|
||||||
_cancelFont->height);
|
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 {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue