diff options
Diffstat (limited to 'src/Body.cpp')
-rw-r--r-- | src/Body.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index 2d429f8..6f1d9ae 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -18,10 +18,11 @@ static const float padding_y = 5.0f; static const float embedded_item_padding_y = 0.0f; static const double thumbnail_fade_duration_sec = 0.1; -const float reaction_background_padding_x = 7.0f; -const float reaction_background_padding_y = 3.0f; -const float reaction_spacing_x = 5.0f; +static const float reaction_background_padding_x = 7.0f; +static const float reaction_background_padding_y = 3.0f; +static const float reaction_spacing_x = 5.0f; static const float reaction_padding_y = 7.0f; +static const int embedded_item_font_size = 14; namespace QuickMedia { BodyItem::BodyItem(std::string _title) : @@ -101,7 +102,7 @@ namespace QuickMedia { Body::Body(Program *program, sf::Texture &loading_icon_texture) : progress_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 14), replies_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 14), - embedded_item_load_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 14), + embedded_item_load_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), embedded_item_font_size), draw_thumbnails(true), wrap_around(false), line_separator_color(sf::Color(32, 37, 43, 255)), @@ -373,7 +374,9 @@ namespace QuickMedia { clear_body_item_cache(body_item->embedded_item.get()); } last_item_fully_visible = true; - items_cut_off = false; + top_cut_off = false; + bottom_cut_off = false; + body_full = false; offset_to_top = 0.0f; offset_to_bottom = 0.0f; return; @@ -439,22 +442,25 @@ namespace QuickMedia { page_scroll = 0.0f; } - if(items_cut_off) { - if(offset_to_top > 0.0f) + if(top_cut_off || bottom_cut_off) { + if(attach_side == AttachSide::TOP && offset_to_top > 0.0f) { page_scroll -= offset_to_top; - else if(offset_to_bottom > 0.0f) + } else if(attach_side == AttachSide::BOTTOM && offset_to_bottom > 0.0f) { page_scroll += offset_to_bottom; + } } else { - if(attach_side == AttachSide::TOP) + if(attach_side == AttachSide::TOP) { page_scroll -= offset_to_top; - else if(attach_side == AttachSide::BOTTOM) + } else if(attach_side == AttachSide::BOTTOM) { page_scroll += offset_to_bottom; + } } pos.y += page_scroll; - bool last_item_fully_visible_set = false; - bool items_cut_off_set = false; + last_item_fully_visible = true; + top_cut_off = false; + bottom_cut_off = false; sf::Vector2u window_size = window.getSize(); @@ -471,10 +477,8 @@ namespace QuickMedia { float item_height = get_item_height(item.get(), size.x); prev_pos.y -= (item_height + spacing_y); - if(prev_pos.y < start_y) { - items_cut_off = true; - items_cut_off_set = true; - } + if(prev_pos.y < start_y) + top_cut_off = true; if(prev_pos.y + item_height + spacing_y <= start_y) break; @@ -497,11 +501,12 @@ namespace QuickMedia { if(!item->visible) continue; + if(after_pos.y < start_y) + top_cut_off = true; + if(after_pos.y - start_y >= size.y) { last_item_fully_visible = false; - items_cut_off = true; - last_item_fully_visible_set = true; - items_cut_off_set = true; + bottom_cut_off = true; break; } @@ -518,9 +523,7 @@ namespace QuickMedia { if(after_pos.y - start_y > size.y) { last_item_fully_visible = false; - items_cut_off = true; - last_item_fully_visible_set = true; - items_cut_off_set = true; + bottom_cut_off = true; } else { last_fully_visible_item = i; } @@ -530,11 +533,10 @@ namespace QuickMedia { last_fully_visible_item = selected_item; offset_to_bottom = size.y - (after_pos.y - start_y); - - if(!last_item_fully_visible_set) - last_item_fully_visible = true; - if(!items_cut_off_set) - items_cut_off = false; + if(top_cut_off && (bottom_cut_off || offset_to_bottom < 5.0f)) + body_full = true; + else + body_full = false; for(auto it = item_thumbnail_textures.begin(); it != item_thumbnail_textures.end();) { if(!it->second->referenced) @@ -794,7 +796,7 @@ namespace QuickMedia { if(include_embedded_item && item->embedded_item_status != FetchStatus::NONE) { const float border_width = 4.0f; const float embedded_item_width = std::floor(size.x - text_offset_x - border_width - padding_x); - float embedded_item_height = item->embedded_item ? get_item_height(item->embedded_item.get(), embedded_item_width, true, false) : (embedded_item_load_text.getLocalBounds().height + embedded_item_padding_y * 2.0f); + float embedded_item_height = item->embedded_item ? get_item_height(item->embedded_item.get(), embedded_item_width, true, false) : ((embedded_item_font_size + 5.0f) + embedded_item_padding_y * 2.0f); sf::RectangleShape border_left(sf::Vector2f(border_width, std::floor(embedded_item_height))); border_left.setFillColor(sf::Color::White); border_left.setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + 4.0f)); @@ -806,7 +808,7 @@ namespace QuickMedia { draw_item(window, item->embedded_item.get(), embedded_item_pos, embedded_item_size, false); } else { embedded_item_load_text.setString(embedded_item_status_to_string(item->embedded_item_status)); - embedded_item_load_text.setPosition(std::floor(item_pos.x + text_offset_x + border_width + padding_x), std::floor(item_pos.y + embedded_item_height * 0.5f - embedded_item_load_text.getLocalBounds().height * 0.5f + 4.0f)); + embedded_item_load_text.setPosition(std::floor(item_pos.x + text_offset_x + border_width + padding_x), std::floor(item_pos.y + embedded_item_height * 0.5f - (embedded_item_font_size + 5.0f) * 0.5f + 4.0f)); window.draw(embedded_item_load_text); } item_pos.y += embedded_item_height + 4.0f; @@ -939,7 +941,7 @@ namespace QuickMedia { if(item->embedded_item) item_height += (get_item_height(item->embedded_item.get(), width, load_texture, false) + 4.0f + embedded_item_padding_y * 2.0f); else - item_height += (embedded_item_load_text.getLocalBounds().height + 4.0f + embedded_item_padding_y * 2.0f); + item_height += ((embedded_item_font_size + 5.0f) + 4.0f + embedded_item_padding_y * 2.0f); } if(item->description_text) { item_height += item->description_text->getHeight() - 2.0f; |