diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Body.cpp | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index f316e2f..2e267c5 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -604,7 +604,19 @@ namespace QuickMedia { } } - const double scroll_diff = extra_scroll_target - extra_scroll_current; + if(prev_selected_item < 0 || prev_selected_item >= (int)items.size()) { + prev_selected_item = selected_item; + } + + const int prev_body_item_index = get_previous_visible_item(selected_item); + bool selected_merge_with_previous = !items.empty() && body_item_merge_handler && body_item_merge_handler(prev_body_item_index == -1 ? nullptr : items[prev_body_item_index].get(), items[selected_item].get()); + + double target_scroll = extra_scroll_target; + if(selected_merge_with_previous) + target_scroll += spacing_y; + if(selected_item == last_visible_item) + target_scroll -= selected_item_height; + const double scroll_diff = target_scroll - extra_scroll_current; const double scroll_move_speed = 25.0; extra_scroll_current += (scroll_diff * std::min(1.0, frame_time * scroll_move_speed)); @@ -619,9 +631,10 @@ namespace QuickMedia { } bool selected_item_fits_on_screen = selected_item_height <= size.y; - if(shit_hack_body_size_change == 0 && selected_item_fits_on_screen && render_selected_item_bg && !first_item_fully_visible && !last_item_fully_visible && items_cut_off && (selected_item == first_visible_item || selected_item == last_visible_item || selected_item == first_fully_visible_item || selected_item == last_fully_visible_item)) { + if(shit_hack_body_size_change == 0 && selected_item_fits_on_screen && render_selected_item_bg && !first_item_fully_visible && !last_item_fully_visible && items_cut_off && (selected_item == first_visible_item || selected_item == last_visible_item)) { page_scroll += scroll_smooth_diff; - keep_selected_inside_body = false; + if(selected_item != first_fully_visible_item && selected_item != last_fully_visible_item) + keep_selected_inside_body = false; } //item_separator.setFillColor(line_separator_color); @@ -652,10 +665,6 @@ namespace QuickMedia { return; } - if(prev_selected_item < 0 || prev_selected_item >= (int)items.size()) { - prev_selected_item = selected_item; - } - // TODO: Optimize this, especially when scrolling to top/bottom. // TODO: If the thumbnail fallback size is larger than the real thumbnail size then the scroll will be incorrect when scrolling down // because first we scroll by a larger value and then the thumbnail size changes when the thumbnail has finished loading @@ -708,10 +717,6 @@ namespace QuickMedia { extra_scroll_target -= (page_scroll - scroll_before); } - bool merge_with_previous = false; - const int prev_body_item_index = get_previous_visible_item(selected_item); - merge_with_previous = body_item_merge_handler && body_item_merge_handler(prev_body_item_index == -1 ? nullptr : items[prev_body_item_index].get(), items[selected_item].get()); - if(keep_selected_inside_body) { if(!first_item_fully_visible && !last_item_fully_visible) { if(offset_to_top > 0.0f) @@ -737,7 +742,7 @@ namespace QuickMedia { } } - selected_item_height = get_item_height(items[selected_item].get(), size.x, true, true, merge_with_previous, selected_item); + selected_item_height = get_item_height(items[selected_item].get(), size.x, true, true, selected_merge_with_previous, selected_item); selected_item_height += spacing_y; selected_item_fits_on_screen = selected_item_height <= size.y; selected_line_top_visible = pos.y - start_y + page_scroll >= 0.0f; @@ -756,15 +761,15 @@ namespace QuickMedia { if(keep_selected_inside_body) { if(page_scroll > size.y - selected_item_height && selected_item_fits_on_screen) { page_scroll = size.y - selected_item_height; - if(merge_with_previous) + if(selected_merge_with_previous) page_scroll += spacing_y*2.0f; int next_body_item_index = get_next_visible_item(selected_item); const bool merge_with_next = next_body_item_index != -1 && body_item_merge_handler && body_item_merge_handler(items[selected_item].get(), items[next_body_item_index].get()); - if(!merge_with_previous && merge_with_next) + if(!selected_merge_with_previous && merge_with_next) page_scroll += spacing_y; - } else if(page_scroll < (merge_with_previous ? spacing_y : 0.0f) && selected_line_top_visible && selected_item_fits_on_screen) { - if(merge_with_previous) + } else if(page_scroll < (selected_merge_with_previous ? spacing_y : 0.0f) && selected_line_top_visible && selected_item_fits_on_screen) { + if(selected_merge_with_previous) page_scroll = spacing_y; else page_scroll = 0.0f; @@ -848,7 +853,7 @@ namespace QuickMedia { offset_to_top = prev_pos.y - start_y; BodyItem *prev_body_item = prev_body_item_index == -1 ? nullptr : items[prev_body_item_index].get(); - merge_with_previous = false; + bool after_merge_with_previous = false; sf::Vector2f after_pos = pos; for(int i = selected_item; i < num_items;) { @@ -860,11 +865,11 @@ namespace QuickMedia { continue; } - merge_with_previous = body_item_merge_handler && body_item_merge_handler(prev_body_item, item.get()); - if(merge_with_previous) + after_merge_with_previous = body_item_merge_handler && body_item_merge_handler(prev_body_item, item.get()); + if(after_merge_with_previous) after_pos.y -= spacing_y; - float item_height = get_item_height(item.get(), size.x, true, true, merge_with_previous, i); + float item_height = get_item_height(item.get(), size.x, true, true, after_merge_with_previous, i); if(after_pos.y < start_y) { items_cut_off = true; @@ -886,7 +891,7 @@ namespace QuickMedia { // 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); glScissor(scissor_pos.x, (int)window_size.y - (int)scissor_pos.y - (int)scissor_size.y, scissor_size.x, scissor_size.y); - draw_item(window, item.get(), after_pos, size, item_height, i, content_progress, true, merge_with_previous); + draw_item(window, item.get(), after_pos, size, item_height, i, content_progress, true, after_merge_with_previous); glDisable(GL_SCISSOR_TEST); after_pos.y += item_height; after_pos.y += spacing_y; @@ -922,7 +927,7 @@ namespace QuickMedia { if(last_fully_visible_item == -1) last_fully_visible_item = selected_item; - offset_to_bottom = size.y - (after_pos.y - start_y - (last_item_fully_visible && merge_with_previous ? spacing_y : 0.0f)); + offset_to_bottom = size.y - (after_pos.y - start_y - (last_item_fully_visible && after_merge_with_previous ? spacing_y : 0.0f)); if(!last_item_fully_visible_set) last_item_fully_visible = true; |