| 10473 | }; |
| 10474 | |
| 10475 | void ShowExampleAppDocuments(bool* p_open) |
| 10476 | { |
| 10477 | static ExampleAppDocuments app; |
| 10478 | |
| 10479 | // Options |
| 10480 | static bool opt_reorderable = true; |
| 10481 | static ImGuiTabBarFlags opt_fitting_flags = ImGuiTabBarFlags_FittingPolicyDefault_; |
| 10482 | |
| 10483 | bool window_contents_visible = ImGui::Begin("Example: Documents", p_open, ImGuiWindowFlags_MenuBar); |
| 10484 | if (!window_contents_visible) |
| 10485 | { |
| 10486 | ImGui::End(); |
| 10487 | return; |
| 10488 | } |
| 10489 | IMGUI_DEMO_MARKER("Examples/Documents"); |
| 10490 | |
| 10491 | // Menu |
| 10492 | if (ImGui::BeginMenuBar()) |
| 10493 | { |
| 10494 | if (ImGui::BeginMenu("File")) |
| 10495 | { |
| 10496 | int open_count = 0; |
| 10497 | for (MyDocument& doc : app.Documents) |
| 10498 | open_count += doc.Open ? 1 : 0; |
| 10499 | |
| 10500 | if (ImGui::BeginMenu("Open", open_count < app.Documents.Size)) |
| 10501 | { |
| 10502 | for (MyDocument& doc : app.Documents) |
| 10503 | if (!doc.Open && ImGui::MenuItem(doc.Name)) |
| 10504 | doc.DoOpen(); |
| 10505 | ImGui::EndMenu(); |
| 10506 | } |
| 10507 | if (ImGui::MenuItem("Close All Documents", NULL, false, open_count > 0)) |
| 10508 | for (MyDocument& doc : app.Documents) |
| 10509 | app.CloseQueue.push_back(&doc); |
| 10510 | if (ImGui::MenuItem("Exit") && p_open) |
| 10511 | *p_open = false; |
| 10512 | ImGui::EndMenu(); |
| 10513 | } |
| 10514 | ImGui::EndMenuBar(); |
| 10515 | } |
| 10516 | |
| 10517 | // [Debug] List documents with one checkbox for each |
| 10518 | for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++) |
| 10519 | { |
| 10520 | MyDocument& doc = app.Documents[doc_n]; |
| 10521 | if (doc_n > 0) |
| 10522 | ImGui::SameLine(); |
| 10523 | ImGui::PushID(&doc); |
| 10524 | if (ImGui::Checkbox(doc.Name, &doc.Open)) |
| 10525 | if (!doc.Open) |
| 10526 | doc.DoForceClose(); |
| 10527 | ImGui::PopID(); |
| 10528 | } |
| 10529 | |
| 10530 | ImGui::Separator(); |
| 10531 | |
| 10532 | // About the ImGuiWindowFlags_UnsavedDocument / ImGuiTabItemFlags_UnsavedDocument flags. |
no test coverage detected