Shkyera Engine
Easy to use, game engine for Python
FilesystemWidget.hpp
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <functional>
11 
12 #include "core/Filesystem.hpp"
13 #include "ui/Widget.hpp"
14 
15 namespace shkyera {
16 
23 class FilesystemWidget : public Widget {
24  public:
25  using Widget::Widget;
26 
30  virtual void draw() override;
31 
37  void setDirectory(std::filesystem::path path);
38 
39  private:
45  void drawDirectoryTree(const std::shared_ptr<Directory> directory);
46 
52  void drawDirectoryContents(const std::shared_ptr<Directory> directory);
53 
59  void drawDirectory(const std::shared_ptr<Directory> directory);
60 
66  void drawFile(const std::shared_ptr<File> file);
67 
73  void drawIconName(const std::string name) const;
74 
78  void handleRightMouseClick();
79 
83  void drawCreateMenu() const;
84 
91  ImTextureID getTextureOfFile(const std::shared_ptr<File> file) const;
92 
100  static std::string getDisplayableName(std::string name, size_t maxCharactersInLine = 12);
101 
102  std::shared_ptr<Directory> _currentDirectory;
103  std::vector<std::shared_ptr<Directory>> _directoriesToDisplay;
104  std::vector<std::shared_ptr<File>> _filesToDisplay;
105 
107 
108  static constexpr float CONTENTS_ICON_SIZE = 64;
109  static std::string DEFAULT_FOLDER_NAME;
110  static std::string DEFAULT_FILE_NAME;
111 };
112 
113 } // namespace shkyera
Contains the declaration of the Widget class, an abstract base class for GUI widgets.
A user interface widget for interacting with the filesystem.
Definition: FilesystemWidget.hpp:23
std::vector< std::shared_ptr< File > > _filesToDisplay
Files to display in the UI.
Definition: FilesystemWidget.hpp:104
std::vector< std::shared_ptr< Directory > > _directoriesToDisplay
Directories to display in the UI.
Definition: FilesystemWidget.hpp:103
std::shared_ptr< Directory > _currentDirectory
The current working directory to display.
Definition: FilesystemWidget.hpp:102
void handleRightMouseClick()
Handle a right mouse click within the UI.
Definition: FilesystemWidget.cpp:171
static std::string DEFAULT_FOLDER_NAME
The default folder name.
Definition: FilesystemWidget.hpp:109
void drawDirectory(const std::shared_ptr< Directory > directory)
Draw a directory icon and name.
Definition: FilesystemWidget.cpp:110
static std::string getDisplayableName(std::string name, size_t maxCharactersInLine=12)
Get a displayable name for rendering within the UI, ensuring it doesn't exceed a maximum line length.
Definition: FilesystemWidget.cpp:244
static constexpr float CONTENTS_ICON_SIZE
The size of icons representing directory contents.
Definition: FilesystemWidget.hpp:108
bool _hoveredIcon
A flag indicating whether an icon is currently hovered.
Definition: FilesystemWidget.hpp:106
void drawIconName(const std::string name) const
Draw an icon and name within the UI.
Definition: FilesystemWidget.cpp:160
ImTextureID getTextureOfFile(const std::shared_ptr< File > file) const
Get the texture ID associated with a specific file for rendering an icon.
Definition: FilesystemWidget.cpp:230
void setDirectory(std::filesystem::path path)
Set the current working directory to display its contents.
Definition: FilesystemWidget.cpp:42
virtual void draw() override
Implementation of the abstract draw method to render the filesystem widget.
Definition: FilesystemWidget.cpp:13
static std::string DEFAULT_FILE_NAME
The default file name.
Definition: FilesystemWidget.hpp:110
void drawFile(const std::shared_ptr< File > file)
Draw a file icon and name.
Definition: FilesystemWidget.cpp:131
void drawCreateMenu() const
Draw a context menu for creating new files or directories.
Definition: FilesystemWidget.cpp:228
void drawDirectoryTree(const std::shared_ptr< Directory > directory)
Draw the directory tree, starting from the specified directory.
Definition: FilesystemWidget.cpp:47
void drawDirectoryContents(const std::shared_ptr< Directory > directory)
Draw the contents of the specified directory.
Definition: FilesystemWidget.cpp:76
An abstract base class representing a GUI widget.
Definition: Widget.hpp:21
Widget(std::string name)
Constructor to create a widget with a specified name.
Definition: Widget.cpp:5
Definition: Entity.cpp:3