aboutsummaryrefslogtreecommitdiff
path: root/include/Body.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-17 09:40:10 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-17 10:49:13 +0200
commit9bf163d51a252fb5a611e88c2e0b4123a98169e1 (patch)
treee742979a7128e3ead913e9348c4b207c0fd95ab4 /include/Body.hpp
parentfd9178b9d500a0b5f30f388f8d419ac386ce87cb (diff)
Matrix: show reply messages embedded in messages that reply to them, like element does
Diffstat (limited to 'include/Body.hpp')
-rw-r--r--include/Body.hpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/include/Body.hpp b/include/Body.hpp
index 09b477d..cdb0ad0 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -18,10 +18,16 @@ namespace sf {
namespace QuickMedia {
class Program;
+ enum class EmbeddedItemStatus {
+ NONE,
+ LOADING,
+ FINISHED_LOADING,
+ FAILED_TO_LOAD
+ };
+
class BodyItem {
public:
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)); }
@@ -89,7 +95,10 @@ namespace QuickMedia {
sf::Color author_color;
void *userdata; // Not managed, should be deallocated by whoever sets this
sf::Int32 last_drawn_time;
+ EmbeddedItemStatus embedded_item_status = EmbeddedItemStatus::NONE;
+ std::shared_ptr<BodyItem> 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)
private:
+ // TODO: Clean up these strings when set in text, and get_title for example should return |title_text.getString()|
std::string title;
std::string description;
std::string author;
@@ -97,6 +106,7 @@ namespace QuickMedia {
};
using BodyItems = std::vector<std::shared_ptr<BodyItem>>;
+ using BodyItemRenderCallback = std::function<void(BodyItem *body_item)>;
class Body {
public:
@@ -141,9 +151,11 @@ namespace QuickMedia {
// |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);
+ // TODO: Right now drawing an item that also exists in the body will cause the text to update geometry every frame if the text is wrapping text and the items are drawn at different sizes,
+ // because of Text::setMaxWidth
+ void draw_item(sf::RenderWindow &window, BodyItem *item, sf::Vector2f pos, sf::Vector2f size, bool include_embedded_item = true);
- float get_item_height(BodyItem *item, bool load_texture = true);
+ float get_item_height(BodyItem *item, bool load_texture = true, bool include_embedded_item = true);
float get_spacing_y() const;
static bool string_find_case_insensitive(const std::string &str, const std::string &substr);
@@ -156,6 +168,7 @@ namespace QuickMedia {
bool no_items_visible() const;
int get_selected_item() const { return selected_item; }
+ bool is_selected_item_last_visible_item() const;
void set_page_scroll(float scroll) { page_scroll = scroll; }
float get_page_scroll() const { return page_scroll; }
@@ -166,6 +179,7 @@ namespace QuickMedia {
sf::Font *cjk_font;
sf::Text progress_text;
sf::Text replies_text;
+ sf::Text embedded_item_load_text;
BodyItems items;
bool draw_thumbnails;
bool wrap_around;
@@ -173,8 +187,9 @@ namespace QuickMedia {
sf::Vector2i thumbnail_resize_target_size;
sf::Vector2f thumbnail_fallback_size;
sf::Color line_seperator_color;
+ BodyItemRenderCallback body_item_render_callback;
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);
+ 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, bool include_embedded_item = true);
void update_dirty_state(BodyItem *body_item, sf::Vector2f size);
void clear_body_item_cache(BodyItem *body_item);
private: