Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docking Issue: MainMenuBar occluded by dock #2474

Closed
eddieparker opened this issue Apr 5, 2019 · 10 comments
Closed

Docking Issue: MainMenuBar occluded by dock #2474

eddieparker opened this issue Apr 5, 2019 · 10 comments
Labels
menus menu bars, menu items

Comments

@eddieparker
Copy link

I'm not sure if this is expected, but using the docking feature, if I have a BeginMainMenuBar, any docked windows will occlude it. I'd expect that the sizeable space for the dock would respect the mainmenubar where possible.

Example code

		ImVec2 vWindowSize = ImGui::GetMainViewport()->Size;
		ImVec2 vPos0 = ImGui::GetMainViewport()->Pos;

		ImGui::SetNextWindowPos( ImVec2( (float) vPos0.x, (float) vPos0.y ), ImGuiCond_Always );
		ImGui::SetNextWindowSize( ImVec2( (float) vWindowSize.x, (float) vWindowSize.y ), ImGuiSetCond_Always );
		if ( ImGui::Begin(
			"Editor",
			/*p_open=*/nullptr,
			ImGuiWindowFlags_MenuBar |
			ImGuiWindowFlags_NoResize |
			ImGuiWindowFlags_NoMove |
			ImGuiWindowFlags_NoCollapse |
			ImGuiWindowFlags_NoBringToFrontOnFocus
		)
			)
		{
			if ( ImGui::BeginMainMenuBar() )
			{
				if ( ImGui::BeginMenu( "File" ) )
				{
					if ( ImGui::MenuItem( "New map" ) )
					{
					}
					if ( ImGui::MenuItem( "Load map..." ) )
					{
					}
					if ( ImGui::MenuItem( "Save map" ) )
					{
					}
					if ( ImGui::MenuItem( "Save map as..." ) )
					{
					}
					if ( ImGui::MenuItem( "Exit" ) )
					{
						pEngine->RequestTermination();
					}
					ImGui::EndMenu();
				}

				if ( ImGui::BeginMenu( "Windows" ) )
				{
					ImGui::Checkbox( "ImGui Demo Window", &m_bShowDemoWindow );
					ImGui::EndMenu();
				}
			}
			ImGui::EndMainMenuBar();

			ImGui::Begin( "One" );
			ImGui::Text( "Text" );
			ImGui::End();

			if ( m_bShowDemoWindow )
			{
				ImGui::ShowDemoWindow();
			}
		}

		ImGui::End();

If you drag and drop the window named "One" onto any of the docks (directional or 'middle'), it'll hide the mainmenu bar.

@ocornut ocornut added the menus menu bars, menu items label Apr 5, 2019
@ocornut
Copy link
Owner

ocornut commented Apr 5, 2019

You made a mistake here. I’ll let you check the Demo and the Metrics window to understand what you did wrong.

@eddieparker
Copy link
Author

Oh; should I be using the dockspace stuff directly then? Using the demo window I could get what I wanted to work by using dockspace.

Pardon my ignorance, but if you're inclined to teach me how to fish; how should I have used the Metrics window to discover this?

@ocornut
Copy link
Owner

ocornut commented Apr 5, 2019 via email

@eddieparker
Copy link
Author

OK. I seem to have it fixed with using this:

		ImVec2 vWindowSize = ImGui::GetMainViewport()->Size;
		ImVec2 vPos0 = ImGui::GetMainViewport()->Pos;

		ImGui::SetNextWindowPos( ImVec2( (float) vPos0.x, (float) vPos0.y ), ImGuiCond_Always );
		ImGui::SetNextWindowSize( ImVec2( (float) vWindowSize.x, (float) vWindowSize.y ), ImGuiSetCond_Always );
		if ( ImGui::Begin(
			"Editor",
			/*p_open=*/nullptr,
			ImGuiWindowFlags_MenuBar |
			ImGuiWindowFlags_NoResize |
			ImGuiWindowFlags_NoMove |
			ImGuiWindowFlags_NoCollapse |
			ImGuiWindowFlags_NoBringToFrontOnFocus |
			ImGuiWindowFlags_NoTitleBar
		)
			)
		{
			{
				static const ImGuiDockNodeFlags dockspaceFlags = ImGuiDockNodeFlags_None;
				ImGuiID dockSpace = ImGui::GetID( "MainWindowDockspace" );
				ImGui::DockSpace( dockSpace, ImVec2( 0.0f, 0.0f ), dockspaceFlags );

				if ( ImGui::BeginMainMenuBar() )
				{
					if ( ImGui::BeginMenu( "File" ) )
					{
						if ( ImGui::MenuItem( "New map" ) )
						{
						}
						if ( ImGui::MenuItem( "Load map..." ) )
						{
						}
						if ( ImGui::MenuItem( "Save map" ) )
						{
						}
						if ( ImGui::MenuItem( "Save map as..." ) )
						{
						}
						if ( ImGui::MenuItem( "Exit" ) )
						{
						}
						ImGui::EndMenu();
					}
				}
				ImGui::EndMainMenuBar();

				if ( ImGui::Begin( "One" ) )
				{
					ImGui::Text( "Text" );
					ImGui::End();
				}
			}
			ImGui::End();
		}

After having looked through the docking API, this seems to be the 'right' way to do what I'm doing?

Lastly, I notice that I can programmatically cause a dock with SetNextWindowDockID(); but I'd really like to be able to lay it out. I can't see any API surface similar to SetNextWindowDockID(..., [axis]); do you have plans for something like that?

@ocornut
Copy link
Owner

ocornut commented Apr 5, 2019 via email

@ocornut
Copy link
Owner

ocornut commented Apr 5, 2019

( If you want to use a MainMenuBar instead of a regular in-window MenuBar, then make sure your other window doesn’t sit right in front of it, by positioning/sizing it accordingly. )

@eddieparker
Copy link
Author

Interesting. Functionally it didn't seem to create a difference either way until I created the dockspace however.

Also; is there a faculty to programmatically dock to one side of a dockspace? I can't see anything in the public API, and the private stuff seems to use internal splitter/treeview stuff.

@ocornut
Copy link
Owner

ocornut commented Apr 5, 2019

There’s a private/wip DockBuilder api for that, it is discussed in the main docking thread.

@ocornut ocornut closed this as completed Apr 5, 2019
@ocornut
Copy link
Owner

ocornut commented Apr 7, 2019

Functionally it didn't seem to create a difference either way until I created the dockspace however.

There's a large difference. BeginMenuBar() append to the menu bar inside the current window.

BeginMainMenuBar() create a dedicated window just to host a menu bar, that menu bar has no relation to the current window in the stack. In your situation you had two windows overlapping each others and no specific focus restriction on neither of them. So focusing your main large window would bring it to the front of the main menu bar window. The main menu bar also has specific behavior to return focus to the last interacted window after use.

In your situation, the overlapping position made this confusion.

ocornut added a commit that referenced this issue Feb 26, 2020
…-bars. Fixed DocksapceOverViewport() and demo code (overlay etc) (#3035, #2889, #2474, #1542, #2109)

Clarified that BeginMenuMainBar() had an incorrect knowledge of its height (which was previously harmless).
Designed to easily allow for status bars although we don't have/use them yet, but custom code could use them.
@ocornut
Copy link
Owner

ocornut commented Feb 26, 2020

Tangential update for this
Please refer to #3035 and 75de34e !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
menus menu bars, menu items
Projects
None yet
Development

No branches or pull requests

2 participants