diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-06-08 17:12:00 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-06-08 17:12:00 +0200 |
commit | 9409d8f67f856da0ecfb2a485c2a757c2338469e (patch) | |
tree | f170fdd8da6c4f16174b466b4e7e079aa9ca777b | |
parent | 0f0bf1c649388c07ae6e8dd784d7402f68691b96 (diff) |
Make card height the same size as the content
-rw-r--r-- | src/Body.cpp | 72 | ||||
-rw-r--r-- | src/VideoPlayer.cpp | 2 |
2 files changed, 45 insertions, 29 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index d84785a..37a67ee 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -1115,13 +1115,20 @@ namespace QuickMedia { int item_index = 0; int drawn_column_index = 0; int num_visible_rows = 1; + int column_max_height = 0; const int num_items = items.size(); sf::Vector2f pos_offset(space_left_column_each, page_scroll); while(item_index < num_items) { BodyItem *item = items[item_index].get(); - if(pos_offset.y + card_height <= -body_spacing[body_theme].body_padding_vertical) { + get_item_height(item, card_max_image_size.x, false, false, false, item_index); + item->current_loaded_height = item->last_loaded_height; + int item_height = item->current_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); + + if(pos_offset.y + item_height <= -body_spacing[body_theme].body_padding_vertical) { top_cut_off = true; if(item_index == selected_item) selected_line_top_visible = false; @@ -1136,26 +1143,31 @@ namespace QuickMedia { if(item_index == selected_item) selected_column = drawn_column_index; - if(item->visible && pos_offset.y + card_height > -body_spacing[body_theme].body_padding_vertical && pos_offset.y < size.y) { - handle_item_render(pos + pos_offset, card_width, card_height, item_index); + 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); + std::shared_ptr<ThumbnailData> item_thumbnail; + if(draw_thumbnails && !item->thumbnail_url.empty()) + item_thumbnail = AsyncImageLoader::get_instance().get_thumbnail(item->thumbnail_url, item->thumbnail_is_local, thumbnail_size); + + get_item_height(item, card_max_image_size.x, true, false, false, item_index); + item->current_loaded_height = item->last_loaded_height; + int item_height = item->current_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); + + 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)); new_view.setViewport(sf::FloatRect(0.0f, scissor_y / (float)window_size.y, 1.0f, size.y / (float)window_size.y)); window.setView(new_view); item_background.set_position(pos + pos_offset); - item_background.set_size(sf::Vector2f(card_width, card_height)); + item_background.set_size(sf::Vector2f(card_width, item_height)); item_background.set_color(sf::Color(28, 32, 39)); item_background.set_band(item_background_prev_pos - (pos + pos_offset), item_background_prev_size); item_background.set_band_color(sf::Color(55, 60, 68)); item_background.draw(window); { - get_item_height(item, card_max_image_size.x, true, false, false, item_index); - sf::Vector2i thumbnail_size = get_item_thumbnail_size(item); - std::shared_ptr<ThumbnailData> item_thumbnail; - if(draw_thumbnails && !item->thumbnail_url.empty()) - item_thumbnail = AsyncImageLoader::get_instance().get_thumbnail(item->thumbnail_url, item->thumbnail_is_local, thumbnail_size); - float image_height = 0.0f; if(item_thumbnail && item_thumbnail->loading_state == LoadingState::APPLIED_TO_TEXTURE && item_thumbnail->texture.getNativeHandle() != 0) { image.setTexture(item_thumbnail->texture, true); @@ -1191,7 +1203,7 @@ namespace QuickMedia { const float text_padding = item_thumbnail ? card_image_text_padding : 0.0f; sf::Vector2f text_pos = sf::Vector2f(pos.x, scissor_y + body_spacing[body_theme].body_padding_vertical) + pos_offset + sf::Vector2f(card_padding_x, card_padding_y) + sf::Vector2f(0.0f, image_height + text_padding); - const float text_height = (card_height - card_padding_y * 2.0f) - image_height - text_padding; + const float text_height = (item_height - card_padding_y * 2.0f) - image_height - text_padding; const float underflow_text = text_pos.y - scissor_y; const float underflow_height = underflow_text < 0.0f ? std::max(0.0f, text_height + underflow_text) : text_height; @@ -1223,7 +1235,7 @@ namespace QuickMedia { } const float gradient_height = 5.0f; - if(text_offset_y >= text_height - gradient_height) { + if(text_offset_y >= text_height - gradient_height && std::abs(item_height - card_height) < 1) { const sf::Vector2f card_bottom(text_pos.x, text_height); const sf::Color color = item_index == selected_item ? sf::Color(55, 60, 68) : sf::Color(28, 32, 39); @@ -1243,7 +1255,7 @@ namespace QuickMedia { last_visible_item = item_index; } else { if(item_index == selected_item) - handle_item_render(pos + pos_offset, card_width, card_height, item_index); + handle_item_render(pos + pos_offset, card_width, item_height, item_index); if(item->keep_alive_frames == 0) { clear_body_item_cache(item); @@ -1263,16 +1275,13 @@ namespace QuickMedia { drawn_column_index = 0; ++num_visible_rows; pos_offset.x = space_left_column_each; - pos_offset.y += card_height + space_left_row_each; + pos_offset.y += column_max_height + space_left_row_each; + column_max_height = 0; } } ++item_index; } - - /*const float body_total_height = num_visible_rows * (card_height + space_left_row_each); - if(top_cut_off && !bottom_cut_off && body_total_height > size.y) - page_scroll = -(body_total_height - (size.y - body_spacing[body_theme].body_padding_vertical));*/ } 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) { @@ -1547,21 +1556,26 @@ namespace QuickMedia { item_height += reaction_max_height + body_spacing[body_theme].reaction_padding_y; } - 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, image_height); - item_height += (padding_y * 2.0f); + if(card_view && card_view_enabled) { + item_height += image_height; + } else { + 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, image_height); + item_height += (padding_y * 2.0f); + } const bool first_height_set = item->last_loaded_height > 0.01f; if(item_index != -1 && (!first_height_set || load_texture)) { const float height_diff = item_height - item->prev_last_loaded_height; - //if(attach_side == AttachSide::TOP) { - // if(item_index < selected_item) - // extra_scroll_target -= height_diff; - //} else if(attach_side == AttachSide::BOTTOM) { - // if(item_index > selected_item) - // extra_scroll_target += height_diff; - //} + /* + if(attach_side == AttachSide::TOP) { + if(item_index < selected_item) + page_scroll -= height_diff; + } else if(attach_side == AttachSide::BOTTOM) { + if(item_index > selected_item) + page_scroll += height_diff; + } + */ item->last_loaded_height = item_height; item->prev_last_loaded_height = item_height; if(!first_height_set) diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index db43ae1..95a3bd4 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -261,6 +261,8 @@ namespace QuickMedia { close(sockets[0]); video_process_id = -1; sockets[0] = -1; + window_handle = None; + connected_to_ipc = false; return Error::EXITED; } } |