diff options
Diffstat (limited to 'src/Body.cpp')
-rw-r--r-- | src/Body.cpp | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index 67c5c8e..fa56ded 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -125,7 +125,7 @@ namespace QuickMedia { post_number = other.post_number; userdata = other.userdata; loaded_height = other.loaded_height; - loaded_image_height = other.loaded_image_height; + loaded_image_size = other.loaded_image_size; loaded_content_height = other.loaded_content_height; embedded_item_status = other.embedded_item_status; if(other.embedded_item) { @@ -790,7 +790,7 @@ namespace QuickMedia { } void Body::update_dirty_state(BodyItem *body_item, float width) { - if(body_item->dirty) { + if(body_item->dirty || (body_size_changed && body_item->title_text)) { body_item->dirty = false; // TODO: Find a way to optimize fromUtf8 sf::String str = sf::String::fromUtf8(body_item->get_title().begin(), body_item->get_title().end()); @@ -804,7 +804,7 @@ namespace QuickMedia { body_item->title_text->updateGeometry(); } - if(body_item->dirty_description) { + if(body_item->dirty_description || (body_size_changed && body_item->description_text)) { body_item->dirty_description = false; sf::String str = sf::String::fromUtf8(body_item->get_description().begin(), body_item->get_description().end()); if(body_item->description_text) { @@ -817,7 +817,7 @@ namespace QuickMedia { body_item->description_text->updateGeometry(); } - if(body_item->dirty_author) { + if(body_item->dirty_author || (body_size_changed && body_item->author_text)) { body_item->dirty_author = false; sf::String str = sf::String::fromUtf8(body_item->get_author().begin(), body_item->get_author().end()); if(body_item->author_text) { @@ -830,7 +830,7 @@ namespace QuickMedia { body_item->author_text->updateGeometry(); } - if(body_item->dirty_timestamp) { + if(body_item->dirty_timestamp || (body_size_changed && body_item->timestamp_text)) { body_item->dirty_timestamp = false; if(body_item->get_timestamp() != 0) { @@ -1215,21 +1215,18 @@ namespace QuickMedia { float text_offset_y = 0.0f; if(item->author_text) { item->author_text->setPosition(text_pos); - item->author_text->setMaxWidth(card_max_image_size.x); item->author_text->draw(window); text_offset_y += item->author_text->getHeight(); } if(item->title_text) { item->title_text->setPosition(text_pos + sf::Vector2f(0.0f, text_offset_y)); - item->title_text->setMaxWidth(card_max_image_size.x); item->title_text->draw(window); text_offset_y += item->title_text->getHeight(); } if(item->description_text) { item->description_text->setPosition(text_pos + sf::Vector2f(0.0f, text_offset_y)); - item->description_text->setMaxWidth(card_max_image_size.x); item->description_text->draw(window); text_offset_y += item->description_text->getHeight(); } @@ -1367,7 +1364,7 @@ namespace QuickMedia { loading_icon.setScale(get_ratio(loading_icon_size, new_loading_icon_size)); loading_icon.setRotation(elapsed_time_sec * 400.0); window.draw(loading_icon); - text_offset_x += body_spacing[body_theme].image_padding_x + content_size.x; + text_offset_x += body_spacing[body_theme].image_padding_x + item->loaded_image_size.x; } } else if(item->thumbnail_size.x > 0) { text_offset_x += body_spacing[body_theme].image_padding_x + thumbnail_size.x; @@ -1379,7 +1376,6 @@ namespace QuickMedia { const float timestamp_text_y = std::floor(item_pos.y + padding_y - text_offset_y); if(item->author_text && !merge_with_previous) { item->author_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - text_offset_y)); - item->author_text->setMaxWidth(text_max_width); item->author_text->draw(window); sf::Vector2f replies_text_pos = item->author_text->getPosition() + sf::Vector2f(0.0f, 5.0f); @@ -1424,7 +1420,6 @@ namespace QuickMedia { //window.draw(title_text); if(item->title_text) { item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - text_offset_y)); - item->title_text->setMaxWidth(text_max_width); item->title_text->draw(window); item_pos.y += item->title_text->getHeight() - 2.0f + std::floor(3.0f * get_ui_scale()); } @@ -1432,7 +1427,6 @@ namespace QuickMedia { if(item->description_text) { float height_offset = 0.0f; item->description_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - text_offset_y) + height_offset); - item->description_text->setMaxWidth(text_max_width); item->description_text->draw(window); item_pos.y += item->description_text->getHeight() - 2.0f; } @@ -1444,7 +1438,6 @@ namespace QuickMedia { // TODO: Fix first row wrap-around for(int i = 0; i < item->reactions.size(); ++i) { auto &reaction = item->reactions[i]; - reaction.text->setMaxWidth(text_max_width); reaction.text->updateGeometry(); reaction_max_height = std::max(reaction_max_height, reaction.text->getHeight()); reaction.text->setPosition(std::floor(item_pos.x + text_offset_x + reaction_offset_x + body_spacing[body_theme].reaction_background_padding_x), std::floor(item_pos.y + padding_y - 4.0f + body_spacing[body_theme].reaction_background_padding_y)); @@ -1489,7 +1482,6 @@ namespace QuickMedia { const bool rendering_card_view = card_view && card_view_enabled; sf::Vector2i content_size = get_item_thumbnail_size(item); - 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<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, sf::Vector2i(width - (rendering_card_view ? 0.0f : body_spacing[body_theme].image_padding_x * 2.0f), content_size.y)); @@ -1507,20 +1499,19 @@ namespace QuickMedia { auto image_size = item_thumbnail->texture.getSize(); sf::Vector2f image_size_f(image_size.x, image_size.y); auto new_image_size = clamp_to_size(image_size_f, to_vec2f(content_size)); - text_offset_x += body_spacing[body_theme].image_padding_x + new_image_size.x; - item->loaded_image_height = new_image_size.y; + item->loaded_image_size = new_image_size; } else { - text_offset_x += body_spacing[body_theme].image_padding_x + content_size.x; - if(item->loaded_image_height < 0.1f) - item->loaded_image_height = content_size.y; + if(item->loaded_image_size.y < 0.1f) + item->loaded_image_size = to_vec2f(content_size); } } else if(item->thumbnail_size.x > 0) { - text_offset_x += body_spacing[body_theme].image_padding_x + content_size.x; + item->loaded_image_size = sf::Vector2f(body_spacing[body_theme].image_padding_x + content_size.x, 0.0f); // 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 //if(!merge_with_previous) // image_height = content_size.y; } + const float text_offset_x = body_spacing[body_theme].padding_x + body_spacing[body_theme].image_padding_x + item->loaded_image_size.x; const float text_max_width = rendering_card_view ? width : (width - text_offset_x - body_spacing[body_theme].image_padding_x); if(load_texture) @@ -1574,11 +1565,11 @@ namespace QuickMedia { item_height = item->loaded_content_height; if(rendering_card_view) { - item_height += item->loaded_image_height; + item_height += item->loaded_image_size.y; } else { const bool has_thumbnail = draw_thumbnails && !item->thumbnail_url.empty() && !merge_with_previous; const float padding_y = has_thumbnail ? body_spacing[body_theme].padding_y : body_spacing[body_theme].padding_y_text_only; - item_height = std::max(item_height, item->loaded_image_height); + item_height = std::max(item_height, item->loaded_image_size.y); item_height += (padding_y * 2.0f); } |