Added index for spoiler to AbstractBox.

This commit is contained in:
23rd 2021-12-18 15:34:53 +03:00
parent 0524252197
commit e19a4c6544
3 changed files with 52 additions and 23 deletions

View file

@ -450,13 +450,13 @@ void Parser::createBlock(int32 skipBack) {
} }
_lastSkipped = false; _lastSkipped = false;
if (_emoji) { if (_emoji) {
_t->_blocks.push_back(Block::Emoji(_t->_st->font, _t->_text, _blockStart, len, _flags, _lnkIndex, _emoji)); _t->_blocks.push_back(Block::Emoji(_t->_st->font, _t->_text, _blockStart, len, _flags, _lnkIndex, 0/*spoilerIndex*/, _emoji));
_emoji = nullptr; _emoji = nullptr;
_lastSkipped = true; _lastSkipped = true;
} else if (newline) { } else if (newline) {
_t->_blocks.push_back(Block::Newline(_t->_st->font, _t->_text, _blockStart, len, _flags, _lnkIndex)); _t->_blocks.push_back(Block::Newline(_t->_st->font, _t->_text, _blockStart, len, _flags, _lnkIndex, 0/*spoilerIndex*/));
} else { } else {
_t->_blocks.push_back(Block::Text(_t->_st->font, _t->_text, _t->_minResizeWidth, _blockStart, len, _flags, _lnkIndex)); _t->_blocks.push_back(Block::Text(_t->_st->font, _t->_text, _t->_minResizeWidth, _blockStart, len, _flags, _lnkIndex, 0/*spoilerIndex*/));
} }
_blockStart += len; _blockStart += len;
blockCreated(); blockCreated();
@ -466,7 +466,7 @@ void Parser::createBlock(int32 skipBack) {
void Parser::createSkipBlock(int32 w, int32 h) { void Parser::createSkipBlock(int32 w, int32 h) {
createBlock(); createBlock();
_t->_text.push_back('_'); _t->_text.push_back('_');
_t->_blocks.push_back(Block::Skip(_t->_st->font, _t->_text, _blockStart++, w, h, _lnkIndex)); _t->_blocks.push_back(Block::Skip(_t->_st->font, _t->_text, _blockStart++, w, h, _lnkIndex, 0/*spoilerIndex*/));
blockCreated(); blockCreated();
} }
@ -1843,7 +1843,7 @@ private:
_elideSavedIndex = blockIndex; _elideSavedIndex = blockIndex;
auto mutableText = const_cast<String*>(_t); auto mutableText = const_cast<String*>(_t);
_elideSavedBlock = std::move(mutableText->_blocks[blockIndex]); _elideSavedBlock = std::move(mutableText->_blocks[blockIndex]);
mutableText->_blocks[blockIndex] = Block::Text(_t->_st->font, _t->_text, QFIXED_MAX, elideStart, 0, (*_elideSavedBlock)->flags(), (*_elideSavedBlock)->lnkIndex()); mutableText->_blocks[blockIndex] = Block::Text(_t->_st->font, _t->_text, QFIXED_MAX, elideStart, 0, (*_elideSavedBlock)->flags(), (*_elideSavedBlock)->lnkIndex(), (*_elideSavedBlock)->spoilerIndex());
_blocksSize = blockIndex + 1; _blocksSize = blockIndex + 1;
_endBlock = (blockIndex + 1 < _t->_blocks.size() ? _t->_blocks[blockIndex + 1].get() : nullptr); _endBlock = (blockIndex + 1 < _t->_blocks.size() ? _t->_blocks[blockIndex + 1].get() : nullptr);
} }
@ -2889,6 +2889,7 @@ bool String::updateSkipBlock(int width, int height) {
_text.size() - 1, _text.size() - 1,
width, width,
height, height,
0,
0)); 0));
recountNaturalSize(false); recountNaturalSize(false);
return true; return true;

View file

