diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-17 09:40:10 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-17 10:49:13 +0200 |
commit | 9bf163d51a252fb5a611e88c2e0b4123a98169e1 (patch) | |
tree | e742979a7128e3ead913e9348c4b207c0fd95ab4 /include | |
parent | fd9178b9d500a0b5f30f388f8d419ac386ce87cb (diff) |
Matrix: show reply messages embedded in messages that reply to them, like element does
Diffstat (limited to 'include')
-rw-r--r-- | include/Body.hpp | 23 | ||||
-rw-r--r-- | include/DownloadUtils.hpp | 2 | ||||
-rw-r--r-- | include/Storage.hpp | 5 | ||||
-rw-r--r-- | include/Text.hpp | 1 |
4 files changed, 22 insertions, 9 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: diff --git a/include/DownloadUtils.hpp b/include/DownloadUtils.hpp index 2d2b813..52c5b80 100644 --- a/include/DownloadUtils.hpp +++ b/include/DownloadUtils.hpp @@ -2,7 +2,7 @@ #include <string> #include <vector> -#include <rapidjson/document.h> +#include <rapidjson/fwd.h> namespace QuickMedia { enum class DownloadResult { diff --git a/include/Storage.hpp b/include/Storage.hpp index 10cbbb2..ae7db04 100644 --- a/include/Storage.hpp +++ b/include/Storage.hpp @@ -4,10 +4,7 @@ #include <functional> #include <filesystem> #include <json/value.h> -#ifdef Bool -#undef Bool -#endif -#include <rapidjson/document.h> +#include <rapidjson/fwd.h> namespace QuickMedia { // Return false to stop the iterator diff --git a/include/Text.hpp b/include/Text.hpp index 7e9dda2..a71bc8e 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -141,6 +141,7 @@ namespace QuickMedia bool editable; CaretMoveDirection caretMoveDirection; sf::FloatRect boundingBox; + int num_lines; float lineSpacing; float characterSpacing; std::vector<TextElement> textElements; |