impr: Added icons to all menu items

This commit is contained in:
WerWolv
2024-01-08 21:51:48 +01:00
parent 3a068b9719
commit bfafc692db
32 changed files with 236 additions and 103 deletions

View File

@@ -639,6 +639,7 @@ namespace hex {
struct MenuItem {
std::vector<UnlocalizedString> unlocalizedNames;
const char *icon;
std::unique_ptr<Shortcut> shortcut;
View *view;
MenuCallback callback;
@@ -678,6 +679,19 @@ namespace hex {
*/
void registerMainMenuItem(const UnlocalizedString &unlocalizedName, u32 priority);
/**
* @brief Adds a new main menu entry
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries
* @param icon The icon to use for the entry
* @param priority The priority of the entry. Lower values are displayed first
* @param shortcut The shortcut to use for the entry
* @param function The function to call when the entry is clicked
* @param enabledCallback The function to call to determine if the entry is enabled
* @param view The view to use for the entry. If nullptr, the shortcut will work globally
*/
void addMenuItem(const std::vector<UnlocalizedString> &unlocalizedMainMenuNames, const char *icon, u32 priority, const Shortcut &shortcut, const impl::MenuCallback &function, const impl::EnabledCallback& enabledCallback = []{ return true; }, View *view = nullptr);
/**
* @brief Adds a new main menu entry
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries
@@ -698,6 +712,17 @@ namespace hex {
*/
void addMenuItemSubMenu(std::vector<UnlocalizedString> unlocalizedMainMenuNames, u32 priority, const impl::MenuCallback &function, const impl::EnabledCallback& enabledCallback = []{ return true; });
/**
* @brief Adds a new main menu sub-menu entry
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries
* @param icon The icon to use for the entry
* @param priority The priority of the entry. Lower values are displayed first
* @param function The function to call when the entry is clicked
* @param enabledCallback The function to call to determine if the entry is enabled
*/
void addMenuItemSubMenu(std::vector<UnlocalizedString> unlocalizedMainMenuNames, const char *icon, u32 priority, const impl::MenuCallback &function, const impl::EnabledCallback& enabledCallback = []{ return true; });
/**
* @brief Adds a new main menu separator
* @param unlocalizedMainMenuNames The unlocalized names of the main menu entries

View File

@@ -24,7 +24,7 @@
namespace hex {
class View {
explicit View(UnlocalizedString unlocalizedName);
explicit View(UnlocalizedString unlocalizedName, const char *icon);
public:
virtual ~View() = default;
@@ -82,7 +82,7 @@ namespace hex {
*/
[[nodiscard]] virtual ImGuiWindowFlags getWindowFlags() const;
[[nodiscard]] const char *getIcon() const { return m_icon; }
[[nodiscard]] bool &getWindowOpenState();
[[nodiscard]] const bool &getWindowOpenState() const;
@@ -110,6 +110,7 @@ namespace hex {
bool m_windowOpen = false, m_prevWindowOpen = false;
std::map<Shortcut, ShortcutManager::ShortcutEntry> m_shortcuts;
bool m_windowJustOpened = false;
const char *m_icon;
friend class ShortcutManager;
};
@@ -120,7 +121,7 @@ namespace hex {
*/
class View::Window : public View {
public:
explicit Window(UnlocalizedString unlocalizedName) : View(std::move(unlocalizedName)) {}
explicit Window(UnlocalizedString unlocalizedName, const char *icon) : View(std::move(unlocalizedName), icon) {}
void draw() final {
if (this->shouldDraw()) {
@@ -139,7 +140,7 @@ namespace hex {
*/
class View::Special : public View {
public:
explicit Special(UnlocalizedString unlocalizedName) : View(std::move(unlocalizedName)) {}
explicit Special(UnlocalizedString unlocalizedName) : View(std::move(unlocalizedName), "") {}
void draw() final {
if (this->shouldDraw()) {
@@ -154,7 +155,7 @@ namespace hex {
*/
class View::Floating : public View::Window {
public:
explicit Floating(UnlocalizedString unlocalizedName) : Window(std::move(unlocalizedName)) {}
explicit Floating(UnlocalizedString unlocalizedName) : Window(std::move(unlocalizedName), "") {}
[[nodiscard]] ImGuiWindowFlags getWindowFlags() const override { return ImGuiWindowFlags_NoDocking; }
};
@@ -164,7 +165,7 @@ namespace hex {
*/
class View::Modal : public View {
public:
explicit Modal(UnlocalizedString unlocalizedName) : View(std::move(unlocalizedName)) {}
explicit Modal(UnlocalizedString unlocalizedName) : View(std::move(unlocalizedName), "") {}
void draw() final {
if (this->shouldDraw()) {

View File

@@ -723,10 +723,14 @@ namespace hex {
}
void addMenuItem(const std::vector<UnlocalizedString> &unlocalizedMainMenuNames, u32 priority, const Shortcut &shortcut, const impl::MenuCallback &function, const impl::EnabledCallback& enabledCallback, View *view) {
addMenuItem(unlocalizedMainMenuNames, nullptr, priority, shortcut, function, enabledCallback, view);
}
void addMenuItem(const std::vector<UnlocalizedString> &unlocalizedMainMenuNames, const char *icon, u32 priority, const Shortcut &shortcut, const impl::MenuCallback &function, const impl::EnabledCallback& enabledCallback, View *view) {
log::debug("Added new menu item to menu {} with priority {}", unlocalizedMainMenuNames[0].get(), priority);
impl::getMenuItems().insert({
priority, impl::MenuItem { unlocalizedMainMenuNames, std::make_unique<Shortcut>(shortcut), view, function, enabledCallback }
priority, impl::MenuItem { unlocalizedMainMenuNames, icon, std::make_unique<Shortcut>(shortcut), view, function, enabledCallback }
});
if (shortcut != Shortcut::None) {
@@ -738,18 +742,22 @@ namespace hex {
}
void addMenuItemSubMenu(std::vector<UnlocalizedString> unlocalizedMainMenuNames, u32 priority, const impl::MenuCallback &function, const impl::EnabledCallback& enabledCallback) {
addMenuItemSubMenu(std::move(unlocalizedMainMenuNames), nullptr, priority, function, enabledCallback);
}
void addMenuItemSubMenu(std::vector<UnlocalizedString> unlocalizedMainMenuNames, const char *icon, u32 priority, const impl::MenuCallback &function, const impl::EnabledCallback& enabledCallback) {
log::debug("Added new menu item sub menu to menu {} with priority {}", unlocalizedMainMenuNames[0].get(), priority);
unlocalizedMainMenuNames.emplace_back(impl::SubMenuValue);
impl::getMenuItems().insert({
priority, impl::MenuItem { unlocalizedMainMenuNames, std::make_unique<Shortcut>(), nullptr, function, enabledCallback }
priority, impl::MenuItem { unlocalizedMainMenuNames, icon, std::make_unique<Shortcut>(), nullptr, function, enabledCallback }
});
}
void addMenuItemSeparator(std::vector<UnlocalizedString> unlocalizedMainMenuNames, u32 priority) {
unlocalizedMainMenuNames.emplace_back(impl::SeparatorValue);
impl::getMenuItems().insert({
priority, impl::MenuItem { unlocalizedMainMenuNames, std::make_unique<Shortcut>(), nullptr, []{}, []{ return true; } }
priority, impl::MenuItem { unlocalizedMainMenuNames, "", std::make_unique<Shortcut>(), nullptr, []{}, []{ return true; } }
});
}

View File

@@ -6,7 +6,7 @@
namespace hex {
View::View(UnlocalizedString unlocalizedName) : m_unlocalizedViewName(std::move(unlocalizedName)) { }
View::View(UnlocalizedString unlocalizedName, const char *icon) : m_unlocalizedViewName(std::move(unlocalizedName)), m_icon(icon) { }
bool View::shouldDraw() const {
return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isAvailable();