aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index c79f836..2747a22 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -935,6 +935,7 @@ namespace QuickMedia {
}
reaction.text->set_color(reaction.text_color);
reaction.size = { 0.0f, 0.0f };
+ reaction.num_lines = 1;
}
}
}
@@ -1441,6 +1442,7 @@ namespace QuickMedia {
text_offset_x += body_spacing[body_theme].image_padding_x + item->loaded_image_size.x;
}
+ const float text_max_width = size.x - text_offset_x;
const float text_offset_y = std::floor(6.0f * get_config().scale * get_config().font_scale);
const float timestamp_text_y = std::floor(item_pos.y + padding_y - text_offset_y - std::floor(4.0f * get_config().scale * get_config().font_scale));
@@ -1487,28 +1489,31 @@ namespace QuickMedia {
float reaction_offset_x = 0.0f;
item_pos.y += 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->updateGeometry();
reaction.size = { reaction.text->getWidth(), reaction.text->getHeight() };
+ reaction.num_lines = reaction.text->getNumLines();
+ const float reaction_max_height_prev = reaction_max_height;
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);
- 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 + new_reaction_offset_x > size.x && row != 0) {
+ const float new_reaction_offset_x = reaction_offset_x + reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x;
+ if(i != 0 && (text_offset_x + new_reaction_offset_x > text_max_width || reaction.num_lines > 1)) {
reaction_offset_x = 0.0f;
- item_pos.y += reaction_max_height + body_spacing[body_theme].reaction_padding_y + text_offset_y;
+ item_pos.y += reaction_max_height_prev + body_spacing[body_theme].reaction_padding_y + text_offset_y;
reaction_max_height = reaction.size.y;
- row = 0;
+ reaction_background.set_position(vec2f_floor(item_pos.x + text_offset_x + reaction_offset_x, item_pos.y + padding_y));
+ reaction_offset_x = reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x;
} 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;
}
+
+ reaction.text->set_position(reaction_background.get_position() + mgl::vec2f(body_spacing[body_theme].reaction_background_padding_x, - 4.0f + body_spacing[body_theme].reaction_background_padding_y));
+
+ reaction_background.draw(window);
+ reaction.text->draw(window);
}
item_pos.y += reaction_max_height + body_spacing[body_theme].reaction_padding_y;
}
@@ -1715,25 +1720,24 @@ 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];
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.num_lines = reaction.text->getNumLines();
}
+ const float reaction_max_height_prev = reaction_max_height;
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_max_height + body_spacing[body_theme].reaction_padding_y + std::floor(6.0f * get_config().scale);
+ const float new_reaction_offset_x = reaction_offset_x + reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x;
+ if(i != 0 && (text_offset_x + new_reaction_offset_x > text_max_width || reaction.num_lines > 1)) {
+ item_height += reaction_max_height_prev + body_spacing[body_theme].reaction_padding_y + std::floor(6.0f * get_config().scale);
reaction_max_height = reaction.size.y;
- row = 0;
+ reaction_offset_x = reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x;
} else {
reaction_offset_x = new_reaction_offset_x;
- ++row;
}
}
item_height += reaction_max_height + body_spacing[body_theme].reaction_padding_y;