From 0c4fd4700d6ee31f6b848d49a6aa7ebfa4a806fa Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 23 Nov 2022 20:41:40 +0100 Subject: Re-add item drawing height diff shifting to fix bumping in item drawing Add newline before codeblock in 4chan if previous line is not a newline. --- src/Body.cpp | 119 +++++++++++++++++++++++++---------------------------------- 1 file changed, 51 insertions(+), 68 deletions(-) (limited to 'src/Body.cpp') diff --git a/src/Body.cpp b/src/Body.cpp index fcf932c..cc0edfa 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -1184,20 +1184,18 @@ namespace QuickMedia { item->prev_height = item->height; if(attach_side == AttachSide::TOP) { - // TODO: Remove - // if(index < selected_item) { - // page_scroll -= height_diff; - // pos.y -= height_diff; - // } + if(index < selected_item) { + page_scroll -= height_diff; + pos.y -= height_diff; + } prev_body_item = item.get(); index = get_next_visible_item(index); } else { - // TODO: Remove - // if(index > selected_item) { - // page_scroll += height_diff; - // pos.y += height_diff; - // } + if(index > selected_item) { + page_scroll += height_diff; + pos.y += height_diff; + } index = prev_index; } @@ -1510,40 +1508,7 @@ namespace QuickMedia { } if(!item->reactions.empty() && include_embedded_item) { - float reaction_offset_x = 0.0f; - item_pos.y += body_spacing[body_theme].reaction_padding_y; - float reaction_max_height = 0.0f; - for(int i = 0; i < (int)item->reactions.size(); ++i) { - auto &reaction = item->reactions[i]; - if(reaction.text) { - reaction.text->updateGeometry(); - reaction.size = { reaction.text->getWidth(), reaction.text->getHeight() }; - reaction.num_lines = reaction.text->getNumLines(); - } - const float reaction_max_height_prev = reaction_max_height; - reaction_max_height = std::max(reaction_max_height, reaction.size.y); - reaction_background.set_size(mgl::vec2f(reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f, reaction.size.y + body_spacing[body_theme].reaction_background_padding_y * 2.0f)); - - const float new_reaction_offset_x = reaction_offset_x + reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f; - if(i != 0 && (new_reaction_offset_x > text_max_width || reaction.num_lines > 1)) { - reaction_offset_x = 0.0f; - item_pos.y += reaction_max_height_prev + body_spacing[body_theme].reaction_padding_y + text_offset_y; - reaction_max_height = reaction.size.y; - reaction_background.set_position(vec2f_floor(item_pos.x + text_offset_x + reaction_offset_x, item_pos.y + padding_y)); - reaction_offset_x = reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x; - } else { - reaction_background.set_position(vec2f_floor(item_pos.x + text_offset_x + reaction_offset_x, item_pos.y + padding_y)); - reaction_offset_x = new_reaction_offset_x + body_spacing[body_theme].reaction_spacing_x; - } - - if(reaction.text) { - reaction.text->set_position(reaction_background.get_position() + mgl::vec2f(body_spacing[body_theme].reaction_background_padding_x, -6.0f + body_spacing[body_theme].reaction_background_padding_y)); - - reaction_background.draw(window); - reaction.text->draw(window); - } - } - item_pos.y += reaction_max_height + body_spacing[body_theme].reaction_padding_y; + item_pos.y += process_reactions(&window, item.get(), text_max_width, item_pos.x + text_offset_x, item_pos.y, padding_y, text_offset_y, true); } if(item_index == selected_item && item->timestamp_text) { @@ -1681,6 +1646,47 @@ namespace QuickMedia { } } + float Body::process_reactions(mgl::Window *window, BodyItem *item, float max_width, float x, float y, float padding_y, float text_offset_y, bool draw) { + float height = 0.0f; + float reaction_offset_x = 0.0f; + height += body_spacing[body_theme].reaction_padding_y; + float reaction_max_height = 0.0f; + for(int i = 0; i < (int)item->reactions.size(); ++i) { + auto &reaction = item->reactions[i]; + if(reaction.size.x < 0.001f && reaction.text && !draw) { + reaction.text->setMaxWidth(max_width); + reaction.text->updateGeometry(); + reaction.size = { reaction.text->getWidth(), reaction.text->getHeight() }; + reaction.num_lines = reaction.text->getNumLines(); + } + const float reaction_max_height_prev = reaction_max_height; + reaction_max_height = std::max(reaction_max_height, reaction.size.y); + reaction_background.set_size(mgl::vec2f(reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f, reaction.size.y + body_spacing[body_theme].reaction_background_padding_y * 2.0f)); + + const float new_reaction_offset_x = reaction_offset_x + reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f; + if(i != 0 && (new_reaction_offset_x > max_width || reaction.num_lines > 1)) { + reaction_offset_x = 0.0f; + height += reaction_max_height_prev + body_spacing[body_theme].reaction_padding_y + text_offset_y; + reaction_max_height = reaction.size.y; + reaction_background.set_position(vec2f_floor(x + reaction_offset_x, y + height + padding_y)); + reaction_offset_x = reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x; + } else { + reaction_background.set_position(vec2f_floor(x + reaction_offset_x, y + height + padding_y)); + reaction_offset_x = new_reaction_offset_x + body_spacing[body_theme].reaction_spacing_x; + } + + if(reaction.text) { + reaction.text->set_position(reaction_background.get_position() + mgl::vec2f(body_spacing[body_theme].reaction_background_padding_x, -6.0f + body_spacing[body_theme].reaction_background_padding_y)); + } + + if(draw && reaction.text) { + reaction_background.draw(*window); + reaction.text->draw(*window); + } + } + return height + reaction_max_height + body_spacing[body_theme].reaction_padding_y; + } + float Body::get_item_height(BodyItem *item, float width, bool load_texture, bool include_embedded_item, bool merge_with_previous, int item_index) { const bool rendering_card_view = card_view && card_view_enabled; mgl::vec2i content_size = get_item_thumbnail_size(item); @@ -1747,30 +1753,7 @@ namespace QuickMedia { // TODO: Only do this if reactions dirty? if(!item->reactions.empty() && include_embedded_item) { - float reaction_offset_x = 0.0f; - item_height += body_spacing[body_theme].reaction_padding_y; - float reaction_max_height = 0.0f; - for(int i = 0; i < (int)item->reactions.size(); ++i) { - auto &reaction = item->reactions[i]; - if(reaction.size.x < 0.001f && reaction.text) { - reaction.text->setMaxWidth(text_max_width); - reaction.text->updateGeometry(); - reaction.size = { reaction.text->getWidth(), reaction.text->getHeight() }; - reaction.num_lines = reaction.text->getNumLines(); - } - const float reaction_max_height_prev = reaction_max_height; - reaction_max_height = std::max(reaction_max_height, reaction.size.y); - - const float new_reaction_offset_x = reaction_offset_x + reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f; - if(i != 0 && (new_reaction_offset_x > text_max_width || reaction.num_lines > 1)) { - item_height += reaction_max_height_prev + body_spacing[body_theme].reaction_padding_y + std::floor(6.0f * get_config().scale); - reaction_max_height = reaction.size.y; - reaction_offset_x = reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x; - } else { - reaction_offset_x = new_reaction_offset_x + body_spacing[body_theme].reaction_spacing_x; - } - } - item_height += reaction_max_height + body_spacing[body_theme].reaction_padding_y; + item_height += process_reactions(nullptr, item, text_max_width, 0.0f, 0.0f, 0.0f, std::floor(6.0f * get_config().scale), false); has_loaded_text = true; } -- cgit v1.2.3