1
0
mirror of synced 2024-11-14 19:17:42 +01:00
ImHex/plugins/libimhex/include/hex/views/view.hpp

69 lines
2.0 KiB
C++
Raw Normal View History

#pragma once
#include <hex.hpp>
#include <imgui.h>
#include <nfd.hpp>
#include <hex/api/event.hpp>
#include <hex/providers/provider.hpp>
#include <functional>
#include <string>
#include <vector>
namespace hex {
class View {
public:
2021-01-21 10:53:12 +01:00
explicit View(std::string viewName);
virtual ~View() = default;
virtual void drawContent() = 0;
virtual void drawAlwaysVisible() { }
virtual void drawMenu();
virtual bool handleShortcut(int key, int mods);
2021-02-03 00:56:33 +01:00
virtual bool isAvailable();
virtual bool shouldProcess() { return this->isAvailable() && this->getWindowOpenState(); }
enum class DialogMode {
Open,
Save,
Folder
};
static void openFileBrowser(std::string_view title, DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::string)> &callback);
2021-01-21 10:53:12 +01:00
static void doLater(std::function<void()> &&function);
static std::vector<std::function<void()>>& getDeferedCalls();
2021-01-21 10:53:12 +01:00
static std::vector<std::any> postEvent(Events eventType, const std::any &userData = { });
static void drawCommonInterfaces();
static void showErrorPopup(std::string_view errorMessage);
virtual bool hasViewMenuItemEntry();
virtual ImVec2 getMinSize();
virtual ImVec2 getMaxSize();
bool& getWindowOpenState();
2021-01-21 10:53:12 +01:00
std::string_view getName() const;
protected:
2021-01-21 10:53:12 +01:00
void subscribeEvent(Events eventType, const std::function<std::any(const std::any&)> &callback);
void subscribeEvent(Events eventType, const std::function<void(const std::any&)> &callback);
void unsubscribeEvent(Events eventType);
void discardNavigationRequests();
protected:
2021-01-21 10:53:12 +01:00
void confirmButtons(const char *textLeft, const char *textRight, const std::function<void()> &leftButtonFn, const std::function<void()> &rightButtonFn);
private:
std::string m_viewName;
bool m_windowOpen = this->hasViewMenuItemEntry();
};
}