Use FlatLabel::textMaxWidth.

This commit is contained in:
John Preston 2023-08-17 13:54:01 +02:00
parent 632626b192
commit b3580f7987
4 changed files with 14 additions and 11 deletions

View file

@ -250,11 +250,11 @@ void BoxLayerWidget::updateTitlePosition() {
_titleLeft = st::boxTitlePosition.x();
_titleTop = st::boxTitlePosition.y();
if (_title) {
const auto topButtonSkip = _topButton ? (_topButton->width() / 2) : 0;
_title->resizeToWidth(
std::min(
_title->naturalWidth(),
width() - _titleLeft * 2 - topButtonSkip));
const auto topButtonSkip = _topButton
? (_topButton->width() / 2)
: 0;
_title->resizeToNaturalWidth(
width() - _titleLeft * 2 - topButtonSkip);
_title->moveToLeft(_titleLeft, _titleTop);
}
}

View file

@ -199,8 +199,8 @@ public:
// Resize to minimum of natural width and available width.
void resizeToNaturalWidth(int newWidth) {
auto maxWidth = naturalWidth();
resizeToWidth((maxWidth >= 0) ? qMin(newWidth, maxWidth) : newWidth);
const auto natural = naturalWidth();
resizeToWidth((natural >= 0) ? qMin(newWidth, natural) : newWidth);
}
QRect rectNoMargins() const {

View file

@ -65,8 +65,8 @@ void MultilineAction::paintEvent(QPaintEvent *e) {
void MultilineAction::updateMinWidth() {
const auto skip = _labelPosition.x();
auto min = _text->naturalWidth() / 2;
auto max = _icon ? _st.widthMax : (_text->naturalWidth() - skip);
auto min = _text->textMaxWidth() / 2;
auto max = _icon ? _st.widthMax : (_text->textMaxWidth() - skip);
_text->resizeToWidth(max);
const auto height = _icon
? ((_st.itemIconPosition.y() * 2) + _icon->height())

View file

@ -446,10 +446,13 @@ object_ptr<FlatLabel> MakeNiceTooltipLabel(
stMenu);
const auto raw = result.data();
std::move(text) | rpl::start_with_next([=, &st] {
raw->resizeToNaturalWidth(maxWidth);
if (raw->naturalWidth() <= maxWidth) {
raw->resizeToWidth(qMin(maxWidth, raw->textMaxWidth()));
const auto desired = raw->textMaxWidth();
if (desired <= maxWidth) {
raw->resizeToWidth(desired);
return;
}
raw->resizeToWidth(maxWidth);
const auto niceWidth = FindNiceTooltipWidth(
st.minWidth,
maxWidth,