From bc26e012f3041529939d38ac522c18499ddff982 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 12 Apr 2021 19:46:14 +0200 Subject: Stop fucking flickering again in room list --- TODO | 2 +- include/Body.hpp | 4 +++- src/Body.cpp | 25 ++++++++++++++++++------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index efc890f..547ac7a 100644 --- a/TODO +++ b/TODO @@ -158,4 +158,4 @@ Make video visible when reading comments (youtube). Convert nyaa.si/spotify/soundcloud date from ISO date string to local time. When ui is scaled then the predicated thumbnail size will be wrong since its scaled in Body but not in the plugins where they are requested. Check if get_page handlers in pages need to check if next batch is valid. If the server returns empty next batch we shouldn't fetch the first page... -Remove dependency on wget when using manganelo... Figure out why manganelo causes curl to stop download for up to 20 seconds and then fail. \ No newline at end of file +Cloudflare kicks in when downloading manga on manganelo.. figure out a way to bypass it. This doesn't seem to happen when using python requests as is done in AutoMedia. \ No newline at end of file diff --git a/include/Body.hpp b/include/Body.hpp index 7c8226e..fb22a21 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -153,6 +153,8 @@ namespace QuickMedia { sf::Vector2i thumbnail_size; std::vector reactions; // TODO: Move to a different body item type std::shared_ptr extra; // TODO: Remove + + float calculated_height = -1.0f; private: // TODO: Clean up these strings when set in text, and get_title for example should return |title_text.getString()| // TODO: Use sf::String instead, removes the need to convert to utf32 every time the text is dirty (for example when resizing window) @@ -226,7 +228,7 @@ namespace QuickMedia { // because of Text::setMaxWidth void draw_item(sf::RenderWindow &window, BodyItem *item, sf::Vector2f pos, sf::Vector2f size, bool include_embedded_item = true, bool is_embedded = false); - float get_item_height(BodyItem *item, float width, bool load_texture = true, bool include_embedded_item = true, bool merge_with_previous = false); + float get_item_height(BodyItem *item, float width, bool load_texture = true, bool include_embedded_item = true, bool merge_with_previous = false, int item_index = -1); float get_spacing_y() const; static bool string_find_case_insensitive(const std::string &str, const std::string &substr); diff --git a/src/Body.cpp b/src/Body.cpp index 4c715ed..5c40c96 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -100,6 +100,7 @@ namespace QuickMedia { author_color = other.author_color; description_color = other.description_color; extra = other.extra; + calculated_height = other.calculated_height; return *this; } @@ -548,7 +549,7 @@ namespace QuickMedia { while(num_items_scrolled < selected_int_diff_abs && i < num_items) { if(items[i]->visible) { const bool merge_with_previous = body_item_merge_handler && body_item_merge_handler(prev_body_item, items[i].get()); - page_scroll += get_item_height(items[i].get(), size.x, selected_int_diff_abs < 50, true, merge_with_previous); + page_scroll += get_item_height(items[i].get(), size.x, selected_int_diff_abs < 50, true, merge_with_previous, i); if(merge_with_previous) page_scroll -= spacing_y; page_scroll += spacing_y; @@ -566,7 +567,7 @@ namespace QuickMedia { if(items[i]->visible) { prev_body_item = get_previous_visible_item(i); const bool merge_with_previous = body_item_merge_handler && body_item_merge_handler(prev_body_item, items[i].get()); - page_scroll -= get_item_height(items[i].get(), size.x, selected_int_diff_abs < 50, true, merge_with_previous); + page_scroll -= get_item_height(items[i].get(), size.x, selected_int_diff_abs < 50, true, merge_with_previous, i); if(merge_with_previous) page_scroll += spacing_y; page_scroll -= spacing_y; @@ -580,7 +581,7 @@ namespace QuickMedia { bool merge_with_previous = false; merge_with_previous = body_item_merge_handler && body_item_merge_handler(get_previous_visible_item(selected_item), items[selected_item].get()); - selected_item_height = get_item_height(items[selected_item].get(), size.x, true, true, merge_with_previous); + selected_item_height = get_item_height(items[selected_item].get(), size.x, true, true, merge_with_previous, selected_item); selected_item_height += spacing_y; bool selected_item_fits_on_screen = selected_item_height <= size.y; selected_line_top_visible = pos.y - start_y + page_scroll >= 0.0f; @@ -648,7 +649,9 @@ namespace QuickMedia { const bool merge_with_previous = body_item_merge_handler && body_item_merge_handler(prev_body_item, item.get()); item->last_drawn_time = elapsed_time_sec; - float item_height = get_item_height(item.get(), size.x, true, true, merge_with_previous); + float extra_page_scroll = page_scroll; + float item_height = get_item_height(item.get(), size.x, true, true, merge_with_previous, i); + prev_pos.y += (page_scroll - extra_page_scroll); float item_height_with_merge = item_height; item_height_with_merge += spacing_y; prev_pos.y -= item_height_with_merge; @@ -694,6 +697,10 @@ namespace QuickMedia { if(merge_with_previous) after_pos.y -= spacing_y; + float extra_page_scroll = page_scroll; + float item_height = get_item_height(item.get(), size.x, true, true, merge_with_previous, i); + after_pos.y += (page_scroll - extra_page_scroll); + if(after_pos.y < start_y) { items_cut_off = true; first_item_fully_visible = false; @@ -710,7 +717,6 @@ namespace QuickMedia { } item->last_drawn_time = elapsed_time_sec; - float item_height = get_item_height(item.get(), size.x, true, true, merge_with_previous); // This is needed here rather than above the loop, since update_dirty_text cant be called inside scissor because it corrupts the text for some reason glEnable(GL_SCISSOR_TEST); @@ -898,7 +904,7 @@ namespace QuickMedia { update_dirty_state(item, size.x); item->last_drawn_time = draw_timer.getElapsedTime().asMilliseconds(); sf::Vector2u window_size = window.getSize(); - get_item_height(item, size.x, true, false); + get_item_height(item, size.x, true, false, false, -1); if(!is_embedded) { glEnable(GL_SCISSOR_TEST); glScissor(pos.x, (int)window_size.y - (int)pos.y - (int)size.y, size.x, size.y); @@ -1143,7 +1149,7 @@ namespace QuickMedia { } } - float Body::get_item_height(BodyItem *item, float width, bool load_texture, bool include_embedded_item, bool merge_with_previous) { + float Body::get_item_height(BodyItem *item, float width, bool load_texture, bool include_embedded_item, bool merge_with_previous, int item_index) { float image_height = 0.0f; float text_offset_x = padding_x; if(draw_thumbnails && !item->thumbnail_url.empty() && !merge_with_previous) { @@ -1236,6 +1242,11 @@ namespace QuickMedia { item_height = std::max(item_height, image_height); item_height += (padding_y * 2.0f); + + if(attach_side == AttachSide::TOP && item_index != -1 && item_index < selected_item && item->calculated_height >= 0.0f) + page_scroll += (item_height - item->calculated_height); + item->calculated_height = item_height; + return item_height; } -- cgit v1.2.3