Viewports, Docking: Added per-viewport work area system for e.g. menu-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.
if(is_popup||is_menu)// Popups and menus bypass style.WindowMinSize by default, but we give then a non-zero minimum size to facilitate understanding problematic cases (e.g. empty popups)
size_min=ImMin(size_min,ImVec2(4.0f,4.0f));
// FIXME-VIEWPORT-WORKAREA: May want to use GetWorkSize() instead of Size depending on the type of windows?
// Tips: Use with ImGuiDockNodeFlags_PassthruCentralNode!
// The limitation with this call is that your window won't have a menu bar.
// Even though we could pass window flags, it would also require the user to be able to call BeginMenuBar() somehow meaning we can't Begin/End in a single function.
// So if you want a menu bar you need to repeat this code manually ourselves. As with advanced other Docking API, we may change this function signature.
// But you can also use BeginMainMenuBar(). If you really want a menu bar inside the same window as the one hosting the dockspace, you will need to copy this code somewhere and tweak it.
ImGuiViewportFlags_CanHostOtherWindows=1<<9// Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window).
};
// The viewports created and managed by imgui. The role of the platform back-end is to create the platform/OS windows corresponding to each viewport.
// The viewports created and managed by Dear ImGui. The role of the platform back-end is to create the platform/OS windows corresponding to each viewport.
// - Main Area = entire viewport.
// - Work Area = entire viewport minus sections optionally used by menu bars, status bars. Some positioning code will prefer to use this. Window are also trying to stay within this area.
structImGuiViewport
{
ImGuiIDID;// Unique identifier for the viewport
ImGuiViewportFlagsFlags;// See ImGuiViewportFlags_
ImVec2Pos;// Position of viewport both in imgui space and in OS desktop/native space
ImVec2Size;// Size of viewport in pixel
floatDpiScale;// 1.0f = 96 DPI = No extra scale
ImVec2Pos;// Main Area: Position of the viewport (the imgui coordinates are the same as OS desktop/native coordinates)
ImVec2Size;// Main Area: Size of the viewport.
ImVec2WorkOffsetMin;// Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height). Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!)
ImVec2WorkOffsetMax;// Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height).
floatDpiScale;// 1.0f = 96 DPI = No extra scale.
ImDrawData*DrawData;// The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame().
ImGuiIDParentViewportId;// (Advanced) 0: no parent. Instruct the platform back-end to setup a parent/child relationship between platform windows.
IM_ASSERT(ImGui::GetCurrentContext()!=NULL&&"Missing dear imgui context. Refer to examples app!");// Exceptionally add an extra assert here for people confused with initial dear imgui setup
// Examples Apps (accessible from the "Examples" menu)
if(show_app_dockspace)ShowExampleAppDockSpace(&show_app_dockspace);// Process the Docking app first, as explicit DockSpace() nodes needs to be submitted early (read comments near the DockSpace function)
if(show_app_documents)ShowExampleAppDocuments(&show_app_documents);// Process the Document app next, as it may also use a DockSpace()
if(no_close)p_open=NULL;// Don't pass our bool* to Begin
// We specify a default position/size in case there's no data in the .ini file. Typically this isn't required! We only do it to make the Demo applications a little more welcoming.
ImVec2MenuBarOffsetMinVal;// *Always on* This is not exposed publicly, so we don't clear it.
ImVec2MenuBarOffsetMinVal;// (Always on) This is not exposed publicly, so we don't clear it and it doesn't have a corresponding flag (could we? for consistency?)
SetNextWindowViewport(viewport->ID);// Enforce viewport so we don't create our onw viewport when ImGuiConfigFlags_ViewportsNoMerge is set.
// Get our rectangle in the work area, and report the size we need for next frame.
// We don't attempt to calculate our height ahead, as it depends on the per-viewport font size. However menu-bar will affect the minimum window size so we'll get the right height.
PushStyleVar(ImGuiStyleVar_WindowMinSize,ImVec2(0,0));// Lift normal size constraint, however the presence of a menu-bar will give us the minimum height we want.