aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-06-04 19:22:04 +0200
committerdec05eba <dec05eba@protonmail.com>2021-06-04 19:22:04 +0200
commit59e4ce5c35e7e5a73d61e7111e8d4f07d63b7056 (patch)
treea8465d03cc8e6de2999c2fd22bbc83592e7ddd06 /include
parent31efd6ba39036291955babd900c86a897c5cbd86 (diff)
Add grid view
Diffstat (limited to 'include')
-rw-r--r--include/Body.hpp25
-rw-r--r--include/QuickMedia.hpp2
-rw-r--r--include/RoundedRectangle.hpp6
-rw-r--r--include/Tabs.hpp13
4 files changed, 32 insertions, 14 deletions
diff --git a/include/Body.hpp b/include/Body.hpp
index 4846b59..4007bc4 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -198,10 +198,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 = false);
+ bool select_previous_item(bool scroll_page_if_large_item = false, bool ignore_columns = 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 = false);
+ bool select_next_item(bool scroll_page_if_large_item = false, bool ignore_columns = false);
void set_selected_item(int item, bool reset_prev_selected_item = true);
void reset_prev_selected_item();
@@ -259,6 +259,9 @@ namespace QuickMedia {
void apply_search_filter_for_item(BodyItem *body_item);
+ bool can_move_left() const { return selected_column > 0; }
+ bool can_move_right() const { return selected_column + 1 < num_columns; }
+
BodyItems items;
bool draw_thumbnails;
// Set to {0, 0} to disable resizing
@@ -271,13 +274,17 @@ namespace QuickMedia {
bool title_mark_urls = false;
bool swiping_enabled = false;
bool show_drop_shadow = true;
+ bool card_view = false;
std::function<void()> on_top_reached = nullptr;
std::function<void()> on_bottom_reached = nullptr;
private:
void draw_drop_shadow(sf::RenderWindow &window);
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 handle_item_render(const sf::Vector2f pos, const float item_width, const float item_height, int item_index);
+ // Returns the the body total drawn height
+ float draw_list_view(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const int prev_num_visible_items, const Json::Value &content_progress);
+ void draw_card_view(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, sf::Vector2u window_size, float scissor_y);
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);
@@ -312,6 +319,7 @@ namespace QuickMedia {
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.
+ // TODO: Use rounded rectangle instead
sf::RectangleShape image_fallback;
//sf::RectangleShape item_separator;
sf::Sprite image;
@@ -336,6 +344,9 @@ namespace QuickMedia {
bool mouse_left_clicked = false;
bool has_scrolled_with_input = false;
bool click_counts = false;
+ int num_columns = 1;
+ int selected_column = 0;
+ bool card_view_enabled = true;
StuckDirection stuck_direction = StuckDirection::NONE;
sf::Vector2f mouse_click_pos;
sf::Vector2f mouse_release_pos;
@@ -354,10 +365,10 @@ namespace QuickMedia {
RoundedRectangle item_background;
RoundedRectangle reaction_background;
bool render_selected_item_bg = true;
- float item_background_prev_pos_y = 0.0f;
- float item_background_target_pos_y = 0.0f;
- float item_background_prev_height = 0.0f;
- float item_background_target_height = 0.0f;
+ sf::Vector2f item_background_prev_pos;
+ sf::Vector2f item_background_target_pos;
+ sf::Vector2f item_background_prev_size;
+ sf::Vector2f item_background_target_size;
TargetSetState target_y_set = TargetSetState::NOT_SET;
// TODO: Instead of using this, add functions for modifying |items| and apply the filter on those new items
DirtyState items_dirty = DirtyState::FALSE;
diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp
index 09b0806..903e815 100644
--- a/include/QuickMedia.hpp
+++ b/include/QuickMedia.hpp
@@ -79,7 +79,7 @@ namespace QuickMedia {
~Program();
int run(int argc, char **argv);
- std::unique_ptr<Body> create_body(bool plain_text_list = false);
+ std::unique_ptr<Body> create_body(bool plain_text_list = false, bool prefer_card_view = false);
std::unique_ptr<SearchBar> create_search_bar(const std::string &placeholder, int search_delay);
bool load_manga_content_storage(const char *service_name, const std::string &manga_title, const std::string &manga_id);
diff --git a/include/RoundedRectangle.hpp b/include/RoundedRectangle.hpp
index b9d0754..2106634 100644
--- a/include/RoundedRectangle.hpp
+++ b/include/RoundedRectangle.hpp
@@ -17,7 +17,7 @@ namespace QuickMedia {
void set_color(sf::Color color);
sf::Vector2f get_position() const;
sf::Vector2f get_size() const;
- void set_band(float y, float height);
+ void set_band(sf::Vector2f pos, sf::Vector2f size);
void set_band_color(sf::Color color);
void draw(sf::RenderTarget &target);
private:
@@ -26,8 +26,8 @@ namespace QuickMedia {
sf::Vector2f size;
sf::Vertex vertices[4];
sf::Shader *rounded_rectangle_shader;
- float band_y;
- float band_height;
+ sf::Vector2f band_pos;
+ sf::Vector2f band_size;
sf::Color band_color;
};
} \ No newline at end of file
diff --git a/include/Tabs.hpp b/include/Tabs.hpp
index ec5ab96..f7c3054 100644
--- a/include/Tabs.hpp
+++ b/include/Tabs.hpp
@@ -13,6 +13,8 @@ namespace sf {
}
namespace QuickMedia {
+ class Body;
+
class Tabs {
public:
Tabs(sf::Shader *rounded_rectangle_shader, sf::Color shade_color = sf::Color(33, 37, 44));
@@ -21,7 +23,7 @@ namespace QuickMedia {
static float get_shade_height();
// Returns the id (index) of the tab. The ids start from 0
- int add_tab(const std::string &title);
+ int add_tab(const std::string &title, Body *body);
void on_event(sf::Event &event);
void draw(sf::RenderWindow &window, sf::Vector2f pos, float width);
@@ -32,10 +34,15 @@ namespace QuickMedia {
std::function<void(int)> on_change_tab = nullptr;
private:
+ void move_selected_tab(int new_tab);
float tab_index_to_x_offset(int index);
private:
- std::vector<sf::Text> tab_texts;
- std::vector<std::string> tab_labels_utf8;
+ struct Tab {
+ sf::Text text;
+ std::string label_utf8; // TODO: Remove
+ Body *body;
+ };
+ std::vector<Tab> tabs;
RoundedRectangle background;
sf::RectangleShape shade;
int selected_tab = 0;