Correct String::countHeight with breakEverywhere.
This commit is contained in:
parent
6fb693f606
commit
00393b7b3b
3 changed files with 22 additions and 17 deletions
|
|
@ -2890,13 +2890,13 @@ bool String::removeSkipBlock() {
|
|||
return true;
|
||||
}
|
||||
|
||||
int String::countWidth(int width) const {
|
||||
int String::countWidth(int width, bool breakEverywhere) const {
|
||||
if (QFixed(width) >= _maxWidth) {
|
||||
return _maxWidth.ceil().toInt();
|
||||
}
|
||||
|
||||
QFixed maxLineWidth = 0;
|
||||
enumerateLines(width, [&maxLineWidth](QFixed lineWidth, int lineHeight) {
|
||||
enumerateLines(width, breakEverywhere, [&](QFixed lineWidth, int lineHeight) {
|
||||
if (lineWidth > maxLineWidth) {
|
||||
maxLineWidth = lineWidth;
|
||||
}
|
||||
|
|
@ -2904,25 +2904,28 @@ int String::countWidth(int width) const {
|
|||
return maxLineWidth.ceil().toInt();
|
||||
}
|
||||
|
||||
int String::countHeight(int width) const {
|
||||
int String::countHeight(int width, bool breakEverywhere) const {
|
||||
if (QFixed(width) >= _maxWidth) {
|
||||
return _minHeight;
|
||||
}
|
||||
int result = 0;
|
||||
enumerateLines(width, [&result](QFixed lineWidth, int lineHeight) {
|
||||
enumerateLines(width, breakEverywhere, [&](QFixed lineWidth, int lineHeight) {
|
||||
result += lineHeight;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
void String::countLineWidths(int width, QVector<int> *lineWidths) const {
|
||||
enumerateLines(width, [lineWidths](QFixed lineWidth, int lineHeight) {
|
||||
void String::countLineWidths(int width, QVector<int> *lineWidths, bool breakEverywhere) const {
|
||||
enumerateLines(width, breakEverywhere, [&](QFixed lineWidth, int lineHeight) {
|
||||
lineWidths->push_back(lineWidth.ceil().toInt());
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
void String::enumerateLines(int w, Callback callback) const {
|
||||
void String::enumerateLines(
|
||||
int w,
|
||||
bool breakEverywhere,
|
||||
Callback callback) const {
|
||||
QFixed width = w;
|
||||
if (width < _minResizeWidth) width = _minResizeWidth;
|
||||
|
||||
|
|
@ -2994,7 +2997,7 @@ void String::enumerateLines(int w, Callback callback) const {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (f != j) {
|
||||
if (f != j && !breakEverywhere) {
|
||||
j = f;
|
||||
widthLeft = f_wLeft;
|
||||
lineHeight = f_lineHeight;
|
||||
|
|
|
|||
|
|
@ -114,9 +114,9 @@ public:
|
|||
String &operator=(const String &other);
|
||||
String &operator=(String &&other);
|
||||
|
||||
int countWidth(int width) const;
|
||||
int countHeight(int width) const;
|
||||
void countLineWidths(int width, QVector<int> *lineWidths) const;
|
||||
int countWidth(int width, bool breakEverywhere = false) const;
|
||||
int countHeight(int width, bool breakEverywhere = false) const;
|
||||
void countLineWidths(int width, QVector<int> *lineWidths, bool breakEverywhere = false) const;
|
||||
void setText(const style::TextStyle &st, const QString &text, const TextParseOptions &options = _defaultOptions);
|
||||
void setRichText(const style::TextStyle &st, const QString &text, TextParseOptions options = _defaultOptions);
|
||||
void setMarkedText(const style::TextStyle &st, const TextWithEntities &textWithEntities, const TextParseOptions &options = _defaultOptions);
|
||||
|
|
@ -208,7 +208,7 @@ private:
|
|||
// callback(lineWidth, lineHeight) will be called for all lines with:
|
||||
// QFixed lineWidth, int lineHeight
|
||||
template <typename Callback>
|
||||
void enumerateLines(int w, Callback callback) const;
|
||||
void enumerateLines(int w, bool breakEverywhere, Callback callback) const;
|
||||
|
||||
void recountNaturalSize(bool initial, Qt::LayoutDirection optionsDir = Qt::LayoutDirectionAuto);
|
||||
|
||||
|
|
|
|||
|
|
@ -266,10 +266,10 @@ int FlatLabel::countTextWidth() const {
|
|||
&& _tryMakeSimilarLines) {
|
||||
auto large = _allowedWidth;
|
||||
auto small = _allowedWidth / 2;
|
||||
const auto largeHeight = _text.countHeight(large);
|
||||
const auto largeHeight = _text.countHeight(large, _breakEverywhere);
|
||||
while (large - small > 1) {
|
||||
const auto middle = (large + small) / 2;
|
||||
if (largeHeight == _text.countHeight(middle)) {
|
||||
if (largeHeight == _text.countHeight(middle, _breakEverywhere)) {
|
||||
large = middle;
|
||||
} else {
|
||||
small = middle;
|
||||
|
|
@ -281,8 +281,10 @@ int FlatLabel::countTextWidth() const {
|
|||
}
|
||||
|
||||
int FlatLabel::countTextHeight(int textWidth) {
|
||||
_fullTextHeight = _text.countHeight(textWidth);
|
||||
return _st.maxHeight ? qMin(_fullTextHeight, _st.maxHeight) : _fullTextHeight;
|
||||
_fullTextHeight = _text.countHeight(textWidth, _breakEverywhere);
|
||||
return _st.maxHeight
|
||||
? qMin(_fullTextHeight, _st.maxHeight)
|
||||
: _fullTextHeight;
|
||||
}
|
||||
|
||||
void FlatLabel::refreshSize() {
|
||||
|
|
@ -693,7 +695,7 @@ std::unique_ptr<CrossFadeAnimation> FlatLabel::CrossFade(
|
|||
auto result = Data();
|
||||
result.full = GrabWidgetToImage(label, QRect(), bg->c);
|
||||
auto textWidth = label->width() - label->_st.margin.left() - label->_st.margin.right();
|
||||
label->_text.countLineWidths(textWidth, &result.lineWidths);
|
||||
label->_text.countLineWidths(textWidth, &result.lineWidths, label->_breakEverywhere);
|
||||
result.lineHeight = label->_st.style.font->height;
|
||||
auto addedHeight = (label->_st.style.lineHeight - result.lineHeight);
|
||||
if (addedHeight > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue