aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-06-30 13:10:07 +0200
committerdec05eba <dec05eba@protonmail.com>2023-06-30 13:10:07 +0200
commitb51468e440bb73371a430d0a0efe7658e8b7b80c (patch)
tree9036dd18aa3a79c26a8086ee6685240fdb15d02c /src/Body.cpp
parent08e1a601e4aa13cdfb3bea836b89524cc13b07bf (diff)
Dont show spinning circle when thumbnail failed to load
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 2af12c3..3f8691a 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -1458,12 +1458,14 @@ namespace QuickMedia {
window.draw(image_fallback);
}
- mgl::vec2f loading_icon_size(loading_icon.get_texture()->get_size().x, loading_icon.get_texture()->get_size().y);
- auto new_loading_icon_size = clamp_to_size(loading_icon_size, content_size);
- loading_icon.set_position(item_pos + mgl::vec2f(body_spacing[body_theme].image_padding_x, padding_y) + (content_size * 0.5f));
- loading_icon.set_scale(get_ratio(loading_icon_size, new_loading_icon_size));
- loading_icon.set_rotation(elapsed_time_sec * 400.0);
- window.draw(loading_icon);
+ if(item_thumbnail->loading_state != LoadingState::FAILED_TO_LOAD) {
+ mgl::vec2f loading_icon_size(loading_icon.get_texture()->get_size().x, loading_icon.get_texture()->get_size().y);
+ auto new_loading_icon_size = clamp_to_size(loading_icon_size, content_size);
+ loading_icon.set_position(item_pos + mgl::vec2f(body_spacing[body_theme].image_padding_x, padding_y) + (content_size * 0.5f));
+ loading_icon.set_scale(get_ratio(loading_icon_size, new_loading_icon_size));
+ loading_icon.set_rotation(elapsed_time_sec * 400.0);
+ window.draw(loading_icon);
+ }
text_offset_x += body_spacing[body_theme].image_padding_x + item->loaded_image_size.x;
}
} else if(draw_thumbnails && item->thumbnail_size.x > 0) {
@@ -1586,12 +1588,20 @@ namespace QuickMedia {
thumbnail_drawn = true;
} else if(!item->thumbnail_url.empty()) {
mgl::vec2f content_size = thumbnail_size.to_vec2f();
- mgl::vec2f loading_icon_size(loading_icon.get_texture()->get_size().x, loading_icon.get_texture()->get_size().y);
- auto new_loading_icon_size = clamp_to_size(loading_icon_size, content_size);
- loading_icon.set_position(pos + pos_offset + mgl::vec2f(card_padding_x, card_padding_y) + mgl::vec2f(card_max_image_size.x, content_size.y) * 0.5f);
- loading_icon.set_scale(get_ratio(loading_icon_size, new_loading_icon_size));
- loading_icon.set_rotation(elapsed_time_sec * 400.0);
- window.draw(loading_icon);
+ image_fallback.set_size(content_size);
+ image_fallback.set_color(get_theme().image_loading_background_color);
+ image_fallback.set_position(pos + pos_offset + mgl::vec2f(card_padding_x, card_padding_y) + mgl::vec2f(card_max_image_size.x * 0.5f, 0.0f) - mgl::vec2f(content_size.x * 0.5f, 0.0f));
+ // TODO: Rounded corners
+ window.draw(image_fallback);
+
+ if(item_thumbnail->loading_state != LoadingState::FAILED_TO_LOAD) {
+ mgl::vec2f loading_icon_size(loading_icon.get_texture()->get_size().x, loading_icon.get_texture()->get_size().y);
+ auto new_loading_icon_size = clamp_to_size(loading_icon_size, content_size);
+ loading_icon.set_position(pos + pos_offset + mgl::vec2f(card_padding_x, card_padding_y) + mgl::vec2f(card_max_image_size.x, content_size.y) * 0.5f);
+ loading_icon.set_scale(get_ratio(loading_icon_size, new_loading_icon_size));
+ loading_icon.set_rotation(elapsed_time_sec * 400.0);
+ window.draw(loading_icon);
+ }
image_height = content_size.y;
}
@@ -1703,7 +1713,7 @@ namespace QuickMedia {
std::shared_ptr<ThumbnailData> item_thumbnail = AsyncImageLoader::get_instance().get_thumbnail(item->thumbnail_url, item->thumbnail_is_local, content_size);
content_size = clamp_to_size_x(content_size, width - (rendering_card_view ? 0.0f : body_spacing[body_theme].image_padding_x * 2.0f));
- if(item_thumbnail && item_thumbnail->loading_state == LoadingState::FINISHED_LOADING && item_thumbnail->image->get_size().x > 0 && item_thumbnail->image->get_size().y > 0) {
+ if(item_thumbnail && item_thumbnail->loading_state == LoadingState::FINISHED_LOADING) {
if(!item_thumbnail->texture.load_from_image(*item_thumbnail->image))
fprintf(stderr, "Warning: failed to load texture from image: %s\n", item->thumbnail_url.c_str());
//item_thumbnail->texture.generateMipmap();