@ -346,9 +346,11 @@ AbstractBlock::AbstractBlock(
uint16 from, uint16 from,
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex) uint16 lnkIndex,
uint16 spoilerIndex)
: _from(from) : _from(from)
, _flags((flags & 0xFF) | ((lnkIndex & 0xFFFF) << 12)) { , _flags((flags & 0xFF) | ((lnkIndex & 0xFFFF) << 12))
, _spoilerIndex(spoilerIndex) {
} }
uint16 AbstractBlock::from() const { uint16 AbstractBlock::from() const {
@ -379,12 +381,20 @@ void AbstractBlock::setLnkIndex(uint16 lnkIndex) {
_flags = (_flags & ~(0xFFFF << 12)) | (lnkIndex << 12); _flags = (_flags & ~(0xFFFF << 12)) | (lnkIndex << 12);
} }
uint16 AbstractBlock::spoilerIndex() const {
return _spoilerIndex;
}
void AbstractBlock::setSpoilerIndex(uint16 spoilerIndex) {
_spoilerIndex = spoilerIndex;
}
TextBlockType AbstractBlock::type() const { TextBlockType AbstractBlock::type() const {
return TextBlockType((_flags >> 8) & 0x0F); return TextBlockType((_flags >> 8) & 0x0F);
} }
int32 AbstractBlock::flags() const { int32 AbstractBlock::flags() const {
return (_flags & 0xFF); return (_flags & 0xFFF);
} }
QFixed AbstractBlock::f_rbearing() const { QFixed AbstractBlock::f_rbearing() const {
@ -400,8 +410,9 @@ TextBlock::TextBlock(
uint16 from, uint16 from,
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex) uint16 lnkIndex,
: AbstractBlock(font, str, from, length, flags, lnkIndex) { uint16 spoilerIndex)
: AbstractBlock(font, str, from, length, flags, lnkIndex, spoilerIndex) {
_flags |= ((TextBlockTText & 0x0F) << 8); _flags |= ((TextBlockTText & 0x0F) << 8);
if (length) { if (length) {
style::font blockFont = font; style::font blockFont = font;
@ -442,8 +453,9 @@ EmojiBlock::EmojiBlock(
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex, uint16 lnkIndex,
uint16 spoilerIndex,
EmojiPtr emoji) EmojiPtr emoji)
: AbstractBlock(font, str, from, length, flags, lnkIndex) : AbstractBlock(font, str, from, length, flags, lnkIndex, spoilerIndex)
, _emoji(emoji) { , _emoji(emoji) {
_flags |= ((TextBlockTEmoji & 0x0F) << 8); _flags |= ((TextBlockTEmoji & 0x0F) << 8);
_width = int(st::emojiSize + 2 * st::emojiPadding); _width = int(st::emojiSize + 2 * st::emojiPadding);

View file

@ -46,6 +46,9 @@ public:
uint16 lnkIndex() const; uint16 lnkIndex() const;
void setLnkIndex(uint16 lnkIndex); void setLnkIndex(uint16 lnkIndex);
uint16 spoilerIndex() const;
void setSpoilerIndex(uint16 spoilerIndex);
TextBlockType type() const; TextBlockType type() const;
int32 flags() const; int32 flags() const;
@ -56,12 +59,15 @@ protected:
uint16 from, uint16 from,
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex); uint16 lnkIndex,
uint16 spoilerIndex);
uint16 _from = 0; uint16 _from = 0;
uint32 _flags = 0; // 4 bits empty, 16 bits lnkIndex, 4 bits type, 8 bits flags uint32 _flags = 0; // 4 bits empty, 16 bits lnkIndex, 4 bits type, 8 bits flags
uint16 _spoilerIndex = 0;
QFixed _width = 0; QFixed _width = 0;
// Right padding: spaces after the last content of the block (like a word). // Right padding: spaces after the last content of the block (like a word).
@ -81,8 +87,9 @@ public:
uint16 from, uint16 from,
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex) uint16 lnkIndex,
: AbstractBlock(font, str, from, length, flags, lnkIndex) { uint16 spoilerIndex)
: AbstractBlock(font, str, from, length, flags, lnkIndex, spoilerIndex) {
_flags |= ((TextBlockTNewline & 0x0F) << 8); _flags |= ((TextBlockTNewline & 0x0F) << 8);
} }
@ -142,7 +149,8 @@ public:
uint16 from, uint16 from,
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex); uint16 lnkIndex,
uint16 spoilerIndex);
private: private:
QFixed real_f_rbearing() const { QFixed real_f_rbearing() const {
@ -168,6 +176,7 @@ public:
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex, uint16 lnkIndex,
uint16 spoilerIndex,
EmojiPtr emoji); EmojiPtr emoji);
private: private:
@ -187,8 +196,9 @@ public:
uint16 from, uint16 from,
int32 w, int32 w,
int32 h, int32 h,
uint16 lnkIndex) uint16 lnkIndex,
: AbstractBlock(font, str, from, 1, 0, lnkIndex) uint16 spoilerIndex)
: AbstractBlock(font, str, from, 1, 0, lnkIndex, spoilerIndex)
, _height(h) { , _height(h) {
_flags |= ((TextBlockTSkip & 0x0F) << 8); _flags |= ((TextBlockTSkip & 0x0F) << 8);
_width = w; _width = w;
@ -304,8 +314,9 @@ public:
uint16 from, uint16 from,
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex) { uint16 lnkIndex,
return New<NewlineBlock>(font, str, from, length, flags, lnkIndex); uint16 spoilerIndex) {
return New<NewlineBlock>(font, str, from, length, flags, lnkIndex, spoilerIndex);
} }
[[nodiscard]] static Block Text( [[nodiscard]] static Block Text(
@ -315,7 +326,8 @@ public:
uint16 from, uint16 from,
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex) { uint16 lnkIndex,
uint16 spoilerIndex) {
return New<TextBlock>( return New<TextBlock>(
font, font,
str, str,
@ -323,7 +335,8 @@ public:
from, from,
length, length,
flags, flags,
lnkIndex); lnkIndex,
spoilerIndex);
} }
[[nodiscard]] static Block Emoji( [[nodiscard]] static Block Emoji(
@ -333,6 +346,7 @@ public:
uint16 length, uint16 length,
uchar flags, uchar flags,
uint16 lnkIndex, uint16 lnkIndex,
uint16 spoilerIndex,
EmojiPtr emoji) { EmojiPtr emoji) {
return New<EmojiBlock>( return New<EmojiBlock>(
font, font,
@ -341,6 +355,7 @@ public:
length, length,
flags, flags,
lnkIndex, lnkIndex,
spoilerIndex,
emoji); emoji);
} }
@ -350,8 +365,9 @@ public:
uint16 from, uint16 from,
int32 w, int32 w,
int32 h, int32 h,
uint16 lnkIndex) { uint16 lnkIndex,
return New<SkipBlock>(font, str, from, w, h, lnkIndex); uint16 spoilerIndex) {
return New<SkipBlock>(font, str, from, w, h, lnkIndex, spoilerIndex);
} }
template <typename FinalBlock> template <typename FinalBlock>