aboutsummaryrefslogtreecommitdiff
path: root/include/Body.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-20 15:06:37 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-20 15:06:37 +0200
commit795cc3d873df13bfe2abaa56b17ea247bc892c20 (patch)
tree45f5918e7778fe5793f8636747f2834ba01ef141 /include/Body.hpp
parentf52d48906f7fad95353da3cc7ddfe75b12106e4e (diff)
Word-wrap body text
Diffstat (limited to 'include/Body.hpp')
-rw-r--r--include/Body.hpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/include/Body.hpp b/include/Body.hpp
index 4c7044d..86b6984 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "Text.hpp"
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/Texture.hpp>
@@ -12,18 +13,29 @@ namespace QuickMedia {
class BodyItem {
public:
- BodyItem(std::string _title): visible(true), num_lines(1) {
+ BodyItem(std::string _title): visible(true), dirty(true) {
set_title(std::move(_title));
}
+ BodyItem(const BodyItem &other) {
+ title = other.title;
+ url = other.url;
+ thumbnail_url = other.thumbnail_url;
+ attached_content_url = other.attached_content_url;
+ author = other.author;
+ visible = other.visible;
+ dirty = other.dirty;
+ if(other.title_text)
+ title_text = std::make_unique<Text>(*other.title_text);
+ else
+ title_text = nullptr;
+ replies = other.replies;
+ post_number = other.post_number;
+ }
+
void set_title(std::string new_title) {
title = std::move(new_title);
- // TODO: Optimize this
- num_lines = 1;
- for(char c : title) {
- if(c == '\n')
- ++num_lines;
- }
+ dirty = true;
}
std::string title;
@@ -32,9 +44,10 @@ namespace QuickMedia {
std::string attached_content_url;
std::string author;
bool visible;
+ bool dirty;
+ std::unique_ptr<Text> title_text;
// Used by image boards for example. The elements are indices to other body items
std::vector<size_t> replies;
- int num_lines;
std::string post_number;
};