ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
58.14k stars 9.96k forks source link

Issue with Amend Tab Bar Visibility in Empty Docking Node #6738

Open Sioyth opened 11 months ago

Sioyth commented 11 months ago

Version/Branch of Dear ImGui:

Version: v1.89.8 Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp Operating System: Windows 11

My Issue/Question:

In order to create a tab manager, I wanted to incorporate a "+" button onto a docking bar. To achieve this, I've been utilizing the ImGui::DockNodeBeginAmendTabBar(dockNode) function. However I append a tab item button to an empty docked bar, therefore the button doesn't appear until a window is docked into it. For a clearer understanding, you can refer to the video provided below. (Probably a bit easier to understand)

I'm guessing that's the wanted and default behaviour to not show anything on it unless a window is there, is there any way to make it visible?

Thank you!

Screenshots/Video

ImGuiTabBarIssue

Set up dock space (SetDefaultStyle function)

// SetDefaultStyle Function
const ImGuiViewport* viewport = ImGui::GetMainViewport();

ImGui::DockBuilderRemoveNode(_arcaneID);
ImGui::DockBuilderAddNode(_arcaneID, _dockSpaceFlags | ImGuiDockNodeFlags_DockSpace);
ImGui::DockBuilderSetNodeSize(_arcaneID, viewport->Size);

ImGui::DockBuilderSplitNode(_arcaneID, ImGuiDir_Left, 0.3f, &left , &_tabManagerDockID);

ImGui::DockBuilderDockWindow("Left", left);
ImGui::DockBuilderFinish(_arcaneID);

Draw Dockspace

const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID);

// Style
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));

// Dockspace Window
ImGui::Begin("Arcane Editor", nullptr, _windowFlags);
ImGui::PopStyleVar(3);
_arcaneID = ImGui::GetID("ArcaneDockSpace");
ImGui::DockSpace(_arcaneID, ImVec2(0.0f, 0.0f), _dockSpaceFlags);

static bool _firstTime = true;
if(_firstTime)
{
   SetDefaultStyle();
   _firstTime = false;
}
ImGui::End();

// Dummy window just for layout
ImGui::Begin("Left");
ImGui::End();

// Get hold of the dock node, add a + button into it for adding new tabs
ImGuiDockNode* dockNode = ImGui::DockBuilderGetNode(_tabManagerDockID);
if (ImGui::DockNodeBeginAmendTabBar(dockNode))
{
   ImGui::TabItemButton("+", ImGuiTabItemFlags_Trailing;
   ImGui::DockNodeEndAmendTabBar();
}
ocornut commented 11 months ago

I hadn't considered this case so far.

In DockNodeUpdate() if you replace this code:

    if (host_window && node->Windows.Size > 0)
    {
        DockNodeUpdateTabBar(node, host_window);
    }

by

    if (host_window && node->IsLeafNode())
    {
        DockNodeUpdateTabBar(node, host_window);
    }

At first glance it would seem to work. but I don't know what the side effects may be and it would need more thought and design work.

As a rule of thumb the way to detect side effects is to run the imgui_test_suite. docking_split_payload seems to be the only failing tests but I would guess this would requires more methodical work to validate.

As an alternative you could also decide to submit a dummy "welcome screen" type of window as a workaround.

Sioyth commented 11 months ago

Hey, thank you for the quick reply.

Yeah, it is a bit of an odd case. I will change it as you suggested and run some tests, even though I might go with what you suggested which was the workaround I had in mind just to have some landing page which honestly also looks better!

But I wonder if this could ever be a feature of the nodes where a flag could be pushed for it to always be visible?

ocornut commented 11 months ago

But I wonder if this could ever be a feature of the nodes where a flag could be pushed for it to always be visible?

We can consider it indeed. If aforementioned change works it could be exposed as a flag. Being a imgui_internal.h flag gives you a little more flexibility in committing this. But first the failing test needs to be investigated.

Sioyth commented 10 months ago

I think that would be a good idea for this edge cases, I will do some investigating and experimenting see if it breaks anything else aswell!