aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp83
1 files changed, 51 insertions, 32 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 6bf816d..c79f836 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -100,7 +100,6 @@ namespace QuickMedia {
prev_selected_item(0),
loading_icon(&loading_icon_texture),
progress_text("", *FontLoader::get_font(FontLoader::FontType::LATIN, get_config().body.progress_font_size * get_config().scale * get_config().font_scale)),
- replies_text("", *FontLoader::get_font(FontLoader::FontType::LATIN, get_config().body.replies_font_size * get_config().scale * get_config().font_scale)),
embedded_item_load_text("", *FontLoader::get_font(FontLoader::FontType::LATIN, body_spacing[body_theme].embedded_item_font_size)),
num_visible_items(0),
top_cut_off(false),
@@ -111,7 +110,6 @@ namespace QuickMedia {
rounded_rectangle_mask_shader(rounded_rectangle_mask_shader)
{
progress_text.set_color(get_theme().text_color);
- replies_text.set_color(get_theme().replies_text_color);
thumbnail_max_size.x = 600;
thumbnail_max_size.y = 337;
mgl::vec2f loading_icon_size(loading_icon.get_texture()->get_size().x, loading_icon.get_texture()->get_size().y);
@@ -925,6 +923,20 @@ namespace QuickMedia {
body_item->timestamp_text->set_color(get_theme().timestamp_text_color);
}
}
+
+ if((body_item->dirty_reactions && !body_item->reactions.empty()) || (body_size_changed && !body_item->reactions.empty() && body_item->reactions.front().text)) {
+ body_item->dirty_reactions = false;
+ for(auto &reaction : body_item->reactions) {
+ if(reaction.text) {
+ reaction.text->setString(reaction.text_str);
+ reaction.text->setMaxWidth(width);
+ } else {
+ reaction.text = std::make_unique<Text>(reaction.text_str, false, floor(get_config().body.reaction_font_size * get_config().scale * get_config().font_scale), width);
+ }
+ reaction.text->set_color(reaction.text_color);
+ reaction.size = { 0.0f, 0.0f };
+ }
+ }
}
void Body::clear_body_item_cache(BodyItem *body_item) {
@@ -944,6 +956,12 @@ namespace QuickMedia {
body_item->timestamp_text.reset();
body_item->dirty_timestamp = true;
}
+ if(!body_item->reactions.empty()) {
+ for(auto &reaction : body_item->reactions) {
+ reaction.text.reset();
+ }
+ body_item->dirty_reactions = true;
+ }
body_item->keep_alive_frames = 0;
}
@@ -1429,20 +1447,6 @@ namespace QuickMedia {
if(item->author_text && !merge_with_previous) {
item->author_text->set_position(vec2f_floor(item_pos.x + text_offset_x, item_pos.y + padding_y - text_offset_y));
item->author_text->draw(window);
-
- mgl::vec2f replies_text_pos = item->author_text->get_position();
- replies_text_pos.x += item->author_text->getWidth() + 5.0f;
- replies_text.set_position(replies_text_pos);
-
- std::string replies_text_str;
- for(size_t reply_index : item->replies) {
- BodyItem *reply_item = items[reply_index].get();
- replies_text_str += " >>";
- replies_text_str += reply_item->post_number;
- }
- replies_text.set_string(std::move(replies_text_str));
- window.draw(replies_text);
-
item_pos.y += item->author_text->getHeight() - 2.0f + std::floor(3.0f * get_config().scale);
}
@@ -1483,21 +1487,27 @@ namespace QuickMedia {
float reaction_offset_x = 0.0f;
item_pos.y += body_spacing[body_theme].reaction_padding_y;
float reaction_max_height = 0.0f;
- // TODO: Fix first row wrap-around
+ int row = 0;
for(int i = 0; i < (int)item->reactions.size(); ++i) {
auto &reaction = item->reactions[i];
reaction.text->updateGeometry();
- reaction_max_height = std::max(reaction_max_height, reaction.text->getHeight());
- reaction.text->set_position(vec2f_floor(item_pos.x + text_offset_x + reaction_offset_x + body_spacing[body_theme].reaction_background_padding_x, item_pos.y + padding_y - 4.0f + body_spacing[body_theme].reaction_background_padding_y));
- reaction_background.set_position(vec2f_floor(item_pos.x + text_offset_x + reaction_offset_x, item_pos.y + padding_y));
- reaction_background.set_size(mgl::vec2f(reaction.text->getWidth() + body_spacing[body_theme].reaction_background_padding_x * 2.0f, reaction.text->getHeight() + body_spacing[body_theme].reaction_background_padding_y * 2.0f));
+ reaction.size = { reaction.text->getWidth(), reaction.text->getHeight() };
+ reaction_max_height = std::max(reaction_max_height, reaction.size.y);
+ reaction_background.set_size(mgl::vec2f(reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f, reaction.size.y + body_spacing[body_theme].reaction_background_padding_y * 2.0f));
reaction_background.draw(window);
- reaction_offset_x += reaction.text->getWidth() + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x;
+
+ const float new_reaction_offset_x = reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x;
reaction.text->draw(window);
- if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + body_spacing[body_theme].reaction_background_padding_x * 2.0f > size.x && i < (int)item->reactions.size() - 1) {
+ if(text_offset_x + new_reaction_offset_x > size.x && row != 0) {
reaction_offset_x = 0.0f;
- item_pos.y += reaction.text->getHeight() + body_spacing[body_theme].reaction_padding_y + text_offset_y;
- reaction_max_height = reaction.text->getHeight();
+ item_pos.y += reaction_max_height + body_spacing[body_theme].reaction_padding_y + text_offset_y;
+ reaction_max_height = reaction.size.y;
+ row = 0;
+ } else {
+ reaction_background.set_position(vec2f_floor(item_pos.x + text_offset_x + reaction_offset_x, item_pos.y + padding_y));
+ reaction.text->set_position(vec2f_floor(item_pos.x + text_offset_x + reaction_offset_x + body_spacing[body_theme].reaction_background_padding_x, item_pos.y + padding_y - 4.0f + body_spacing[body_theme].reaction_background_padding_y));
+ reaction_offset_x = new_reaction_offset_x;
+ ++row;
}
}
item_pos.y += reaction_max_height + body_spacing[body_theme].reaction_padding_y;
@@ -1705,16 +1715,25 @@ namespace QuickMedia {
float reaction_offset_x = 0.0f;
item_height += body_spacing[body_theme].reaction_padding_y;
float reaction_max_height = 0.0f;
+ int row = 0;
for(int i = 0; i < (int)item->reactions.size(); ++i) {
auto &reaction = item->reactions[i];
- reaction.text->setMaxWidth(text_max_width);
- reaction.text->updateGeometry();
- reaction_max_height = std::max(reaction_max_height, reaction.text->getHeight());
- reaction_offset_x += reaction.text->getWidth() + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x;
- if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + body_spacing[body_theme].reaction_background_padding_x * 2.0f > width && i < (int)item->reactions.size() - 1) {
+ if(reaction.size.x < 0.001f && reaction.text) {
+ reaction.text->setMaxWidth(text_max_width);
+ reaction.text->updateGeometry();
+ reaction.size = { reaction.text->getWidth(), reaction.text->getHeight() };
+ }
+ reaction_max_height = std::max(reaction_max_height, reaction.size.y);
+
+ const float new_reaction_offset_x = reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x;
+ if(text_offset_x + new_reaction_offset_x > width && row != 0) {
reaction_offset_x = 0.0f;
- item_height += reaction.text->getHeight() + body_spacing[body_theme].reaction_padding_y + std::floor(6.0f * get_config().scale);
- reaction_max_height = reaction.text->getHeight();
+ item_height += reaction_max_height + body_spacing[body_theme].reaction_padding_y + std::floor(6.0f * get_config().scale);
+ reaction_max_height = reaction.size.y;
+ row = 0;
+ } else {
+ reaction_offset_x = new_reaction_offset_x;
+ ++row;
}
}
item_height += reaction_max_height + body_spacing[body_theme].reaction_padding_y;