Simplified structure to mimic a Document model
| 7935 | |
| 7936 | // Simplified structure to mimic a Document model |
| 7937 | struct MyDocument |
| 7938 | { |
| 7939 | const char* Name; // Document title |
| 7940 | bool Open; // Set when open (we keep an array of all available documents to simplify demo code!) |
| 7941 | bool OpenPrev; // Copy of Open from last update. |
| 7942 | bool Dirty; // Set when the document has been modified |
| 7943 | bool WantClose; // Set when the document |
| 7944 | ImVec4 Color; // An arbitrary variable associated to the document |
| 7945 | |
| 7946 | MyDocument(const char* name, bool open = true, const ImVec4& color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)) |
| 7947 | { |
| 7948 | Name = name; |
| 7949 | Open = OpenPrev = open; |
| 7950 | Dirty = false; |
| 7951 | WantClose = false; |
| 7952 | Color = color; |
| 7953 | } |
| 7954 | void DoOpen() { Open = true; } |
| 7955 | void DoQueueClose() { WantClose = true; } |
| 7956 | void DoForceClose() { Open = false; Dirty = false; } |
| 7957 | void DoSave() { Dirty = false; } |
| 7958 | |
| 7959 | // Display placeholder contents for the Document |
| 7960 | static void DisplayContents(MyDocument* doc) |
| 7961 | { |
| 7962 | ImGui::PushID(doc); |
| 7963 | ImGui::Text("Document \"%s\"", doc->Name); |
| 7964 | ImGui::PushStyleColor(ImGuiCol_Text, doc->Color); |
| 7965 | ImGui::TextWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); |
| 7966 | ImGui::PopStyleColor(); |
| 7967 | if (ImGui::Button("Modify", ImVec2(100, 0))) |
| 7968 | doc->Dirty = true; |
| 7969 | ImGui::SameLine(); |
| 7970 | if (ImGui::Button("Save", ImVec2(100, 0))) |
| 7971 | doc->DoSave(); |
| 7972 | ImGui::ColorEdit3("color", &doc->Color.x); // Useful to test drag and drop and hold-dragged-to-open-tab behavior. |
| 7973 | ImGui::PopID(); |
| 7974 | } |
| 7975 | |
| 7976 | // Display context menu for the Document |
| 7977 | static void DisplayContextMenu(MyDocument* doc) |
| 7978 | { |
| 7979 | if (!ImGui::BeginPopupContextItem()) |
| 7980 | return; |
| 7981 | |
| 7982 | char buf[256]; |
| 7983 | sprintf(buf, "Save %s", doc->Name); |
| 7984 | if (ImGui::MenuItem(buf, "CTRL+S", false, doc->Open)) |
| 7985 | doc->DoSave(); |
| 7986 | if (ImGui::MenuItem("Close", "CTRL+W", false, doc->Open)) |
| 7987 | doc->DoQueueClose(); |
| 7988 | ImGui::EndPopup(); |
| 7989 | } |
| 7990 | }; |
| 7991 | |
| 7992 | struct ExampleAppDocuments |
| 7993 | { |