| 10748 | }; |
| 10749 | |
| 10750 | void ShowExampleAppDocuments(bool* p_open) |
| 10751 | { |
| 10752 | static ExampleAppDocuments app; |
| 10753 | |
| 10754 | // Options |
| 10755 | enum Target |
| 10756 | { |
| 10757 | Target_None, |
| 10758 | Target_Tab, // Create documents as local tab into a local tab bar |
| 10759 | Target_DockSpaceAndWindow // Create documents as regular windows, and create an embedded dockspace |
| 10760 | }; |
| 10761 | static Target opt_target = Target_Tab; |
| 10762 | static bool opt_reorderable = true; |
| 10763 | static ImGuiTabBarFlags opt_fitting_flags = ImGuiTabBarFlags_FittingPolicyDefault_; |
| 10764 | |
| 10765 | // When (opt_target == Target_DockSpaceAndWindow) there is the possibily that one of our child Document window (e.g. "Eggplant") |
| 10766 | // that we emit gets docked into the same spot as the parent window ("Example: Documents"). |
| 10767 | // This would create a problematic feedback loop because selecting the "Eggplant" tab would make the "Example: Documents" tab |
| 10768 | // not visible, which in turn would stop submitting the "Eggplant" window. |
| 10769 | // We avoid this problem by submitting our documents window even if our parent window is not currently visible. |
| 10770 | // Another solution may be to make the "Example: Documents" window use the ImGuiWindowFlags_NoDocking. |
| 10771 | |
| 10772 | bool window_contents_visible = ImGui::Begin("Example: Documents", p_open, ImGuiWindowFlags_MenuBar); |
| 10773 | if (!window_contents_visible && opt_target != Target_DockSpaceAndWindow) |
| 10774 | { |
| 10775 | ImGui::End(); |
| 10776 | return; |
| 10777 | } |
| 10778 | IMGUI_DEMO_MARKER("Examples/Documents"); |
| 10779 | |
| 10780 | // Menu |
| 10781 | if (ImGui::BeginMenuBar()) |
| 10782 | { |
| 10783 | if (ImGui::BeginMenu("File")) |
| 10784 | { |
| 10785 | int open_count = 0; |
| 10786 | for (MyDocument& doc : app.Documents) |
| 10787 | open_count += doc.Open ? 1 : 0; |
| 10788 | |
| 10789 | if (ImGui::BeginMenu("Open", open_count < app.Documents.Size)) |
| 10790 | { |
| 10791 | for (MyDocument& doc : app.Documents) |
| 10792 | if (!doc.Open && ImGui::MenuItem(doc.Name)) |
| 10793 | doc.DoOpen(); |
| 10794 | ImGui::EndMenu(); |
| 10795 | } |
| 10796 | if (ImGui::MenuItem("Close All Documents", NULL, false, open_count > 0)) |
| 10797 | for (MyDocument& doc : app.Documents) |
| 10798 | app.CloseQueue.push_back(&doc); |
| 10799 | if (ImGui::MenuItem("Exit") && p_open) |
| 10800 | *p_open = false; |
| 10801 | ImGui::EndMenu(); |
| 10802 | } |
| 10803 | ImGui::EndMenuBar(); |
| 10804 | } |
| 10805 | |
| 10806 | // [Debug] List documents with one checkbox for each |
| 10807 | for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++) |
no test coverage detected