diff options
-rw-r--r-- | src/Body.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index 0b4ec0f..9cb0c31 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -834,21 +834,22 @@ namespace QuickMedia { float reaction_offset_x = 0.0f; item_pos.y += reaction_padding_y; float reaction_max_height = 0.0f; - for(auto &reaction : item->reactions) { + for(int i = 0; i < item->reactions.size(); ++i) { + auto &reaction = item->reactions[i]; reaction.text->setMaxWidth(size.x - text_offset_x - image_padding_x); reaction.text->updateGeometry(); reaction_max_height = std::max(reaction_max_height, reaction.text->getHeight()); - if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + reaction_background_padding_x * 2.0f > size.x) { - reaction_offset_x = 0.0f; - item_pos.y += reaction.text->getHeight() + reaction_padding_y + 6.0f; - reaction_max_height = reaction.text->getHeight(); - } reaction.text->setPosition(std::floor(item_pos.x + text_offset_x + reaction_offset_x + reaction_background_padding_x), std::floor(item_pos.y + padding_y - 4.0f + reaction_background_padding_y)); reaction_background.setPosition(std::floor(item_pos.x + text_offset_x + reaction_offset_x), std::floor(item_pos.y + padding_y)); reaction_background.setSize(sf::Vector2f(reaction.text->getWidth() + reaction_background_padding_x * 2.0f, reaction.text->getHeight() + reaction_background_padding_y * 2.0f)); window.draw(reaction_background); reaction_offset_x += reaction.text->getWidth() + reaction_background_padding_x * 2.0f + reaction_spacing_x; reaction.text->draw(window); + if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + reaction_background_padding_x * 2.0f > size.x && i < (int)item->reactions.size() - 1) { + reaction_offset_x = 0.0f; + item_pos.y += reaction.text->getHeight() + reaction_padding_y + 6.0f; + reaction_max_height = reaction.text->getHeight(); + } } item_pos.y += reaction_max_height + reaction_padding_y; } @@ -946,16 +947,17 @@ namespace QuickMedia { float reaction_offset_x = 0.0f; item_height += reaction_padding_y; float reaction_max_height = 0.0f; - for(auto &reaction : item->reactions) { + for(int i = 0; i < item->reactions.size(); ++i) { + auto &reaction = item->reactions[i]; reaction.text->setMaxWidth(width - text_offset_x - image_padding_x); reaction.text->updateGeometry(); reaction_max_height = std::max(reaction_max_height, reaction.text->getHeight()); - if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + reaction_background_padding_x * 2.0f > width) { + reaction_offset_x += reaction.text->getWidth() + reaction_background_padding_x * 2.0f + reaction_spacing_x; + if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + reaction_background_padding_x * 2.0f > width && i < (int)item->reactions.size() - 1) { reaction_offset_x = 0.0f; item_height += reaction.text->getHeight() + reaction_padding_y + 6.0f; reaction_max_height = reaction.text->getHeight(); } - reaction_offset_x += reaction.text->getWidth() + reaction_background_padding_x * 2.0f + reaction_spacing_x; } item_height += reaction_max_height + reaction_padding_y; } |