-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathADocumentWindow.cpp
More file actions
80 lines (70 loc) · 3.3 KB
/
ADocumentWindow.cpp
File metadata and controls
80 lines (70 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//// ADocumentWindow.cpp ///////////////////////////////////////////////////////////////
//
// zzzzz zzz zzzzzzzzzzzzz zzzz zzzz zzzzzz zzzzz
// zzzzzzz zzz zzzz zzzz zzzz zzzz
// zzz zzz zzz zzzzzzzzzzzzz zzzz zzzz zzz
// zzz zzz zzz z zzzz zzzz zzzz zzzz
// zzz zzz zzzzzzzzzzzzz zzzz zzz zzzzzzz zzzzz
//
// Author: Mehdy MORVAN
// Date: 29/04/2025
// Description: Source file for the abstract document window class
//
///////////////////////////////////////////////////////////////////////////////
#include "ADocumentWindow.hpp"
#include <imgui_internal.h>
namespace nexo::editor {
void ADocumentWindow::beginRender(const std::string &windowName)
{
dockingUpdate(windowName);
visibilityUpdate();
sizeUpdate();
}
void ADocumentWindow::dockingUpdate(const std::string &windowName)
{
if (const ImGuiWindow* currentWindow = ImGui::GetCurrentWindow(); currentWindow)
{
const bool isDocked = currentWindow->DockIsActive;
const ImGuiID currentDockID = currentWindow->DockId;
const auto dockId = m_windowRegistry.getDockId(windowName);
// If it's the first time opening the window and we have a dock id saved in the registry, then we force set it
if (m_firstOpened && (dockId && currentDockID != *dockId))
ImGui::DockBuilderDockWindow(windowName.c_str(), *dockId);
// If the docks ids differ, it means the window got rearranged in the global layout
// If we are docked but we dont have a dock id saved in the registry, it means the user moved the window
// In both cases, we update our docking registry with the new dock id
else if ((dockId && currentDockID != *dockId) || (isDocked && !dockId))
m_windowRegistry.setDockId(windowName, currentDockID);
// If it is not docked anymore, we have a floating window without docking node,
// So we erase it from the docking registry
if (!m_firstOpened && !isDocked)
m_windowRegistry.resetDockId(windowName);
m_firstOpened = false;
}
}
void ADocumentWindow::visibilityUpdate()
{
m_focused = ImGui::IsWindowFocused();
const bool isDocked = ImGui::IsWindowDocked();
const ImGuiWindow* window = ImGui::GetCurrentWindow();
if (isDocked) {
// If the window is currently being rendered with normal content,
// and not hidden or set to skip items, then it is visible
m_isVisibleInDock = !window->Hidden && !window->SkipItems && window->Active;
}
else {
// Not docked windows are visible if we've reached this point
m_isVisibleInDock = true;
}
m_hovered = ImGui::IsWindowHovered();
}
void ADocumentWindow::sizeUpdate()
{
const ImGuiWindow* window = ImGui::GetCurrentWindow();
m_windowPos = window->Pos;
m_windowSize = window->Size;
m_contentSizeMin = ImGui::GetWindowContentRegionMin();
m_contentSizeMax = ImGui::GetWindowContentRegionMax();
m_contentSize = ImGui::GetContentRegionAvail();
}
}