mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-20 23:06:36 +00:00
Docking: move NavWindow to SelectedTabId application lower to leave a chance for in-between code to alter focus. + store per-node window menu button id to simplify usage.
This commit is contained in:
parent
646c873598
commit
3f16a524c8
14
imgui.cpp
14
imgui.cpp
@ -12761,7 +12761,7 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req)
|
|||||||
ImGuiDir split_dir = req->DockSplitDir;
|
ImGuiDir split_dir = req->DockSplitDir;
|
||||||
if (split_dir != ImGuiDir_None)
|
if (split_dir != ImGuiDir_None)
|
||||||
{
|
{
|
||||||
// Split into one, one side will be our payload node unless we are dropping a loose window
|
// Split into two, one side will be our payload node unless we are dropping a loose window
|
||||||
const ImGuiAxis split_axis = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y;
|
const ImGuiAxis split_axis = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y;
|
||||||
const int split_inheritor_child_idx = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0; // Current contents will be moved to the opposite side
|
const int split_inheritor_child_idx = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0; // Current contents will be moved to the opposite side
|
||||||
const float split_ratio = req->DockSplitRatio;
|
const float split_ratio = req->DockSplitRatio;
|
||||||
@ -12970,6 +12970,7 @@ bool ImGui::DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode*
|
|||||||
ImGuiDockNode::ImGuiDockNode(ImGuiID id)
|
ImGuiDockNode::ImGuiDockNode(ImGuiID id)
|
||||||
{
|
{
|
||||||
ID = id;
|
ID = id;
|
||||||
|
WindowMenuButtonId = ImHashStr("#COLLAPSE", 0, ID);
|
||||||
SharedFlags = LocalFlags = ImGuiDockNodeFlags_None;
|
SharedFlags = LocalFlags = ImGuiDockNodeFlags_None;
|
||||||
ParentNode = ChildNodes[0] = ChildNodes[1] = NULL;
|
ParentNode = ChildNodes[0] = ChildNodes[1] = NULL;
|
||||||
TabBar = NULL;
|
TabBar = NULL;
|
||||||
@ -13804,13 +13805,11 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
|
|||||||
ImVec2 window_menu_button_pos;
|
ImVec2 window_menu_button_pos;
|
||||||
DockNodeCalcTabBarLayout(node, &title_bar_rect, &tab_bar_rect, &window_menu_button_pos);
|
DockNodeCalcTabBarLayout(node, &title_bar_rect, &tab_bar_rect, &window_menu_button_pos);
|
||||||
|
|
||||||
// Submit new tabs and apply NavWindow focus back to the tab bar. They will be added as Unsorted and sorted below based on relative DockOrder value.
|
// Submit new tabs, they will be added as Unsorted and sorted below based on relative DockOrder value.
|
||||||
const int tabs_count_old = tab_bar->Tabs.Size;
|
const int tabs_count_old = tab_bar->Tabs.Size;
|
||||||
for (int window_n = 0; window_n < node->Windows.Size; window_n++)
|
for (int window_n = 0; window_n < node->Windows.Size; window_n++)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = node->Windows[window_n];
|
ImGuiWindow* window = node->Windows[window_n];
|
||||||
if (g.NavWindow && g.NavWindow->RootWindow == window)
|
|
||||||
tab_bar->SelectedTabId = window->ID;
|
|
||||||
if (TabBarFindTabByID(tab_bar, window->ID) == NULL)
|
if (TabBarFindTabByID(tab_bar, window->ID) == NULL)
|
||||||
TabBarAddTab(tab_bar, ImGuiTabItemFlags_Unsorted, window);
|
TabBarAddTab(tab_bar, ImGuiTabItemFlags_Unsorted, window);
|
||||||
}
|
}
|
||||||
@ -13824,7 +13823,8 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
|
|||||||
// Docking/Collapse button
|
// Docking/Collapse button
|
||||||
if (has_window_menu_button)
|
if (has_window_menu_button)
|
||||||
{
|
{
|
||||||
if (CollapseButton(host_window->GetID("#COLLAPSE"), window_menu_button_pos, node))
|
IMGUI_TEST_ENGINE_ID_INFO(node->WindowMenuButtonId, ImGuiDataType_String, "#COLLAPSE");
|
||||||
|
if (CollapseButton(node->WindowMenuButtonId, window_menu_button_pos, node))
|
||||||
OpenPopup("#WindowMenu");
|
OpenPopup("#WindowMenu");
|
||||||
if (IsItemActive())
|
if (IsItemActive())
|
||||||
focus_tab_id = tab_bar->SelectedTabId;
|
focus_tab_id = tab_bar->SelectedTabId;
|
||||||
@ -13847,6 +13847,10 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
|
|||||||
ImQsort(tab_bar->Tabs.Data + tabs_unsorted_start, tab_bar->Tabs.Size - tabs_unsorted_start, sizeof(ImGuiTabItem), TabItemComparerByDockOrder);
|
ImQsort(tab_bar->Tabs.Data + tabs_unsorted_start, tab_bar->Tabs.Size - tabs_unsorted_start, sizeof(ImGuiTabItem), TabItemComparerByDockOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply NavWindow focus back to the tab bar
|
||||||
|
if (g.NavWindow && g.NavWindow->RootWindow->DockNode == node)
|
||||||
|
tab_bar->SelectedTabId = g.NavWindow->RootWindow->ID;
|
||||||
|
|
||||||
// Selected newly added tabs, or persistent tab ID if the tab bar was just recreated
|
// Selected newly added tabs, or persistent tab ID if the tab bar was just recreated
|
||||||
if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabId) != NULL)
|
if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabId) != NULL)
|
||||||
tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabId;
|
tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabId;
|
||||||
|
@ -1227,6 +1227,7 @@ enum ImGuiDockNodeState
|
|||||||
struct IMGUI_API ImGuiDockNode
|
struct IMGUI_API ImGuiDockNode
|
||||||
{
|
{
|
||||||
ImGuiID ID;
|
ImGuiID ID;
|
||||||
|
ImGuiID WindowMenuButtonId; // == ImHashStr("#COLLAPSE", ID)
|
||||||
ImGuiDockNodeFlags SharedFlags; // Flags shared by all nodes of a same dockspace hierarchy (inherited from the root node)
|
ImGuiDockNodeFlags SharedFlags; // Flags shared by all nodes of a same dockspace hierarchy (inherited from the root node)
|
||||||
ImGuiDockNodeFlags LocalFlags; // Flags specific to this node
|
ImGuiDockNodeFlags LocalFlags; // Flags specific to this node
|
||||||
ImGuiDockNodeState State;
|
ImGuiDockNodeState State;
|
||||||
@ -2860,8 +2861,8 @@ extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const char* fmt,
|
|||||||
#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box
|
#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box
|
||||||
#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional)
|
#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional)
|
||||||
#define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log
|
#define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log
|
||||||
#define IMGUI_TEST_ENGINE_ID_INFO(_ID,_TYPE,_DATA) if (g.TestEngineHookIdInfo == id) ImGuiTestEngineHook_IdInfo(&g, _TYPE, _ID, (const void*)(_DATA));
|
#define IMGUI_TEST_ENGINE_ID_INFO(_ID,_TYPE,_DATA) if (g.TestEngineHookIdInfo == _ID) ImGuiTestEngineHook_IdInfo(&g, _TYPE, _ID, (const void*)(_DATA));
|
||||||
#define IMGUI_TEST_ENGINE_ID_INFO2(_ID,_TYPE,_DATA,_DATA2) if (g.TestEngineHookIdInfo == id) ImGuiTestEngineHook_IdInfo(&g, _TYPE, _ID, (const void*)(_DATA), (const void*)(_DATA2));
|
#define IMGUI_TEST_ENGINE_ID_INFO2(_ID,_TYPE,_DATA,_DATA2) if (g.TestEngineHookIdInfo == _ID) ImGuiTestEngineHook_IdInfo(&g, _TYPE, _ID, (const void*)(_DATA), (const void*)(_DATA2));
|
||||||
#else
|
#else
|
||||||
#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) do { } while (0)
|
#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) do { } while (0)
|
||||||
#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) do { } while (0)
|
#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) do { } while (0)
|
||||||
|
Loading…
Reference in New Issue
Block a user