Added ability to show or hide spoilers from outside.

This commit is contained in:
23rd 2021-12-25 16:53:00 +03:00
parent db871a87f5
commit 44853e9334
4 changed files with 26 additions and 2 deletions

View file

@ -30,3 +30,7 @@ crl::time SpoilerClickHandler::startMs() const {
void SpoilerClickHandler::setStartMs(crl::time value) {
_startMs = value;
}
void SpoilerClickHandler::setShown(bool value) {
_shown = value;
}

View file

@ -19,6 +19,7 @@ public:
void onClick(ClickContext context) const override;
[[nodiscard]] bool shown() const;
void setShown(bool value);
[[nodiscard]] crl::time startMs() const;
void setStartMs(crl::time value);

View file

@ -3156,14 +3156,29 @@ void String::setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk) {
void String::setSpoiler(
uint16 lnkIndex,
const std::shared_ptr<SpoilerClickHandler> &lnk) {
if (!lnkIndex || lnkIndex > _spoilers.size()) return;
if (!lnkIndex || lnkIndex > _spoilers.size()) {
return;
}
_spoilers[lnkIndex - 1] = lnk;
}
void String::setSpoilerShown(uint16 lnkIndex, bool shown) {
if (!lnkIndex
|| (lnkIndex > _spoilers.size())
|| !_spoilers[lnkIndex - 1]) {
return;
}
_spoilers[lnkIndex - 1]->setShown(shown);
}
bool String::hasLinks() const {
return !_links.isEmpty();
}
int String::spoilersCount() const {
return _spoilers.size();
}
bool String::hasSkipBlock() const {
return _blocks.empty() ? false : _blocks.back()->type() == TextBlockTSkip;
}

View file

@ -135,7 +135,11 @@ public:
void setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk);
bool hasLinks() const;
void setSpoiler(uint16 lnkIndex, const std::shared_ptr<SpoilerClickHandler> &lnk);
void setSpoiler(
uint16 lnkIndex,
const std::shared_ptr<SpoilerClickHandler> &lnk);
void setSpoilerShown(uint16 lnkIndex, bool shown);
int spoilersCount() const;
bool hasSkipBlock() const;
bool updateSkipBlock(int width, int height);