1 #pragma once 2 3 #include <hex.hpp> 4 5 #include <imgui.h> 6 #include <ImGuiFileBrowser.h> 7 8 #include <hex/api/event.hpp> 9 #include <hex/providers/provider.hpp> 10 11 #include <functional> 12 #include <string> 13 #include <vector> 14 15 16 namespace hex { 17 18 class View { 19 public: 20 explicit View(std::string viewName); 21 virtual ~View() = default; 22 23 virtual void drawContent() = 0; drawAlwaysVisible()24 virtual void drawAlwaysVisible() { } 25 virtual void drawMenu(); 26 virtual bool handleShortcut(int key, int mods); 27 virtual bool isAvailable(); shouldProcess()28 virtual bool shouldProcess() { return this->isAvailable() && this->getWindowOpenState(); } 29 30 static void openFileBrowser(std::string title, imgui_addons::ImGuiFileBrowser::DialogMode mode, std::string validExtensions, const std::function<void(std::string)> &callback); 31 static void doLater(std::function<void()> &&function); 32 static std::vector<std::function<void()>>& getDeferedCalls(); 33 34 static std::vector<std::any> postEvent(Events eventType, const std::any &userData = { }); 35 36 static void drawCommonInterfaces(); 37 38 static void showErrorPopup(std::string_view errorMessage); 39 40 virtual bool hasViewMenuItemEntry(); 41 virtual ImVec2 getMinSize(); 42 virtual ImVec2 getMaxSize(); 43 44 bool& getWindowOpenState(); 45 46 std::string_view getName() const; 47 48 protected: 49 void subscribeEvent(Events eventType, const std::function<std::any(const std::any&)> &callback); 50 void subscribeEvent(Events eventType, const std::function<void(const std::any&)> &callback); 51 52 void unsubscribeEvent(Events eventType); 53 54 void discardNavigationRequests(); 55 protected: 56 void confirmButtons(const char *textLeft, const char *textRight, const std::function<void()> &leftButtonFn, const std::function<void()> &rightButtonFn); 57 58 private: 59 std::string m_viewName; 60 bool m_windowOpen = false; 61 }; 62 63 }