From 1d44ae1b038b6d541bc45d298ba704f8a3fbd559 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 12 Jun 2021 02:51:23 +0200 Subject: Change height of item to fit scaled image --- include/Body.hpp | 2 ++ src/Body.cpp | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/Body.hpp b/include/Body.hpp index 121fbb5..8ce05fc 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -329,6 +329,8 @@ namespace QuickMedia { sf::Text replies_text; sf::Text embedded_item_load_text; + bool body_size_changed = false; + int num_visible_items; bool top_cut_off; bool bottom_cut_off; diff --git a/src/Body.cpp b/src/Body.cpp index 3c210a8..76ad110 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -546,7 +546,7 @@ namespace QuickMedia { const bool rendering_card_view = card_view && card_view_enabled; - const bool body_size_changed = std::abs(size.x - body_size.x) > 0.1f || std::abs(size.y - body_size.y) > 0.1f; + body_size_changed = std::abs(size.x - body_size.x) > 0.1f || std::abs(size.y - body_size.y) > 0.1f; if(body_size_changed) body_size = size; @@ -1297,7 +1297,7 @@ namespace QuickMedia { if(draw_thumbnails && !merge_with_previous && !item->thumbnail_url.empty()) item_thumbnail = AsyncImageLoader::get_instance().get_thumbnail(item->thumbnail_url, item->thumbnail_is_local, thumbnail_size); - thumbnail_size = clamp_to_size_x(thumbnail_size, sf::Vector2i(size.x, thumbnail_size.y)); + thumbnail_size = clamp_to_size_x(thumbnail_size, sf::Vector2i(size.x - body_spacing[body_theme].image_padding_x * 2.0f, thumbnail_size.y)); if(body_item_render_callback && include_embedded_item) body_item_render_callback(item); @@ -1492,7 +1492,7 @@ namespace QuickMedia { float text_offset_x = body_spacing[body_theme].padding_x; if(draw_thumbnails && load_texture && !item->thumbnail_url.empty() && !merge_with_previous) { std::shared_ptr item_thumbnail = AsyncImageLoader::get_instance().get_thumbnail(item->thumbnail_url, item->thumbnail_is_local, content_size); - content_size = clamp_to_size_x(content_size, sf::Vector2i(width, content_size.y)); + content_size = clamp_to_size_x(content_size, sf::Vector2i(width - body_spacing[body_theme].image_padding_x * 2.0f, content_size.y)); image_height = content_size.y; if(item_thumbnail && item_thumbnail->loading_state == LoadingState::FINISHED_LOADING && item_thumbnail->image->getSize().x > 0 && item_thumbnail->image->getSize().y > 0) { @@ -1515,7 +1515,10 @@ namespace QuickMedia { } // TODO: This wont work if the image has changed to a different image (for example if the image is a local image and it has been overwritten). - item->loaded_image_height = std::max(item->loaded_image_height, image_height); + if(body_size_changed) + item->loaded_image_height = image_height; + else + item->loaded_image_height = std::max(item->loaded_image_height, image_height); } else if(item->thumbnail_size.x > 0) { text_offset_x += body_spacing[body_theme].image_padding_x + content_size.x; // TODO: Fix. This makes the body item have incorrect position when loading and if the item is merge_with_previous? and has an embedded item -- cgit v1.2.3