diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-04-19 16:13:55 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-04-19 16:13:55 +0200 |
commit | 5465c09cd108e37720dbad139de98bdcf5dfe8bf (patch) | |
tree | 47db7d4a488bca6711fe9a8cbc47f53a74f3fc67 /include | |
parent | 7f0bdeddb79c308ab082a124441f1d69d665dbfc (diff) |
Move tab code to separate class, fix upload time missing for certain manga plugins, fix touch room click messed up
Diffstat (limited to 'include')
-rw-r--r-- | include/Body.hpp | 1 | ||||
-rw-r--r-- | include/QuickMedia.hpp | 5 | ||||
-rw-r--r-- | include/Tabs.hpp | 47 |
3 files changed, 50 insertions, 3 deletions
diff --git a/include/Body.hpp b/include/Body.hpp index 22d9ff9..90e75c8 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -310,6 +310,7 @@ namespace QuickMedia { float selected_item_height = 0.0f; float selected_scrolled = 0.0f; bool loaded_textures_changed = false; + std::shared_ptr<BodyItem> clicked_body_item = nullptr; //float scroll_y = 0.0f; }; }
\ No newline at end of file diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 9729c4b..bd3b316 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -29,6 +29,7 @@ namespace QuickMedia { class RoomData; class MatrixChatPage; class VideoPage; + class Tabs; enum class ImageViewMode { SINGLE, @@ -103,7 +104,7 @@ namespace QuickMedia { void event_idle_handler(const sf::Event &event); void idle_active_handler(); void update_idle_state(); - void page_loop_render(sf::RenderWindow &window, std::vector<Tab> &tabs, int selected_tab, TabAssociatedData &tab_associated_data, const Json::Value *json_chapters); + void page_loop_render(sf::RenderWindow &window, std::vector<Tab> &tabs, int selected_tab, TabAssociatedData &tab_associated_data, const Json::Value *json_chapters, Tabs &ui_tabs); using PageLoopSubmitHandler = std::function<void(const std::vector<Tab> &new_tabs)>; void page_loop(std::vector<Tab> &tabs, int start_tab_index = 0, PageLoopSubmitHandler after_submit_handler = nullptr); void video_content_page(Page *parent_page, VideoPage *video_page, std::string video_title, bool download_if_streaming_fails, BodyItems &next_play_items, int play_index, int *parent_body_page = nullptr, const std::string &parent_page_search = ""); @@ -181,8 +182,6 @@ namespace QuickMedia { bool fit_image_to_window = false; RoomData *current_chat_room = nullptr; bool go_to_previous_page = false; - sf::RoundedRectangleShape tab_background; - sf::RectangleShape tab_shade; sf::Text tab_text; sf::Vertex gradient_points[4]; sf::Vector2f body_pos; diff --git a/include/Tabs.hpp b/include/Tabs.hpp new file mode 100644 index 0000000..d5aa5b6 --- /dev/null +++ b/include/Tabs.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include "../external/RoundedRectangleShape.hpp" +#include <SFML/Graphics/RectangleShape.hpp> +#include <SFML/Graphics/Text.hpp> +#include <vector> +#include <functional> + +namespace sf { + class Event; + class RenderWindow; +} + +namespace QuickMedia { + class Tabs { + public: + Tabs(sf::Color shade_color = sf::Color(33, 37, 44)); + + static float get_height(); + static float get_shade_height(); + + // Returns the id (index) of the tab. The ids start from 0 + int add_tab(const std::string &title); + void on_event(sf::Event &event); + void draw(sf::RenderWindow &window, sf::Vector2f pos, float width); + + void set_text(int index, const std::string &text); + + void set_selected(int index); + int get_selected() const; + + std::function<void(int)> on_change_tab = nullptr; + private: + float tab_index_to_x_offset(int index); + private: + std::vector<sf::Text> tab_texts; + sf::RoundedRectangleShape background; + sf::RectangleShape shade; + int selected_tab = 0; + float scroll = 0.0f; + float width_per_tab = 0.0f; + float tab_background_width = 0.0f; + float container_width = 0.0f; + int tab_offset = 0; + sf::Color shade_color; + }; +}
\ No newline at end of file |