Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
FilesystemWidget.hpp
Go to the documentation of this file.
1
8#pragma once
9
10#include <functional>
11
12#include <imgui.h>
13
16#include <ECS/Registry.hpp>
17#include <UI/Widget.hpp>
18#include <Utils/AssetUtils.hpp>
19
20namespace shkyera {
21
28class FilesystemWidget : public Widget {
29 public:
30 FilesystemWidget(std::string name, std::shared_ptr<Registry> registry);
31
35 virtual void draw() override;
36
37 private:
44
51
58
65 template <typename AssetType>
67 const auto& fileName = _registry->getComponent<NameComponent>(handle).getName();
68
69 ImGui::BeginGroup();
70 ImGui::PushID(fileName.c_str());
71
72 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
73
75
76 const auto assetTypeName = std::string(typeid(AssetType).name());
77 if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
78 ImGui::TextUnformatted(fileName.c_str());
79 ImGui::SetDragDropPayload(("ASSET_" + assetTypeName).c_str(), reinterpret_cast<void*>(&handle),
80 sizeof(AssetHandle));
81 ImGui::EndDragDropSource();
82 }
83 _hoveredIcon |= ImGui::IsItemHovered();
84
85 ImGui::PopStyleColor();
86
88
89 ImGui::PopID();
90 ImGui::EndGroup();
91 }
92
98 template <typename AssetType>
100
106 void drawIconName(const std::string& name) const;
107
109
110 static constexpr float CONTENTS_ICON_SIZE = 64;
111
112 std::shared_ptr<Registry> _registry;
121};
122
123} // namespace shkyera
A user interface widget for interacting with the filesystem.
Definition FilesystemWidget.hpp:28
void drawIconName(const std::string &name) const
Draw an icon and name within the UI.
Definition FilesystemWidget.cpp:241
AssetHandle _currentDirectoryHandle
Definition FilesystemWidget.hpp:114
void drawDirectoryContents()
Draw the contents of the specified directory.
Definition FilesystemWidget.cpp:102
void handleRightMouseClick()
Definition FilesystemWidget.cpp:150
AssetRef< Texture > _textIcon
Definition FilesystemWidget.hpp:118
AssetRef< Texture > _audioIcon
Definition FilesystemWidget.hpp:119
static constexpr float CONTENTS_ICON_SIZE
The size of icons representing directory contents.
Definition FilesystemWidget.hpp:110
bool _hoveredIcon
Definition FilesystemWidget.hpp:120
void drawAssetIcon(AssetHandle handle)
void drawAsset(AssetHandle handle)
Draw an asset icon and name.
Definition FilesystemWidget.hpp:66
virtual void draw() override
Implementation of the abstract draw method to render the filesystem widget.
Definition FilesystemWidget.cpp:37
AssetRef< Texture > _imageIcon
Definition FilesystemWidget.hpp:117
AssetRef< Texture > _folderIcon
Definition FilesystemWidget.hpp:115
void drawDirectoryTree(AssetHandle directoryHandle)
Draw the directory tree, starting from the specified directory.
Definition FilesystemWidget.cpp:68
AssetHandle _rootDirectoryHandle
Definition FilesystemWidget.hpp:113
AssetRef< Texture > _pythonIcon
Definition FilesystemWidget.hpp:116
std::shared_ptr< Registry > _registry
Definition FilesystemWidget.hpp:112
void drawDirectory(AssetHandle directoryHandle)
Draw a directory icon and name.
Definition FilesystemWidget.cpp:186
Definition NameComponent.hpp:9
An abstract base class representing a GUI widget.
Definition Widget.hpp:23
Definition Asset.hpp:6
Entity AssetHandle
Definition Asset.hpp:8
Definition Clock.hpp:9