From e1a8d10b61c5f8ca092ba3aa458b661da29ba447 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 30 Sep 2020 19:07:05 +0200 Subject: Matrix: add message replying with ctrl+r, also use shared_ptr for BodyItem --- include/Body.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'include/Body.hpp') diff --git a/include/Body.hpp b/include/Body.hpp index a5c346e..60b976d 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -22,6 +22,8 @@ namespace QuickMedia { BodyItem(std::string _title); BodyItem(const BodyItem &other); + static std::shared_ptr create(std::string title) { return std::make_shared(std::move(title)); } + void set_title(std::string new_title) { if(title.empty() && new_title.empty()) return; @@ -74,13 +76,14 @@ namespace QuickMedia { std::string post_number; sf::Color title_color; sf::Color author_color; + void *userdata; // Not managed, should be deallocated by whoever sets this private: std::string title; std::string description; std::string author; }; - using BodyItems = std::vector>; + using BodyItems = std::vector>; class Body { public: @@ -108,10 +111,18 @@ namespace QuickMedia { void clear_thumbnails(); BodyItem* get_selected() const; + std::shared_ptr get_selected_shared(); void clamp_selection(); void draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size); void draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress); + // |size| is the clip size, another outside this will be cut off. + // Note: this should be called after |draw|, or thumbnails will be messed up. TODO: find a way to solve this issue in a clean way. + // This happens because of |draw| sets thumbnails as unreferenced at the beginning and cleans them up at the end if they are not drawn in the same function call. + void draw_item(sf::RenderWindow &window, BodyItem *item, sf::Vector2f pos, sf::Vector2f size); + + float get_item_height(BodyItem *item); + float get_spacing_y() const; static bool string_find_case_insensitive(const std::string &str, const std::string &substr); // TODO: Make this actually fuzzy... Right now it's just a case insensitive string find. @@ -142,7 +153,6 @@ namespace QuickMedia { sf::Color line_seperator_color; private: void draw_item(sf::RenderWindow &window, BodyItem *item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress); - float get_item_height(BodyItem *item); private: enum class LoadingState { NOT_LOADED, -- cgit v1.2.3