ocornut / imgui

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

Reset docking layout #4899

Open caxapexac opened 2 years ago

caxapexac commented 2 years ago

Version/Branch of Dear ImGui:

Version: 1.86 Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: webGL Compiler: em++ Operating System: V8

My Issue/Question:

I thought this line would reset positions of all the windows but it doesn't:

std::string iniData = "";
ImGui::LoadIniSettingsFromMemory(iniData.c_str(), iniData.size());

How to reset current context data such as windows docking and positions?

dgregorius commented 2 years ago

I just use a simple boolean which I use to trigger a reset...

` void Editor::BeginDockspace() { ImGuiViewport* Viewport = ImGui::GetMainViewport(); ImGui::SetNextWindowPos( Viewport->WorkPos ); ImGui::SetNextWindowSize( Viewport->WorkSize ); ImGui::SetNextWindowViewport( Viewport->ID );

ImGuiWindowFlags WindowFlags = 0;
WindowFlags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking;
WindowFlags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;

ImGui::PushStyleVar( ImGuiStyleVar_WindowRounding, 0.0f );
ImGui::PushStyleVar( ImGuiStyleVar_WindowBorderSize, 0.0f );
ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0.0f, 0.0f ) );
ImGui::Begin( "##Editor", NULL, WindowFlags );
ImGui::PopStyleVar( 3 );

ImGuiID DockspaceID = ImGui::GetID( "##DockspaceID" );
if ( !ImGui::DockBuilderGetNode( DockspaceID ) || mResetLayout )
    {
    mResetLayout = false;

    ImGui::DockBuilderRemoveNode( DockspaceID );
    ImGui::DockBuilderAddNode( DockspaceID );

    // Build dockspace...

    ImGui::DockBuilderFinish( DockspaceID );
    }

ImGui::DockSpace( DockspaceID );
}

`

caxapexac commented 2 years ago

@dgregorius looks working but pretty messy and unflexible Thanks, I'll definetely use it

caxapexac commented 1 year ago

@ocornut should we close this issue if there are no plans adding feature like ImGui::ResetAllDockings()? Seems like it's not really needed for anybody except me :)

ocornut commented 1 year ago

I'm keeping issues open until a decision is taken or solution implemented.