mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
feat: Add EventViewClosed event (#2377)
Where one door opens, another one closes (said someone) and in this situation i mean view, because there's no event for closing a view only opening one, so please add this :c ### Problem description Simply adds an **EventViewClosed** to match the pre-existing **EventViewOpened**. Also fixes the issue where EventViewOpened wouldn't trigger for windows that were popups (even if they are technically a View. ### Implementation description I mirrored the current functionality of EventViewOpened for closing. --------- Co-authored-by: paxcut <53811119+paxcut@users.noreply.github.com>
This commit is contained in:
@@ -773,38 +773,47 @@ namespace hex {
|
||||
|
||||
ImGui::SetNextWindowClass(&windowClass);
|
||||
|
||||
auto window = ImGui::FindWindowByName(view->getName().c_str());
|
||||
const auto window = ImGui::FindWindowByName(view->getName().c_str());
|
||||
if (window != nullptr && window->DockNode == nullptr)
|
||||
ImGui::SetNextWindowBgAlpha(1.0F);
|
||||
|
||||
// Draw view
|
||||
view->draw();
|
||||
view->trackViewOpenState();
|
||||
view->trackViewState();
|
||||
|
||||
if (view->getWindowOpenState()) {
|
||||
// Get the currently focused view
|
||||
if (window != nullptr && (window->Flags & ImGuiWindowFlags_Popup) != ImGuiWindowFlags_Popup) {
|
||||
if (window != nullptr) {
|
||||
if (view->getWindowOpenState()) {
|
||||
// Get the currently focused view
|
||||
auto windowName = View::toWindowName(name);
|
||||
ImGui::Begin(windowName.c_str());
|
||||
bool focused = false;
|
||||
|
||||
// Detect if the window is focused
|
||||
const bool focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy);
|
||||
view->setFocused(focused);
|
||||
const bool windowIsPopup = (window->Flags & ImGuiWindowFlags_Popup) == ImGuiWindowFlags_Popup;
|
||||
if (!windowIsPopup) {
|
||||
ImGui::Begin(windowName.c_str());
|
||||
|
||||
// Detect if the window is focused
|
||||
focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy);
|
||||
view->setFocused(focused);
|
||||
}
|
||||
|
||||
// Dock the window if it's not already docked
|
||||
if (view->didWindowJustOpen()) {
|
||||
if (!ImGui::IsWindowDocked())
|
||||
// Dock the window if it's not already docked
|
||||
if (!windowIsPopup && !ImGui::IsWindowDocked())
|
||||
ImGui::DockBuilderDockWindow(windowName.c_str(), ImHexApi::System::getMainDockSpaceId());
|
||||
|
||||
EventViewOpened::post(view.get());
|
||||
}
|
||||
|
||||
// Pass on currently pressed keys to the shortcut handler
|
||||
for (const auto &key : m_pressedKeys) {
|
||||
ShortcutManager::process(view.get(), io.ConfigMacOSXBehaviors ? io.KeySuper : io.KeyCtrl, io.KeyAlt, io.KeyShift, io.ConfigMacOSXBehaviors ? io.KeyCtrl : io.KeySuper, focused, key);
|
||||
}
|
||||
if (!windowIsPopup) {
|
||||
for (const auto &key : m_pressedKeys) {
|
||||
ShortcutManager::process(view.get(), io.ConfigMacOSXBehaviors ? io.KeySuper : io.KeyCtrl, io.KeyAlt, io.KeyShift, io.ConfigMacOSXBehaviors ? io.KeyCtrl : io.KeySuper, focused, key);
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
ImGui::End();
|
||||
}
|
||||
} else if (view->didWindowJustClose()) {
|
||||
EventViewClosed::post(view.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user