aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp52
-rw-r--r--src/Text.cpp5
2 files changed, 36 insertions, 21 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index fd6ad07..39f6e01 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -46,6 +46,10 @@ namespace QuickMedia {
description_text = std::make_unique<Text>(*other.description_text);
else
description_text = nullptr;
+ if(other.author_text)
+ author_text = std::make_unique<Text>(*other.author_text);
+ else
+ author_text = nullptr;
replies = other.replies;
post_number = other.post_number;
title_color = other.title_color;
@@ -56,7 +60,6 @@ namespace QuickMedia {
bold_font(bold_font),
cjk_font(cjk_font),
progress_text("", *font, 14),
- author_text("", *bold_font, 16),
replies_text("", *font, 14),
draw_thumbnails(false),
wrap_around(false),
@@ -66,7 +69,6 @@ namespace QuickMedia {
selected_item(0)
{
progress_text.setFillColor(sf::Color::White);
- author_text.setFillColor(sf::Color::White);
replies_text.setFillColor(sf::Color(129, 162, 190));
thumbnail_resize_target_size.x = 200;
thumbnail_resize_target_size.y = 119;
@@ -390,7 +392,11 @@ namespace QuickMedia {
if(body_item->dirty_author) {
body_item->dirty_author = false;
sf::String str = sf::String::fromUtf8(body_item->get_author().data(), body_item->get_author().data() + body_item->get_author().size());
- author_text.setString(std::move(str));
+ if(body_item->author_text)
+ body_item->author_text->setString(std::move(str));
+ else
+ body_item->author_text = std::make_unique<Text>(std::move(str), bold_font, cjk_font, 14, size.x - 50 - image_padding_x * 2.0f);
+ body_item->author_text->updateGeometry();
}
}
@@ -403,13 +409,13 @@ namespace QuickMedia {
if(item->visible) {
float item_height = 0.0f;
if(!item->get_title().empty()) {
- item_height += item->title_text->getHeight();
+ item_height += item->title_text->getHeight() - 2.0f;
}
if(!item->get_author().empty()) {
- item_height += author_text.getCharacterSize() + 2.0f;
+ item_height += item->author_text->getHeight() - 2.0f;
}
if(item->description_text) {
- item_height += item->description_text->getHeight();
+ item_height += item->description_text->getHeight() - 2.0f;
}
if(draw_thumbnails && !item->thumbnail_url.empty()) {
auto &item_thumbnail = item_thumbnail_textures[item->thumbnail_url];
@@ -421,7 +427,7 @@ namespace QuickMedia {
}
item_height = std::max(item_height, image_height);
}
- item_height += spacing_y + padding_y * 2.0f;
+ item_height += (spacing_y + padding_y * 2.0f);
visible_height += item_height;
if(visible_height >= size.y) {
--first_visible_item;
@@ -452,13 +458,13 @@ namespace QuickMedia {
float item_height = 0.0f;
if(!item->get_title().empty()) {
- item_height += item->title_text->getHeight();
+ item_height += item->title_text->getHeight() - 2.0f;
}
if(!item->get_author().empty()) {
- item_height += author_text.getCharacterSize() + 2.0f;
+ item_height += item->author_text->getHeight() - 2.0f;
}
if(item->description_text) {
- item_height += item->description_text->getHeight();
+ item_height += item->description_text->getHeight() - 2.0f;
}
if(draw_thumbnails && !item->thumbnail_url.empty()) {
float image_height = image_fallback.getSize().y;
@@ -514,27 +520,31 @@ namespace QuickMedia {
}
if(!item->get_author().empty()) {
- author_text.setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y));
- window.draw(author_text);
+ item->author_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 6.0f));
+ item->author_text->setMaxWidth(size.x - text_offset_x - image_padding_x * 2.0f);
+ item->author_text->draw(window);
+
+ sf::Vector2f replies_text_pos = item->author_text->getPosition() + sf::Vector2f(0.0f, 5.0f);
+ replies_text_pos.x += item->author_text->getWidth() + 5.0f;
+ replies_text.setPosition(replies_text_pos);
- sf::Vector2f replies_text_pos = author_text.getPosition();
- replies_text_pos.x += author_text.getLocalBounds().width + 5.0f;
+ sf::String replies_text_str;
for(size_t reply_index : item->replies) {
BodyItem *reply_item = items[reply_index].get();
- replies_text.setString(">>" + reply_item->post_number);
- replies_text.setPosition(replies_text_pos);
- window.draw(replies_text);
- replies_text_pos.x += replies_text.getLocalBounds().width + 5.0f;
+ replies_text_str += ">>";
+ replies_text_str += reply_item->post_number;
}
+ replies_text.setString(std::move(replies_text_str));
+ window.draw(replies_text);
- item_pos.y += author_text.getCharacterSize() + 2.0f;
+ item_pos.y += item->author_text->getHeight() - 2.0f;
}
//title_text.setString(item->title);
//title_text.setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y));
//window.draw(title_text);
if(!item->get_title().empty()) {
item->title_text->setFillColor(item->title_color);
- item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 4.0f));
+ item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 8.0f));
item->title_text->setMaxWidth(size.x - text_offset_x - image_padding_x * 2.0f);
item->title_text->draw(window);
}
@@ -544,7 +554,7 @@ namespace QuickMedia {
if(!item->get_title().empty()) {
height_offset = item->title_text->getHeight();
}
- item->description_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 4.0f + height_offset));
+ item->description_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 8.0f + height_offset));
item->description_text->setMaxWidth(size.x - text_offset_x - image_padding_x * 2.0f);
item->description_text->draw(window);
}
diff --git a/src/Text.cpp b/src/Text.cpp
index 4aaf1c6..8f58e3d 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -155,6 +155,11 @@ namespace QuickMedia
dirtyCaret = true;
}
}
+
+ float Text::getWidth() const
+ {
+ return boundingBox.width;
+ }
float Text::getHeight() const
{