From 795cc3d873df13bfe2abaa56b17ea247bc892c20 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 20 Jul 2020 15:06:37 +0200 Subject: Word-wrap body text --- include/Body.hpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'include/Body.hpp') 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 #include #include @@ -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(*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 title_text; // Used by image boards for example. The elements are indices to other body items std::vector replies; - int num_lines; std::string post_number; }; -- cgit v1.2.3