diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Body.hpp | 14 |
1 files changed, 12 insertions, 2 deletions
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<BodyItem> create(std::string title) { return std::make_shared<BodyItem>(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<std::unique_ptr<BodyItem>>; + using BodyItems = std::vector<std::shared_ptr<BodyItem>>; class Body { public: @@ -108,10 +111,18 @@ namespace QuickMedia { void clear_thumbnails(); BodyItem* get_selected() const; + std::shared_ptr<BodyItem> 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, |