From 5dd0248e16522a3672c58a7892d549840257e8dd Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 22 Nov 2020 10:29:58 +0100 Subject: Matrix: add reactions --- include/Body.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'include/Body.hpp') diff --git a/include/Body.hpp b/include/Body.hpp index 45121f8..56ef262 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -31,6 +31,11 @@ namespace QuickMedia { CIRCLE }; + struct Reaction { + std::unique_ptr text; + void *userdata = nullptr; + }; + class BodyItem { public: BodyItem(std::string _title); @@ -88,6 +93,25 @@ namespace QuickMedia { dirty_author = true; } + void add_reaction(std::string text, void *userdata) { + sf::String str = sf::String::fromUtf8(text.begin(), text.end()); + Reaction reaction; + reaction.text = std::make_unique(std::move(str), false, 14, 0.0f); + reaction.userdata = userdata; + reactions.push_back(std::move(reaction)); + } + + // Returns true if reaction is found + bool remove_reaction_by_userdata(void *userdata) { + for(auto it = reactions.begin(); it != reactions.end(); ++it) { + if(it->userdata == userdata) { + reactions.erase(it); + return true; + } + } + return false; + } + const std::string& get_title() const { return title; } const std::string& get_description() const { return description; } const std::string& get_author() const { return author; } @@ -124,6 +148,7 @@ namespace QuickMedia { std::shared_ptr embedded_item; // Used by matrix for example to display reply message body. Note: only the first level of embedded items is rendered (not recursive, this is done on purpose) ThumbnailMaskType thumbnail_mask_type = ThumbnailMaskType::NONE; sf::Vector2i thumbnail_size; + std::vector reactions; // TODO: Move to a different body item type private: // TODO: Clean up these strings when set in text, and get_title for example should return |title_text.getString()| // TODO: Use sf::String instead, removes the need to convert to utf32 every time the text is dirty (for example when resizing window) -- cgit v1.2.3