aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-06-08 13:39:11 +0200
committerdec05eba <dec05eba@protonmail.com>2021-06-08 13:39:11 +0200
commit0f0bf1c649388c07ae6e8dd784d7402f68691b96 (patch)
tree22868fcd37cdc15c6d0b6002d85b7c1676b2f34d
parentda95623137f85b07abf9f56035c23819af1e7fe9 (diff)
Remove images that are not visible from the loading queue, prepare for inline images
-rw-r--r--TODO4
-rw-r--r--include/Body.hpp2
-rw-r--r--include/Entry.hpp4
-rw-r--r--include/MessageQueue.hpp12
-rw-r--r--include/Text.hpp4
-rw-r--r--src/AsyncImageLoader.cpp3
-rw-r--r--src/Body.cpp8
-rw-r--r--src/Entry.cpp8
-rw-r--r--src/Text.cpp8
9 files changed, 35 insertions, 18 deletions
diff --git a/TODO b/TODO
index cc762ab..fb911da 100644
--- a/TODO
+++ b/TODO
@@ -151,4 +151,6 @@ Cancel current search when search is updated.
Support 4chan archive.
Use old method of rendering body where rendering items is done up and down, starting from the selected item. This will make quickmedia run as fast when displaying 100 000 items as when displaying 10 items.
Use correct spacing when in grid (card) mode. Should be row spacing instead of body spacing.
-Instead of selecting the first/last item when reaching the top/bottom, keep the selected column and instead scroll the body so the first/last item is visible. \ No newline at end of file
+Instead of selecting the first/last item when reaching the top/bottom, keep the selected column and instead scroll the body so the first/last item is visible.
+Cleanup reactions when they are not visible on the screen.
+Kill async image downloader thread when the item with the image is no longer visible on the screen. \ No newline at end of file
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 <mutex>
#include <condition_variable>
#include <optional>
+#include <functional>
namespace QuickMedia {
template <typename T>
@@ -55,6 +56,17 @@ namespace QuickMedia {
std::unique_lock<std::mutex> lock(mutex);
running = true;
}
+
+ // Returns true from |callback| to remove the element
+ void erase_if(std::function<bool(T&)> callback) {
+ std::unique_lock<std::mutex> 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<T> 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);
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index 1769846..1a1e120 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -227,6 +227,9 @@ namespace QuickMedia {
bool loaded_textures_changed = false;
for(auto it = thumbnails.begin(); it != thumbnails.end();) {
if(it->second->counter != counter) {
+ image_load_queue.erase_if([&it](ThumbnailLoadData &load_data) {
+ return load_data.path.data == it->first;
+ });
it = thumbnails.erase(it);
loaded_textures_changed = true;
} else {
diff --git a/src/Body.cpp b/src/Body.cpp
index 3df816c..d84785a 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -701,8 +701,8 @@ namespace QuickMedia {
}
bool instant_move = body_size_changed;
- if(target_y_set == TargetSetState::SET) {
- target_y_set = TargetSetState::APPLIED;
+ if(target_set == TargetSetState::SET) {
+ target_set = TargetSetState::APPLIED;
instant_move = true;
}
@@ -941,8 +941,8 @@ namespace QuickMedia {
if(item_index == selected_item) {
item_background_target_pos = pos;
item_background_target_size = sf::Vector2f(item_width, item_height);
- if(target_y_set == TargetSetState::NOT_SET)
- target_y_set = TargetSetState::SET;
+ if(target_set == TargetSetState::NOT_SET)
+ target_set = TargetSetState::SET;
}
}
diff --git a/src/Entry.cpp b/src/Entry.cpp
index 7e1b6d9..8e1fbfb 100644
--- a/src/Entry.cpp
+++ b/src/Entry.cpp
@@ -82,8 +82,8 @@ namespace QuickMedia {
text.setEditable(editable);
}
- void Entry::set_text(std::string new_text) {
- text.setString(sf::String::fromUtf8(new_text.data(), new_text.data() + new_text.size()));
+ void Entry::set_text(const std::string &new_text) {
+ text.setString(sf::String::fromUtf8(new_text.begin(), new_text.end()));
}
void Entry::move_caret_to_end() {
@@ -91,8 +91,8 @@ namespace QuickMedia {
text.moveCaretToEnd();
}
- void Entry::append_text(std::string str) {
- text.appendText(std::move(str));
+ void Entry::append_text(const std::string &str) {
+ text.appendText(sf::String::fromUtf8(str.begin(), str.end()));
}
void Entry::replace(size_t start_index, size_t length, const sf::String &insert_str) {
diff --git a/src/Text.cpp b/src/Text.cpp
index 2e735ab..7859c7a 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -55,12 +55,12 @@ namespace QuickMedia
setString(std::move(_str));
}
- void Text::setString(sf::String str)
+ void Text::setString(const sf::String &str)
{
//if(str != this->str)
//{
size_t prev_str_size = this->str.getSize();
- this->str = std::move(str);
+ this->str = str;
dirty = true;
dirtyText = true;
if((int)this->str.getSize() < caretIndex || prev_str_size == 0)
@@ -76,8 +76,8 @@ namespace QuickMedia
return str;
}
- void Text::appendText(sf::String str) {
- this->str += std::move(str);
+ void Text::appendText(const sf::String &str) {
+ this->str += str;
dirty = true;
dirtyText = true;
}