1
0
mirror of synced 2025-02-08 23:09:36 +01:00

impr: Disable main menu items for views that aren't selected right now

This commit is contained in:
WerWolv 2025-02-02 22:32:24 +01:00
parent 7752354598
commit 9fb38922ea
3 changed files with 15 additions and 5 deletions

View File

@ -98,6 +98,14 @@ namespace hex {
[[nodiscard]] static std::string toWindowName(const UnlocalizedString &unlocalizedName);
[[nodiscard]] bool isFocused() const { return m_focused; }
/**
* @brief Used for focus handling. Don't use this directly
* @param focused Whether this view is focused
*/
void setFocused(bool focused) { m_focused = focused; }
public:
class Window;
class Special;
@ -110,6 +118,7 @@ namespace hex {
std::map<Shortcut, ShortcutManager::ShortcutEntry> m_shortcuts;
bool m_windowJustOpened = false;
const char *m_icon;
bool m_focused = false;
friend class ShortcutManager;
};

View File

@ -728,6 +728,7 @@ namespace hex {
// Detect if the window is focused
const bool focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy);
view->setFocused(focused);
// Dock the window if it's not already docked
if (view->didWindowJustOpen() && !ImGui::IsWindowDocked()) {

View File

@ -33,7 +33,7 @@ namespace hex::plugin::builtin {
bool s_displayShortcutHighlights = true;
bool s_useNativeMenuBar = false;
void createNestedMenu(std::span<const UnlocalizedString> menuItems, const char *icon, const Shortcut &shortcut, const ContentRegistry::Interface::impl::MenuCallback &callback, const ContentRegistry::Interface::impl::EnabledCallback &enabledCallback, const ContentRegistry::Interface::impl::SelectedCallback &selectedCallback) {
void createNestedMenu(std::span<const UnlocalizedString> menuItems, const char *icon, const Shortcut &shortcut, View *view, const ContentRegistry::Interface::impl::MenuCallback &callback, const ContentRegistry::Interface::impl::EnabledCallback &enabledCallback, const ContentRegistry::Interface::impl::SelectedCallback &selectedCallback) {
const auto &name = menuItems.front();
if (name.get() == ContentRegistry::Interface::impl::SeparatorValue) {
@ -46,13 +46,13 @@ namespace hex::plugin::builtin {
callback();
}
} else if (menuItems.size() == 1) {
if (menu::menuItemEx(Lang(name), icon, shortcut, selectedCallback(), enabledCallback()))
if (menu::menuItemEx(Lang(name), icon, shortcut, selectedCallback(), enabledCallback() && (view == nullptr || view->isFocused())))
callback();
} else {
bool isSubmenu = (menuItems.begin() + 1)->get() == ContentRegistry::Interface::impl::SubMenuValue;
if (menu::beginMenuEx(Lang(name), std::next(menuItems.begin())->get() == ContentRegistry::Interface::impl::SubMenuValue ? icon : nullptr, isSubmenu ? enabledCallback() : true)) {
createNestedMenu({ std::next(menuItems.begin()), menuItems.end() }, icon, shortcut, callback, enabledCallback, selectedCallback);
createNestedMenu({ std::next(menuItems.begin()), menuItems.end() }, icon, shortcut, view, callback, enabledCallback, selectedCallback);
menu::endMenu();
}
}
@ -287,7 +287,7 @@ namespace hex::plugin::builtin {
toolbarIndex
] = menuItem;
createNestedMenu(unlocalizedNames | std::views::drop(1), icon.glyph.c_str(), shortcut, callback, enabledCallback, selectedCallack);
createNestedMenu(unlocalizedNames | std::views::drop(1), icon.glyph.c_str(), shortcut, view, callback, enabledCallback, selectedCallack);
}
}
@ -572,7 +572,7 @@ namespace hex::plugin::builtin {
const auto &[unlocalizedNames, icon, shortcut, view, callback, enabledCallback, selectedCallback, toolbarIndex] = menuItem;
if (ImGui::BeginPopup(unlocalizedNames.front().get().c_str())) {
createNestedMenu({ unlocalizedNames.begin() + 1, unlocalizedNames.end() }, icon.glyph.c_str(), shortcut, callback, enabledCallback, selectedCallback);
createNestedMenu({ unlocalizedNames.begin() + 1, unlocalizedNames.end() }, icon.glyph.c_str(), shortcut, view, callback, enabledCallback, selectedCallback);
ImGui::EndPopup();
}
}