From 5b3becc79461d4ecf015e33515871cc09e26e04e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 10 Jun 2021 03:50:20 +0200 Subject: Make selected item height the same as the max item height in the row (in card view) --- src/Body.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Body.cpp b/src/Body.cpp index c25b75f..df52386 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -1112,8 +1112,9 @@ namespace QuickMedia { int item_index = 0; int drawn_column_index = 0; + bool row_has_selected_item = false; int num_visible_rows = 1; - int column_max_height = 0; + int row_max_height = 0; const int num_items = items.size(); sf::Vector2f pos_offset(space_left_column_each, page_scroll); @@ -1123,7 +1124,7 @@ namespace QuickMedia { get_item_height(item, card_max_image_size.x, false, false, false, item_index); int item_height = item->loaded_height; item_height = std::min(card_height, item_height + ((draw_thumbnails && !item->thumbnail_url.empty()) ? card_image_text_padding : 0) + card_padding_y * 2 + 5); - column_max_height = std::max(column_max_height, item_height); + row_max_height = std::max(row_max_height, item_height); if(pos_offset.y + item_height <= -body_spacing[body_theme].body_padding_vertical) { top_cut_off = true; @@ -1137,8 +1138,10 @@ namespace QuickMedia { selected_line_bottom_visible = false; } - if(item_index == selected_item) + if(item_index == selected_item) { selected_column = drawn_column_index; + row_has_selected_item = true; + } if(item->visible && pos_offset.y + item_height > -body_spacing[body_theme].body_padding_vertical && pos_offset.y < size.y) { sf::Vector2i thumbnail_size = get_item_thumbnail_size(item); @@ -1149,7 +1152,7 @@ namespace QuickMedia { get_item_height(item, card_max_image_size.x, true, false, false, item_index); item_height = item->loaded_height; item_height = std::min(card_height, item_height + (item_thumbnail ? card_image_text_padding : 0) + card_padding_y * 2 + 5); - column_max_height = std::max(column_max_height, item_height); + row_max_height = std::max(row_max_height, item_height); handle_item_render(pos + pos_offset, card_width, item_height, item_index); sf::View new_view(sf::FloatRect(0.0f, 0.0f, window_size.x, size.y)); @@ -1268,16 +1271,23 @@ namespace QuickMedia { ++drawn_column_index; if(drawn_column_index == num_columns) { + if(row_has_selected_item) + item_background_target_size = sf::Vector2f(card_width, row_max_height); + drawn_column_index = 0; ++num_visible_rows; pos_offset.x = space_left_column_each; - pos_offset.y += column_max_height + space_left_row_each; - column_max_height = 0; + pos_offset.y += row_max_height + space_left_row_each; + row_max_height = 0; + row_has_selected_item = false; } } ++item_index; } + + if(row_has_selected_item) + item_background_target_size = sf::Vector2f(card_width, row_max_height); } void Body::draw_item(sf::RenderWindow &window, BodyItem *item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress, bool include_embedded_item, bool merge_with_previous) { -- cgit v1.2.3