2020-12-22 18:10:01 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <imgui.h>
|
2021-02-22 23:36:13 +01:00
|
|
|
#include <nfd.hpp>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/api/event.hpp>
|
2021-01-27 14:26:24 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
class View {
|
|
|
|
public:
|
2021-01-21 10:53:12 +01:00
|
|
|
explicit View(std::string viewName);
|
2020-12-22 18:10:01 +01:00
|
|
|
virtual ~View() = default;
|
|
|
|
|
|
|
|
virtual void drawContent() = 0;
|
2021-02-07 14:29:13 +01:00
|
|
|
virtual void drawAlwaysVisible() { }
|
2020-12-22 18:10:01 +01:00
|
|
|
virtual void drawMenu();
|
|
|
|
virtual bool handleShortcut(int key, int mods);
|
2021-02-03 00:56:33 +01:00
|
|
|
virtual bool isAvailable();
|
2021-02-08 19:56:04 +01:00
|
|
|
virtual bool shouldProcess() { return this->isAvailable() && this->getWindowOpenState(); }
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-02-22 23:36:13 +01:00
|
|
|
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);
|
2020-12-22 18:10:01 +01:00
|
|
|
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 = { });
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
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;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
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);
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
void unsubscribeEvent(Events eventType);
|
|
|
|
|
2021-01-28 13:23:50 +01:00
|
|
|
void discardNavigationRequests();
|
2020-12-22 18:10:01 +01:00
|
|
|
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);
|
2021-01-04 00:19:56 +01:00
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
private:
|
|
|
|
std::string m_viewName;
|
2021-02-21 13:49:03 +01:00
|
|
|
bool m_windowOpen = this->hasViewMenuItemEntry();
|
2020-12-22 18:10:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|