mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
feat: Allow custom UIs to be drawn in the command palette
This commit is contained in:
@@ -26,6 +26,7 @@ EXPORT_MODULE namespace hex {
|
||||
std::function<void(std::string)> callback;
|
||||
};
|
||||
|
||||
using ContentDisplayCallback = std::function<void(std::string)>;
|
||||
using DisplayCallback = std::function<std::string(std::string)>;
|
||||
using ExecuteCallback = std::function<std::optional<std::string>(std::string)>;
|
||||
using QueryCallback = std::function<std::vector<QueryResult>(std::string)>;
|
||||
@@ -48,6 +49,8 @@ EXPORT_MODULE namespace hex {
|
||||
const std::vector<Entry>& getEntries();
|
||||
const std::vector<Handler>& getHandlers();
|
||||
|
||||
std::optional<ContentDisplayCallback>& getDisplayedContent();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,6 +80,12 @@ EXPORT_MODULE namespace hex {
|
||||
const std::string &command,
|
||||
const impl::QueryCallback &queryCallback,
|
||||
const impl::DisplayCallback &displayCallback);
|
||||
|
||||
/**
|
||||
* @brief Specify UI content that will be displayed inside the command palette
|
||||
* @param displayCallback Display callback that will be called to display the content
|
||||
*/
|
||||
void setDisplayedContent(const impl::ContentDisplayCallback &displayCallback);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -613,6 +613,11 @@ namespace hex {
|
||||
return *s_handlers;
|
||||
}
|
||||
|
||||
static AutoReset<std::optional<ContentDisplayCallback>> s_displayedContent;
|
||||
std::optional<ContentDisplayCallback>& getDisplayedContent() {
|
||||
return *s_displayedContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void add(Type type, const std::string &command, const UnlocalizedString &unlocalizedDescription, const impl::DisplayCallback &displayCallback, const impl::ExecuteCallback &executeCallback) {
|
||||
@@ -627,6 +632,10 @@ namespace hex {
|
||||
impl::s_handlers->push_back(impl::Handler { type, command, queryCallback, displayCallback });
|
||||
}
|
||||
|
||||
void setDisplayedContent(const impl::ContentDisplayCallback &displayCallback) {
|
||||
impl::s_displayedContent = displayCallback;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user