From 44853e933400a7f1536b9847fd0adc2b7d575bff Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 25 Dec 2021 16:53:00 +0300 Subject: [PATCH] Added ability to show or hide spoilers from outside. --- ui/spoiler_click_handler.cpp | 4 ++++ ui/spoiler_click_handler.h | 1 + ui/text/text.cpp | 17 ++++++++++++++++- ui/text/text.h | 6 +++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ui/spoiler_click_handler.cpp b/ui/spoiler_click_handler.cpp index a982eb8..dbd25e9 100644 --- a/ui/spoiler_click_handler.cpp +++ b/ui/spoiler_click_handler.cpp @@ -30,3 +30,7 @@ crl::time SpoilerClickHandler::startMs() const { void SpoilerClickHandler::setStartMs(crl::time value) { _startMs = value; } + +void SpoilerClickHandler::setShown(bool value) { + _shown = value; +} diff --git a/ui/spoiler_click_handler.h b/ui/spoiler_click_handler.h index 8655856..bacaf68 100644 --- a/ui/spoiler_click_handler.h +++ b/ui/spoiler_click_handler.h @@ -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); diff --git a/ui/text/text.cpp b/ui/text/text.cpp index 27ae6e5..9b17993 100644 --- a/ui/text/text.cpp +++ b/ui/text/text.cpp @@ -3156,14 +3156,29 @@ void String::setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk) { void String::setSpoiler( uint16 lnkIndex, const std::shared_ptr &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; } diff --git a/ui/text/text.h b/ui/text/text.h index 99edc80..442e9cb 100644 --- a/ui/text/text.h +++ b/ui/text/text.h @@ -135,7 +135,11 @@ public: void setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk); bool hasLinks() const; - void setSpoiler(uint16 lnkIndex, const std::shared_ptr &lnk); + void setSpoiler( + uint16 lnkIndex, + const std::shared_ptr &lnk); + void setSpoilerShown(uint16 lnkIndex, bool shown); + int spoilersCount() const; bool hasSkipBlock() const; bool updateSkipBlock(int width, int height);