Furrent
gui.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <raylib/file_dialog.h>
4 #include <raylib/raygui.h>
5 #include <raylib/raylib.h>
6 
7 #include <functional>
8 #include <furrent.hpp>
9 #include <list>
10 #include <string>
11 
12 namespace fur::gui {
13 
16  bool play;
21 };
22 
24  Vector2 scroll;
25  std::list<TorrentGuiData> torrents;
27 };
28 
29 using torrent_insert_fn = std::function<std::optional<TorrentGuiData>(
30  const std::string&, const std::string&)>;
31 using torrent_update_fn = std::function<TorrentGuiData(TorrentID tid)>;
32 using torrent_remove_fn = std::function<void(const TorrentGuiData&)>;
33 
35 class Window {
36  std::string _title;
37  int _width, _height;
38 
39  private:
40  // All GUI buttons
41  bool _button_file_dialog;
42 
44  GuiFileDialogState _file_loader;
46  GuiScrollTorrentState _scroller;
47 
48  torrent_insert_fn _insert_fn;
49  torrent_update_fn _update_fn;
50  torrent_remove_fn _remove_fn;
51 
52  public:
54  Window(const std::string& title, int width, int height);
55  virtual ~Window();
56 
58  void run();
59 
63 
64  private:
66  void configure_style();
67 
69  void render_base();
71  void render_file_dialog();
73  void render_torrent_item(const TorrentGuiData& torrent, float pos);
75  void render_torrents();
77  void render_confirm_dialog();
78 };
79 
80 } // namespace fur::gui
fur::gui::Window::set_torrent_insert_fn
void set_torrent_insert_fn(torrent_insert_fn fn)
Definition: gui.cpp:64
fur::gui::Window::~Window
virtual ~Window()
Definition: gui.cpp:37
fur::gui::GuiTorrentDialogState::play
bool play
True if the button play has been pressed.
Definition: gui.hpp:16
fur::gui::torrent_insert_fn
std::function< std::optional< TorrentGuiData >(const std::string &, const std::string &)> torrent_insert_fn
Definition: gui.hpp:30
fur::gui::torrent_update_fn
std::function< TorrentGuiData(TorrentID tid)> torrent_update_fn
Definition: gui.hpp:31
fur::gui::torrent_remove_fn
std::function< void(const TorrentGuiData &)> torrent_remove_fn
Definition: gui.hpp:32
fur::gui::GuiTorrentDialogState
Definition: gui.hpp:14
fur::TorrentID
int64_t TorrentID
Definition: types.hpp:8
fur::gui::Window::set_torrent_update_fn
void set_torrent_update_fn(torrent_update_fn fn)
Definition: gui.cpp:68
fur::gui::GuiScrollTorrentState::torrents
std::list< TorrentGuiData > torrents
Definition: gui.hpp:25
fur::TorrentGuiData
Definition: furrent.hpp:14
fur::gui::Window::set_torrent_remove_fn
void set_torrent_remove_fn(torrent_remove_fn fn)
Definition: gui.cpp:72
fur::gui
Definition: colors.hpp:7
fur::gui::GuiScrollTorrentState::scroll
Vector2 scroll
Definition: gui.hpp:24
fur::gui::Window::Window
Window(const std::string &title, int width, int height)
Constructs a new window of a fixed size.
Definition: gui.cpp:20
fur::gui::GuiScrollTorrentState
Definition: gui.hpp:23
fur::gui::Window
Responsible for rendering the UI.
Definition: gui.hpp:35
fur::gui::GuiScrollTorrentState::torrent_dialog_state
GuiTorrentDialogState torrent_dialog_state
Definition: gui.hpp:26
fur::gui::GuiTorrentDialogState::delete_torrent
bool delete_torrent
True if the button delete of a specific torrent has been pressed.
Definition: gui.hpp:18
fur::gui::GuiTorrentDialogState::torrent
TorrentGuiData torrent
Target torrent.
Definition: gui.hpp:20
fur::gui::Window::run
void run()
Start the UI loop.
Definition: gui.cpp:39
furrent.hpp