aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp119
-rw-r--r--src/QuickMedia.cpp5
-rw-r--r--src/plugins/Fourchan.cpp5
3 files changed, 60 insertions, 69 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index fcf932c..cc0edfa 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -1184,20 +1184,18 @@ namespace QuickMedia {
item->prev_height = item->height;
if(attach_side == AttachSide::TOP) {
- // TODO: Remove
- // if(index < selected_item) {
- // page_scroll -= height_diff;
- // pos.y -= height_diff;
- // }
+ if(index < selected_item) {
+ page_scroll -= height_diff;
+ pos.y -= height_diff;
+ }
prev_body_item = item.get();
index = get_next_visible_item(index);
} else {
- // TODO: Remove
- // if(index > selected_item) {
- // page_scroll += height_diff;
- // pos.y += height_diff;
- // }
+ if(index > selected_item) {
+ page_scroll += height_diff;
+ pos.y += height_diff;
+ }
index = prev_index;
}
@@ -1510,40 +1508,7 @@ namespace QuickMedia {
}
if(!item->reactions.empty() && include_embedded_item) {
- float reaction_offset_x = 0.0f;
- item_pos.y += body_spacing[body_theme].reaction_padding_y;
- float reaction_max_height = 0.0f;
- for(int i = 0; i < (int)item->reactions.size(); ++i) {
- auto &reaction = item->reactions[i];
- if(reaction.text) {
- 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));
-
- const float new_reaction_offset_x = reaction_offset_x + reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f;
- if(i != 0 && (new_reaction_offset_x > text_max_width || reaction.num_lines > 1)) {
- reaction_offset_x = 0.0f;
- item_pos.y += reaction_max_height_prev + body_spacing[body_theme].reaction_padding_y + text_offset_y;
- reaction_max_height = reaction.size.y;
- 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_offset_x = new_reaction_offset_x + body_spacing[body_theme].reaction_spacing_x;
- }
-
- if(reaction.text) {
- reaction.text->set_position(reaction_background.get_position() + mgl::vec2f(body_spacing[body_theme].reaction_background_padding_x, -6.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;
+ item_pos.y += process_reactions(&window, item.get(), text_max_width, item_pos.x + text_offset_x, item_pos.y, padding_y, text_offset_y, true);
}
if(item_index == selected_item && item->timestamp_text) {
@@ -1681,6 +1646,47 @@ namespace QuickMedia {
}
}
+ float Body::process_reactions(mgl::Window *window, BodyItem *item, float max_width, float x, float y, float padding_y, float text_offset_y, bool draw) {
+ float height = 0.0f;
+ float reaction_offset_x = 0.0f;
+ height += body_spacing[body_theme].reaction_padding_y;
+ float reaction_max_height = 0.0f;
+ for(int i = 0; i < (int)item->reactions.size(); ++i) {
+ auto &reaction = item->reactions[i];
+ if(reaction.size.x < 0.001f && reaction.text && !draw) {
+ reaction.text->setMaxWidth(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);
+ 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));
+
+ const float new_reaction_offset_x = reaction_offset_x + reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f;
+ if(i != 0 && (new_reaction_offset_x > max_width || reaction.num_lines > 1)) {
+ reaction_offset_x = 0.0f;
+ height += reaction_max_height_prev + body_spacing[body_theme].reaction_padding_y + text_offset_y;
+ reaction_max_height = reaction.size.y;
+ reaction_background.set_position(vec2f_floor(x + reaction_offset_x, y + height + 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(x + reaction_offset_x, y + height + padding_y));
+ reaction_offset_x = new_reaction_offset_x + body_spacing[body_theme].reaction_spacing_x;
+ }
+
+ if(reaction.text) {
+ reaction.text->set_position(reaction_background.get_position() + mgl::vec2f(body_spacing[body_theme].reaction_background_padding_x, -6.0f + body_spacing[body_theme].reaction_background_padding_y));
+ }
+
+ if(draw && reaction.text) {
+ reaction_background.draw(*window);
+ reaction.text->draw(*window);
+ }
+ }
+ return height + reaction_max_height + body_spacing[body_theme].reaction_padding_y;
+ }
+
float Body::get_item_height(BodyItem *item, float width, bool load_texture, bool include_embedded_item, bool merge_with_previous, int item_index) {
const bool rendering_card_view = card_view && card_view_enabled;
mgl::vec2i content_size = get_item_thumbnail_size(item);
@@ -1747,30 +1753,7 @@ namespace QuickMedia {
// TODO: Only do this if reactions dirty?
if(!item->reactions.empty() && include_embedded_item) {
- float reaction_offset_x = 0.0f;
- item_height += body_spacing[body_theme].reaction_padding_y;
- float reaction_max_height = 0.0f;
- 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_offset_x + reaction.size.x + body_spacing[body_theme].reaction_background_padding_x * 2.0f;
- if(i != 0 && (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;
- 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 + body_spacing[body_theme].reaction_spacing_x;
- }
- }
- item_height += reaction_max_height + body_spacing[body_theme].reaction_padding_y;
+ item_height += process_reactions(nullptr, item, text_max_width, 0.0f, 0.0f, 0.0f, std::floor(6.0f * get_config().scale), false);
has_loaded_text = true;
}
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index ca69248..9e8211a 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -4548,8 +4548,11 @@ namespace QuickMedia {
return image_board_post_data->post_id == navigate_to_post_id;
});
- if(found_body_item_index != -1)
+ if(found_body_item_index == -1) {
+ show_notification("QuickMedia", "Could not find the post " + thread_page->post_id + " in the thread. It either doesn't exist or it has been deleted", Urgency::NORMAL);
+ } else {
thread_body->set_selected_item(found_body_item_index);
+ }
}
// TODO: Instead of using stage here, use different pages for each stage
diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp
index 1ce97c4..aa941d5 100644
--- a/src/plugins/Fourchan.cpp
+++ b/src/plugins/Fourchan.cpp
@@ -52,6 +52,9 @@ namespace QuickMedia {
return false;
index = thread_id_end + 2;
+ if(index >= url.size())
+ return true;
+
post_id = url.substr(index);
return true;
}
@@ -328,6 +331,8 @@ namespace QuickMedia {
break;
case CommentPiece::Type::CODEBLOCK:
// TODO: Use a different colored background
+ if(!comment_text.empty() && comment_text.back() != '\n')
+ comment_text += '\n';
comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(255, 255, 255, 255), FORMATTED_TEXT_FLAG_CODE);
break;
}