Use FlatLabel::textMaxWidth.

This commit is contained in:
John Preston 2023-08-17 13:54:53 +02:00
parent 4b0c4eee30
commit 311691a3bc
10 changed files with 19 additions and 22 deletions

View File

@ -403,7 +403,7 @@ not_null<Ui::RpWidget*> AddInnerToggle(
(s.height() - label->height()) / 2); (s.height() - label->height()) / 2);
arrow->moveToLeft( arrow->moveToLeft(
std::min( std::min(
labelLeft + label->naturalWidth(), labelLeft + label->textMaxWidth(),
labelRight - arrow->width()), labelRight - arrow->width()),
(s.height() - arrow->height()) / 2); (s.height() - arrow->height()) / 2);
}, button->lifetime()); }, button->lifetime());

View File

@ -731,14 +731,14 @@ void TopBar::updateControlsGeometry() {
width() - _mute->width() - _hangup->width(), width() - _mute->width() - _hangup->width(),
height()); height());
auto fullWidth = _fullInfoLabel->naturalWidth(); auto fullWidth = _fullInfoLabel->textMaxWidth();
auto showFull = (left + fullWidth + right <= width()); auto showFull = (left + fullWidth + right <= width());
_fullInfoLabel->setVisible(showFull); _fullInfoLabel->setVisible(showFull);
_shortInfoLabel->setVisible(!showFull); _shortInfoLabel->setVisible(!showFull);
auto setInfoLabelGeometry = [this, left, right](auto &&infoLabel) { auto setInfoLabelGeometry = [this, left, right](auto &&infoLabel) {
auto minPadding = qMax(left, right); auto minPadding = qMax(left, right);
auto infoWidth = infoLabel->naturalWidth(); auto infoWidth = infoLabel->textMaxWidth();
auto infoLeft = (width() - infoWidth) / 2; auto infoLeft = (width() - infoWidth) / 2;
if (infoLeft < minPadding) { if (infoLeft < minPadding) {
infoLeft = left; infoLeft = left;

View File

@ -2060,7 +2060,7 @@ void Panel::showNiceTooltip(
(normal ? widget().get() : container), (normal ? widget().get() : container),
std::move(text), std::move(text),
st::groupCallNiceTooltipLabel); st::groupCallNiceTooltipLabel);
label->resizeToNaturalWidth(label->naturalWidth()); label->resizeToWidth(label->textMaxWidth());
if (normal) { if (normal) {
return label; return label;
} }
@ -2522,8 +2522,8 @@ void Panel::refreshTitleGeometry() {
fullRect.height()) fullRect.height())
: fullRect; : fullRect;
const auto sep = st::groupCallTitleSeparator; const auto sep = st::groupCallTitleSeparator;
const auto best = _title->naturalWidth() + (_viewers const auto best = _title->textMaxWidth() + (_viewers
? (_titleSeparator->width() + sep * 2 + _viewers->naturalWidth()) ? (_titleSeparator->width() + sep * 2 + _viewers->textMaxWidth())
: 0); : 0);
const auto from = (widget()->width() - best) / 2; const auto from = (widget()->width() - best) / 2;
const auto shownTop = (mode() == PanelMode::Default) const auto shownTop = (mode() == PanelMode::Default)
@ -2541,8 +2541,8 @@ void Panel::refreshTitleGeometry() {
const auto left = titleRect.x(); const auto left = titleRect.x();
const auto notEnough = std::max(0, best - titleRect.width()); const auto notEnough = std::max(0, best - titleRect.width());
const auto titleMaxWidth = _title->naturalWidth(); const auto titleMaxWidth = _title->textMaxWidth();
const auto viewersMaxWidth = _viewers ? _viewers->naturalWidth() : 0; const auto viewersMaxWidth = _viewers ? _viewers->textMaxWidth() : 0;
const auto viewersNotEnough = std::clamp( const auto viewersNotEnough = std::clamp(
viewersMaxWidth - titleMaxWidth, viewersMaxWidth - titleMaxWidth,
0, 0,
@ -2551,9 +2551,9 @@ void Panel::refreshTitleGeometry() {
(notEnough - std::abs(viewersMaxWidth - titleMaxWidth)) / 2, (notEnough - std::abs(viewersMaxWidth - titleMaxWidth)) / 2,
0); 0);
_title->resizeToWidth( _title->resizeToWidth(
_title->naturalWidth() - (notEnough - viewersNotEnough)); _title->textMaxWidth() - (notEnough - viewersNotEnough));
if (_viewers) { if (_viewers) {
_viewers->resizeToWidth(_viewers->naturalWidth() - viewersNotEnough); _viewers->resizeToWidth(_viewers->textMaxWidth() - viewersNotEnough);
} }
const auto layout = [&](int position) { const auto layout = [&](int position) {
_title->moveToLeft(position, top); _title->moveToLeft(position, top);

View File

@ -2818,12 +2818,9 @@ void InnerWidget::resizeEmptyLabel() {
if (!_empty) { if (!_empty) {
return; return;
} }
const auto useWidth = std::min( const auto skip = st::dialogsEmptySkip;
_empty->naturalWidth(), _empty->resizeToWidth(width() - 2 * skip);
width() - 2 * st::dialogsEmptySkip); _empty->move(skip, (st::dialogsEmptyHeight - _empty->height()) / 2);
const auto left = (width() - useWidth) / 2;
_empty->resizeToWidth(useWidth);
_empty->move(left, (st::dialogsEmptyHeight - _empty->height()) / 2);
} }
void InnerWidget::clearMouseSelection(bool clearSelection) { void InnerWidget::clearMouseSelection(bool clearSelection) {

View File

@ -310,7 +310,7 @@ void TranslateBar::setup(not_null<History*> history) {
const auto updateLabelGeometry = [=] { const auto updateLabelGeometry = [=] {
const auto full = _wrap.width() - icon->width(); const auto full = _wrap.width() - icon->width();
const auto skip = st::semiboldFont->spacew * 2; const auto skip = st::semiboldFont->spacew * 2;
const auto natural = label->naturalWidth(); const auto natural = label->textMaxWidth();
const auto top = [&] { const auto top = [&] {
return (_wrap.height() - label->height()) / 2; return (_wrap.height() - label->height()) / 2;
}; };

View File

@ -52,7 +52,7 @@ private:
return label->height(); return label->height();
}; };
auto widthMin = basicWidth; auto widthMin = basicWidth;
auto widthMax = label->naturalWidth(); auto widthMax = label->textMaxWidth();
if (height(widthMin) <= heightLimit || height(widthMax) > heightLimit) { if (height(widthMin) <= heightLimit || height(widthMax) > heightLimit) {
return basicWidth; return basicWidth;
} }

View File

@ -356,7 +356,7 @@ void Header::show(HeaderData data) {
_widget.get(), _widget.get(),
std::move(counter), std::move(counter),
st::storiesHeaderDate); st::storiesHeaderDate);
_counter->resizeToNaturalWidth(_counter->naturalWidth()); _counter->resizeToWidth(_counter->textMaxWidth());
_counter->setAttribute(Qt::WA_TransparentForMouseEvents); _counter->setAttribute(Qt::WA_TransparentForMouseEvents);
_counter->setOpacity(kNameOpacity); _counter->setOpacity(kNameOpacity);
_counter->show(); _counter->show();

View File

@ -322,7 +322,7 @@ struct SimpleFieldState {
QString(), QString(),
st::paymentsFieldAdditional); st::paymentsFieldAdditional);
const auto leftSkip = state->left const auto leftSkip = state->left
? (state->left->naturalWidth() + state->currencySkip) ? (state->left->textMaxWidth() + state->currencySkip)
: 0; : 0;
const auto rightSkip = st::paymentsFieldAdditional.style.font->width( const auto rightSkip = st::paymentsFieldAdditional.style.font->width(
QString(QChar(rule.decimal)) QString(QChar(rule.decimal))

View File

@ -305,7 +305,7 @@ void FormSummary::setupPrices(not_null<VerticalLayout*> layout) {
padding.left(), padding.left(),
padding.top(), padding.top(),
(padding.right() (padding.right()
+ right->naturalWidth() + right->textMaxWidth()
+ 2 * st.style.font->spacew), + 2 * st.style.font->spacew),
padding.bottom())); padding.bottom()));
rpl::combine( rpl::combine(

@ -1 +1 @@
Subproject commit 632626b1921e99aaea6d02a9f7ebbb6354161365 Subproject commit b3580f7987d81b0c7aecee99f7f70f7873f6b35c