asset_browser.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*******************************************************************************************
  2. *
  3. * raylib-extras [ImGui] example - asset browser
  4. *
  5. * This is a more complex ImGui Integration
  6. * It shows how to build windows on top of 2d and 3d views using a render texture
  7. *
  8. * Copyright (c) 2024 Jeffery Myers
  9. *
  10. ********************************************************************************************/
  11. #pragma once
  12. #include "item_view.h"
  13. #include "raylib.h"
  14. #include <string>
  15. #include <vector>
  16. #include <list>
  17. class AssetBrowserPanel
  18. {
  19. public:
  20. AssetBrowserPanel();
  21. void Show();
  22. private:
  23. std::string AssetRoot;
  24. class AssetItemInfo : public ViewableItem
  25. {
  26. protected:
  27. bool File = false;
  28. public:
  29. AssetItemInfo(bool file) : File(file) {}
  30. bool IsFile() const { return File; }
  31. };
  32. class FileInfo : public AssetItemInfo
  33. {
  34. public:
  35. FileInfo() : AssetItemInfo(true) {}
  36. std::string FullPath;
  37. };
  38. class FolderInfo : public AssetItemInfo
  39. {
  40. public:
  41. FolderInfo() : AssetItemInfo(false) {}
  42. std::string FullPath;
  43. FolderInfo* Parent = nullptr;
  44. std::list<FolderInfo> Children;
  45. bool ForceOpenNextFrame = false;
  46. void PopulateChildren();
  47. };
  48. FolderInfo FolderRoot;
  49. class AssetContainer : public ViewableItemContainer
  50. {
  51. public:
  52. ViewableItem* Reset() override;
  53. size_t Count() override;
  54. ViewableItem* Next() override;
  55. FolderInfo* Folder = nullptr;
  56. std::vector<FileInfo> Files;
  57. std::vector<FileInfo>::iterator FileItr;
  58. std::list<FolderInfo>::iterator FolderItr;
  59. };
  60. AssetContainer CurrentFolderContents;
  61. ListItemView ListView;
  62. ItemView* CurrentView = nullptr;
  63. void RebuildFolderTree();
  64. void SetCurrentFolder(FolderInfo* folder);
  65. bool ShowFolderTreeNode(FolderInfo& folder);
  66. void ShowFolderTree();
  67. void ShowFilePane();
  68. void ShowHeader();
  69. const char* GetFileIcon(const char* filename);
  70. };