From 0f0bf1c649388c07ae6e8dd784d7402f68691b96 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 8 Jun 2021 13:39:11 +0200 Subject: Remove images that are not visible from the loading queue, prepare for inline images --- include/Body.hpp | 2 +- include/Entry.hpp | 4 ++-- include/MessageQueue.hpp | 12 ++++++++++++ include/Text.hpp | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/Body.hpp b/include/Body.hpp index 4007bc4..abf0d4b 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -369,7 +369,7 @@ namespace QuickMedia { sf::Vector2f item_background_target_pos; sf::Vector2f item_background_prev_size; sf::Vector2f item_background_target_size; - TargetSetState target_y_set = TargetSetState::NOT_SET; + TargetSetState target_set = TargetSetState::NOT_SET; // TODO: Instead of using this, add functions for modifying |items| and apply the filter on those new items DirtyState items_dirty = DirtyState::FALSE; std::string current_filter; diff --git a/include/Entry.hpp b/include/Entry.hpp index 22680b5..1ee237b 100644 --- a/include/Entry.hpp +++ b/include/Entry.hpp @@ -24,11 +24,11 @@ namespace QuickMedia { void set_single_line(bool single_line); void set_editable(bool editable); - void set_text(std::string text); + void set_text(const std::string &text); void set_position(const sf::Vector2f &pos); void set_max_width(float width); void move_caret_to_end(); - void append_text(std::string str); + void append_text(const std::string &str); void replace(size_t start_index, size_t length, const sf::String &insert_str); int get_caret_index() const; diff --git a/include/MessageQueue.hpp b/include/MessageQueue.hpp index 7c34d51..3f38ca2 100644 --- a/include/MessageQueue.hpp +++ b/include/MessageQueue.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace QuickMedia { template @@ -55,6 +56,17 @@ namespace QuickMedia { std::unique_lock lock(mutex); running = true; } + + // Returns true from |callback| to remove the element + void erase_if(std::function callback) { + std::unique_lock lock(mutex); + for(auto it = data_queue.begin(); it != data_queue.end();) { + if(callback(*it)) + it = data_queue.erase(it); + else + ++it; + } + } private: std::deque data_queue; std::mutex mutex; diff --git a/include/Text.hpp b/include/Text.hpp index 5749072..a39b2ba 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -68,9 +68,9 @@ namespace QuickMedia Text(bool bold_font); Text(sf::String str, bool bold_font, unsigned int characterSize, float maxWidth, bool highlight_urls = false); - void setString(sf::String str); + void setString(const sf::String &str); const sf::String& getString() const; - void appendText(sf::String str); + void appendText(const sf::String &str); void setPosition(float x, float y); void setPosition(const sf::Vector2f &position); -- cgit v1.2.3