aboutsummaryrefslogtreecommitdiff
path: root/include/gui
diff options
context:
space:
mode:
Diffstat (limited to 'include/gui')
-rw-r--r--include/gui/Button.hpp1
-rw-r--r--include/gui/FileChooser.hpp46
-rw-r--r--include/gui/GsrPage.hpp13
-rw-r--r--include/gui/ScrollablePage.hpp4
-rw-r--r--include/gui/Utils.hpp2
5 files changed, 59 insertions, 7 deletions
diff --git a/include/gui/Button.hpp b/include/gui/Button.hpp
index a4dcca1..bc1dd94 100644
--- a/include/gui/Button.hpp
+++ b/include/gui/Button.hpp
@@ -22,6 +22,7 @@ namespace gsr {
void set_border_scale(float scale);
const std::string& get_text() const;
+ void set_text(std::string str);
std::function<void()> on_click;
private:
diff --git a/include/gui/FileChooser.hpp b/include/gui/FileChooser.hpp
index 309ff56..36dac2d 100644
--- a/include/gui/FileChooser.hpp
+++ b/include/gui/FileChooser.hpp
@@ -1,16 +1,51 @@
#pragma once
#include "Widget.hpp"
+#include "ScrollablePage.hpp"
#include <functional>
#include <vector>
#include <mglpp/graphics/Text.hpp>
+#include <mglpp/graphics/Sprite.hpp>
#include <mglpp/system/Clock.hpp>
// This currently only supports displaying folders
// TODO: Support files as well
namespace gsr {
+ class FileChooser;
+
+ class FileChooserBody : public Widget {
+ friend class FileChooser;
+ public:
+ FileChooserBody(FileChooser *file_chooser, mgl::vec2f size);
+ FileChooserBody(const FileChooserBody&) = delete;
+ FileChooserBody& operator=(const FileChooserBody&) = delete;
+
+ bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override;
+ void draw(mgl::Window &window, mgl::vec2f offset) override;
+
+ mgl::vec2f get_size() override;
+ mgl::vec2f get_inner_size() override;
+ void set_size(mgl::vec2f size);
+ private:
+ void set_current_directory(const char *directory);
+ private:
+ struct Folder {
+ mgl::Text text;
+ time_t last_modified_seconds = 0;
+ };
+
+ FileChooser *file_chooser = nullptr;
+ mgl::vec2f size;
+ mgl::vec2f inner_size;
+ std::vector<Folder> folders;
+ int mouse_over_item = -1;
+ int selected_item = -1;
+ mgl::Clock double_click_timer;
+ int times_clicked_within_timer = 0;
+ };
+
class FileChooser : public Widget {
public:
FileChooser(const char *start_directory, mgl::vec2f size);
@@ -23,6 +58,9 @@ namespace gsr {
mgl::vec2f get_size() override;
void set_current_directory(const char *directory);
+ void open_subdirectory(const char *name);
+ void open_parent_directory();
+ const std::string& get_current_directory() const;
private:
struct Folder {
mgl::Text text;
@@ -31,10 +69,8 @@ namespace gsr {
mgl::vec2f size;
mgl::Text current_directory_text;
- int mouse_over_item = -1;
- int selected_item = -1;
- std::vector<Folder> folders;
- mgl::Clock double_click_timer;
- int times_clicked_within_timer = 0;
+ mgl::Sprite up_arrow_sprite;
+ ScrollablePage scrollable_page;
+ FileChooserBody *file_chooser_body_ptr = nullptr;
};
} \ No newline at end of file
diff --git a/include/gui/GsrPage.hpp b/include/gui/GsrPage.hpp
index 916055a..1d298f4 100644
--- a/include/gui/GsrPage.hpp
+++ b/include/gui/GsrPage.hpp
@@ -3,6 +3,7 @@
#include "Page.hpp"
#include "Button.hpp"
+#include <functional>
#include <mglpp/graphics/Text.hpp>
namespace gsr {
@@ -19,9 +20,12 @@ namespace gsr {
mgl::vec2f get_inner_size() override;
void set_margins(float top, float bottom, float left, float right);
- void set_on_back_button_click(std::function<void()> on_click_handler);
+ void add_button(const std::string &text, const std::string &id, mgl::Color color);
+
+ std::function<void(const std::string &id)> on_click;
private:
void draw_page_label(mgl::Window &window, mgl::vec2f body_pos);
+ void draw_buttons(mgl::Window &window, mgl::vec2f body_pos, mgl::vec2f body_size);
void draw_children(mgl::Window &window, mgl::vec2f position);
float get_border_size() const;
@@ -29,11 +33,16 @@ namespace gsr {
mgl::vec2f get_content_position();
mgl::vec2f get_content_position_with_margin();
private:
+ struct ButtonItem {
+ std::unique_ptr<Button> button;
+ std::string id;
+ };
+
float margin_top_scale = 0.0f;
float margin_bottom_scale = 0.0f;
float margin_left_scale = 0.0f;
float margin_right_scale = 0.0f;
- Button back_button;
mgl::Text label_text;
+ std::vector<ButtonItem> buttons;
};
} \ No newline at end of file
diff --git a/include/gui/ScrollablePage.hpp b/include/gui/ScrollablePage.hpp
index 09c618f..5a31b92 100644
--- a/include/gui/ScrollablePage.hpp
+++ b/include/gui/ScrollablePage.hpp
@@ -18,8 +18,12 @@ namespace gsr {
void set_size(mgl::vec2f size);
void add_widget(std::unique_ptr<Widget> widget);
+
+ void reset_scroll();
private:
mgl::vec2f size;
SafeVector<std::unique_ptr<Widget>> widgets;
+ int scroll_target_y = 0;
+ double scroll_y = 0.0;
};
} \ No newline at end of file
diff --git a/include/gui/Utils.hpp b/include/gui/Utils.hpp
index 885bf3e..6963bc5 100644
--- a/include/gui/Utils.hpp
+++ b/include/gui/Utils.hpp
@@ -13,4 +13,6 @@ namespace mgl {
namespace gsr {
// Inner border
void draw_rectangle_outline(mgl::Window &window, mgl::vec2f pos, mgl::vec2f size, mgl::Color color, float border_size);
+ double get_frame_delta_seconds();
+ void set_frame_delta_seconds(double frame_delta);
} \ No newline at end of file