aboutsummaryrefslogtreecommitdiff
path: root/include/Body.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-28 15:48:43 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-28 16:05:00 +0200
commit7b48ab891023d76de6b13b56a8d5e205f62bc37d (patch)
tree5863e129fd26bc2033d63b4f1ead25e25b83a4c2 /include/Body.hpp
parent2421bf3a24cd64767da1dde387c9caa27320dfc8 (diff)
Improve body navigation
Diffstat (limited to 'include/Body.hpp')
-rw-r--r--include/Body.hpp55
1 files changed, 28 insertions, 27 deletions
diff --git a/include/Body.hpp b/include/Body.hpp
index 6977922..a74c320 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -144,7 +144,9 @@ namespace QuickMedia {
std::vector<size_t> replies;
std::string post_number;
void *userdata; // Not managed, should be deallocated by whoever sets this
- double last_drawn_time;
+ float prev_last_loaded_height = 0.0f;
+ float last_loaded_height = 0.0f;
+ float current_loaded_height = 0.0f;
FetchStatus embedded_item_status = FetchStatus::NONE;
// Important! Should refer to a new BodyItem, not one that already exists in the body.
// TODO: Allow referring to an existing body item. This doesn't work properly at the moment because max width of text and line count calculation getting messed up
@@ -154,6 +156,9 @@ namespace QuickMedia {
sf::Vector2i thumbnail_size;
std::vector<Reaction> reactions; // TODO: Move to a different body item type
std::shared_ptr<BodyItemExtra> extra; // TODO: Remove
+
+ // Internal use only
+ int keep_alive_frames = 0;
private:
// TODO: Clean up these strings when set in text, and get_title for example should return |title_text.getString()|
// TODO: Use sf::String instead, removes the need to convert to utf32 every time the text is dirty (for example when resizing window)
@@ -187,10 +192,10 @@ namespace QuickMedia {
bool select_next_page();
// Select previous item, ignoring invisible items. Returns true if the item was changed or if the item scrolled. This can be used to check if the top was hit when wrap_around is set to false
- bool select_previous_item(bool scroll_page_if_large_item = true);
+ bool select_previous_item(bool scroll_page_if_large_item = false);
// Select next item, ignoring invisible items. Returns true if the item was changed or if the item scrolled. This can be used to check if the bottom was hit when wrap_around is set to false
- bool select_next_item(bool scroll_page_if_large_item = true);
+ bool select_next_item(bool scroll_page_if_large_item = false);
void set_selected_item(int item, bool reset_prev_selected_item = true);
void reset_prev_selected_item();
@@ -198,11 +203,13 @@ namespace QuickMedia {
int get_index_by_body_item(BodyItem *body_item);
void select_first_item();
- void select_last_item(bool reset_prev_select = false);
+ void select_last_item();
void clear_items();
void prepend_items_reverse(BodyItems new_items);
void append_items(BodyItems new_items);
- void insert_item_by_timestamp(std::shared_ptr<BodyItem> body_item);
+ // Returns the inserted position
+ size_t insert_item_by_timestamp(std::shared_ptr<BodyItem> body_item);
+ // Note: also moves the selected item forward the number of items inserted before/after it (depending on attach_side)
void insert_items_by_timestamps(BodyItems new_items);
void clear_cache();
void clear_text_cache();
@@ -210,10 +217,6 @@ namespace QuickMedia {
BodyItem* get_selected() const;
std::shared_ptr<BodyItem> get_selected_shared();
- // Returns null if no visible items. This is the item we can see the end of
- BodyItem* get_last_fully_visible_item();
- BodyItem* get_last_visible_item();
-
void clamp_selection();
// Returns true if the event was handled
@@ -231,7 +234,7 @@ namespace QuickMedia {
float get_spacing_y() const;
// TODO: Highlight the part of the text that matches the search.
- void filter_search_fuzzy(const std::string &text, bool select_first_if_empty = true);
+ void filter_search_fuzzy(const std::string &text);
bool no_items_visible() const;
@@ -241,10 +244,9 @@ namespace QuickMedia {
void set_page_scroll(float scroll);
float get_page_scroll() const { return page_scroll; }
// This is the item we can see the start of
- bool is_first_item_fully_visible() const { return first_item_fully_visible; }
+ bool is_top_cut_off() const { return top_cut_off; }
// This is the item we can see the end of
- bool is_last_item_fully_visible() const { return last_item_fully_visible; }
- bool is_body_full_with_items() const { return items_cut_off; }
+ bool is_bottom_cut_off() const { return bottom_cut_off; }
int get_num_visible_items() const { return num_visible_items; };
// Call this once after adding new items
@@ -257,7 +259,6 @@ namespace QuickMedia {
sf::Text embedded_item_load_text;
BodyItems items;
bool draw_thumbnails;
- bool wrap_around;
// Set to {0, 0} to disable resizing
sf::Vector2i thumbnail_max_size;
sf::Color line_separator_color;
@@ -272,6 +273,7 @@ namespace QuickMedia {
std::function<void()> on_bottom_reached = nullptr;
private:
void filter_search_fuzzy_item(const std::string &text, BodyItem *body_item);
+ void handle_item_render(BodyItem *item, const sf::Vector2f pos, const sf::Vector2f size, const float item_height, int item_index);
void draw_item(sf::RenderWindow &window, BodyItem *item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress, bool include_embedded_item = true, bool merge_with_previous = false);
void update_dirty_state(BodyItem *body_item, float width);
void clear_body_item_cache(BodyItem *body_item);
@@ -293,23 +295,25 @@ namespace QuickMedia {
APPLIED
};
+ enum class StuckDirection {
+ TOP,
+ NONE,
+ BOTTOM
+ };
+
Program *program;
int selected_item;
int prev_selected_item;
- double page_scroll;
- double prev_extra_scroll = 0.0;
- double extra_scroll_current = 0.0;
- double extra_scroll_target = 0.0;
+ double page_scroll = 0.0;
+ float selected_scrolled = 0.0f;
// TODO: Use a loading gif or something similar instead, to properly indicate the image is loading. Which could also have text that says "failed to load image" when image loading failed.
sf::RectangleShape image_fallback;
//sf::RectangleShape item_separator;
sf::Sprite image;
sf::Sprite loading_icon;
int num_visible_items;
- bool first_item_fully_visible;
- bool last_item_fully_visible;
- int first_fully_visible_item;
- int last_fully_visible_item;
+ bool top_cut_off;
+ bool bottom_cut_off;
int first_visible_item = -1;
int last_visible_item = -1;
sf::Clock draw_timer;
@@ -317,15 +321,12 @@ namespace QuickMedia {
double elapsed_time_sec = 0.0;
bool selected_line_top_visible = true;
bool selected_line_bottom_visible = true;
- bool items_cut_off = false;
- float offset_to_top = 0.0f;
- float offset_to_bottom = 0.0f;
- int clamp_selected_item_to_body_count = 1;
- int shit_hack_body_size_change = 0;
+ bool selected_item_fits_in_body = true;
bool mouse_left_pressed = false;
bool mouse_left_clicked = false;
bool has_scrolled_with_input = false;
bool click_counts = false;
+ StuckDirection stuck_direction = StuckDirection::NONE;
sf::Vector2f mouse_click_pos;
sf::Vector2f mouse_release_pos;
double mouse_press_pixels_moved_abs;