aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-11-23 20:41:40 +0100
committerdec05eba <dec05eba@protonmail.com>2022-11-23 22:25:02 +0100
commit0c4fd4700d6ee31f6b848d49a6aa7ebfa4a806fa (patch)
tree351e800914a053ab196d972a36e09911227e9f50
parent1de2ff02bb746607727900180b6f32ded0cd7856 (diff)
Re-add item drawing height diff shifting to fix bumping in item drawing
Add newline before codeblock in 4chan if previous line is not a newline.
-rw-r--r--TODO2
-rw-r--r--include/Body.hpp2
-rw-r--r--src/Body.cpp119
-rw-r--r--src/QuickMedia.cpp5
-rw-r--r--src/plugins/Fourchan.cpp5
5 files changed, 63 insertions, 70 deletions
diff --git a/TODO b/TODO
index d91e19f..1fba57f 100644
--- a/TODO
+++ b/TODO
@@ -247,4 +247,4 @@ Atomic file operations should use a random generated name instead of .tmp, becau
TODO: https://github.com/matrix-org/synapse/issues/14444.
Use matrix /sync "since" param. Its beneficial even to quickmedia because synapse is written in such a way that using "since" is faster.
/encrypt should support formatted text like greentext, custom emoji, mentions etc.
-allow navigating to cross-post/dead thread with ctrl+i, fallback to 4chan archive if thread is dead, allow navigating to thread post in the same thread as well using archive to bring the post back alive. \ No newline at end of file
+allow navigating to cross-post/dead thread with ctrl+i, fallback to 4chan archive if thread is dead, allow navigating to thread post in the same thread as well using archive to bring the post back alive, revive deleted images using archive. \ No newline at end of file
diff --git a/include/Body.hpp b/include/Body.hpp
index ced5f4e..77dac54 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -166,6 +166,8 @@ namespace QuickMedia {
void update_dirty_state(BodyItem *body_item, float width);
void clear_body_item_cache(BodyItem *body_item);
mgl::vec2i get_item_thumbnail_size(BodyItem *item) const;
+ // Returns the height of the items
+ float process_reactions(mgl::Window *window, BodyItem *item, float max_width, float x, float y, float padding_y, float text_offset_y, bool draw);
// Returns -1 if not found
int get_previous_visible_item(int start_index);
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;
}