text_extended_data.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include "ui/effects/spoiler_mess.h"
  9. #include "ui/effects/animations.h"
  10. #include "ui/click_handler.h"
  11. namespace Ui::Text {
  12. struct Modification;
  13. class String;
  14. class SpoilerClickHandler final : public ClickHandler {
  15. public:
  16. SpoilerClickHandler(
  17. not_null<String*> text,
  18. Fn<bool(const ClickContext&)> filter);
  19. [[nodiscard]] not_null<String*> text() const;
  20. void setText(not_null<String*> text);
  21. void onClick(ClickContext context) const override;
  22. private:
  23. not_null<String*> _text;
  24. const Fn<bool(const ClickContext &)> _filter;
  25. };
  26. class PreClickHandler final : public ClickHandler {
  27. public:
  28. PreClickHandler(not_null<String*> text, uint16 offset, uint16 length);
  29. [[nodiscard]] not_null<String*> text() const;
  30. void setText(not_null<String*> text);
  31. void onClick(ClickContext context) const override;
  32. private:
  33. not_null<String*> _text;
  34. uint16 _offset = 0;
  35. uint16 _length = 0;
  36. };
  37. class BlockquoteClickHandler final : public ClickHandler {
  38. public:
  39. BlockquoteClickHandler(not_null<String*> text, int quoteIndex);
  40. [[nodiscard]] not_null<String*> text() const;
  41. void setText(not_null<String*> text);
  42. void onClick(ClickContext context) const override;
  43. private:
  44. not_null<String*> _text;
  45. uint16 _quoteIndex = 0;
  46. };
  47. struct SpoilerData {
  48. explicit SpoilerData(Fn<void()> repaint)
  49. : animation(std::move(repaint)) {
  50. }
  51. SpoilerAnimation animation;
  52. std::shared_ptr<SpoilerClickHandler> link;
  53. Animations::Simple revealAnimation;
  54. bool revealed = false;
  55. };
  56. struct QuoteDetails {
  57. QString language;
  58. std::shared_ptr<PreClickHandler> copy;
  59. std::shared_ptr<BlockquoteClickHandler> toggle;
  60. int copyWidth = 0;
  61. int maxWidth = 0;
  62. int minHeight = 0;
  63. int scrollLeft = 0;
  64. bool blockquote = false;
  65. bool collapsed = false;
  66. bool expanded = false;
  67. bool pre = false;
  68. };
  69. struct QuotesData {
  70. std::vector<QuoteDetails> list;
  71. Fn<void(int index, bool expanded)> expandCallback;
  72. };
  73. struct ExtendedData {
  74. std::vector<ClickHandlerPtr> links;
  75. std::unique_ptr<QuotesData> quotes;
  76. std::unique_ptr<SpoilerData> spoiler;
  77. std::vector<Modification> modifications;
  78. };
  79. } // namespace Ui::Text