From b8e6949dfb8a88c832e82f8b7e853fe0ed462da0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 24 Aug 2024 14:08:25 +0200 Subject: Remove scrollable page from gsr page, fix crash when navigating back --- include/SafeVector.hpp | 2 +- include/Theme.hpp | 2 +- include/gui/FileChooser.hpp | 11 ++++++++--- include/gui/GsrPage.hpp | 8 ++++---- include/gui/Page.hpp | 4 ++-- include/gui/ScrollablePage.hpp | 4 ++-- 6 files changed, 18 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/SafeVector.hpp b/include/SafeVector.hpp index cea9cb9..916b547 100644 --- a/include/SafeVector.hpp +++ b/include/SafeVector.hpp @@ -21,7 +21,7 @@ public: } // Might not remove the data immediately if inside for_each loop. - // In that case the item is remove at the end of the loop. + // In that case the item is removed at the end of the loop. void remove(PointerType item_to_remove) { if(for_each_depth == 0) remove_item(item_to_remove); diff --git a/include/Theme.hpp b/include/Theme.hpp index 5f228af..7406c67 100644 --- a/include/Theme.hpp +++ b/include/Theme.hpp @@ -19,7 +19,7 @@ namespace gsr { float window_height = 0.0f; mgl::Color tint_color = mgl::Color(118, 185, 0); - mgl::Color scrollable_page_bg_color = mgl::Color(38, 43, 47); + mgl::Color page_bg_color = mgl::Color(38, 43, 47); mgl::Color text_color = mgl::Color(255, 255, 255); mgl::MemoryMappedFile body_font_file; diff --git a/include/gui/FileChooser.hpp b/include/gui/FileChooser.hpp index b8ea23e..309ff56 100644 --- a/include/gui/FileChooser.hpp +++ b/include/gui/FileChooser.hpp @@ -13,7 +13,7 @@ namespace gsr { class FileChooser : public Widget { public: - FileChooser(const char *start_directory, mgl::vec2f content_size); + FileChooser(const char *start_directory, mgl::vec2f size); FileChooser(const FileChooser&) = delete; FileChooser& operator=(const FileChooser&) = delete; @@ -24,11 +24,16 @@ namespace gsr { void set_current_directory(const char *directory); private: - mgl::vec2f content_size; + struct Folder { + mgl::Text text; + time_t last_modified_seconds = 0; + }; + + mgl::vec2f size; mgl::Text current_directory_text; int mouse_over_item = -1; int selected_item = -1; - std::vector folders; + std::vector folders; mgl::Clock double_click_timer; int times_clicked_within_timer = 0; }; diff --git a/include/gui/GsrPage.hpp b/include/gui/GsrPage.hpp index 9f38382..916055a 100644 --- a/include/gui/GsrPage.hpp +++ b/include/gui/GsrPage.hpp @@ -1,7 +1,6 @@ #pragma once #include "Page.hpp" -#include "ScrollablePage.hpp" #include "Button.hpp" #include @@ -19,20 +18,21 @@ namespace gsr { mgl::vec2f get_size() override; mgl::vec2f get_inner_size() override; - void add_widget(std::unique_ptr widget) override; - void set_margins(float top, float bottom, float left, float right); void set_on_back_button_click(std::function on_click_handler); private: void draw_page_label(mgl::Window &window, mgl::vec2f body_pos); + void draw_children(mgl::Window &window, mgl::vec2f position); + float get_border_size() const; float get_horizontal_spacing() const; + mgl::vec2f get_content_position(); + mgl::vec2f get_content_position_with_margin(); private: float margin_top_scale = 0.0f; float margin_bottom_scale = 0.0f; float margin_left_scale = 0.0f; float margin_right_scale = 0.0f; - ScrollablePage scrollable_body; Button back_button; mgl::Text label_text; }; diff --git a/include/gui/Page.hpp b/include/gui/Page.hpp index a8fa515..0d8536a 100644 --- a/include/gui/Page.hpp +++ b/include/gui/Page.hpp @@ -1,7 +1,7 @@ #pragma once #include "Widget.hpp" -#include +#include "../SafeVector.hpp" #include namespace gsr { @@ -19,6 +19,6 @@ namespace gsr { virtual void add_widget(std::unique_ptr widget); protected: - std::vector> widgets; + SafeVector> widgets; }; } \ No newline at end of file diff --git a/include/gui/ScrollablePage.hpp b/include/gui/ScrollablePage.hpp index 5048627..09c618f 100644 --- a/include/gui/ScrollablePage.hpp +++ b/include/gui/ScrollablePage.hpp @@ -1,8 +1,8 @@ #pragma once #include "Widget.hpp" +#include "../SafeVector.hpp" #include -#include namespace gsr { class ScrollablePage : public Widget { @@ -20,6 +20,6 @@ namespace gsr { void add_widget(std::unique_ptr widget); private: mgl::vec2f size; - std::vector> widgets; + SafeVector> widgets; }; } \ No newline at end of file -- cgit v1.2.3