Demo: Testing return value of BeginTabBar() for consistency.

docking
omar 6 years ago
parent e6cc547a94
commit 8b956216b7

@ -150,7 +150,8 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- dock: C- nav: CTRL+TAB highlighting tabs shows the mismatch between focus-stack and tab-order (not visible in VS because it doesn't highlight the tabs) - dock: C- nav: CTRL+TAB highlighting tabs shows the mismatch between focus-stack and tab-order (not visible in VS because it doesn't highlight the tabs)
- dock: C- after a dock/undock, the Scrollbar Status update in Begin() should use an updated e.g. size_y_for_scrollbars to avoid a 1 frame scrollbar flicker. - dock: C- after a dock/undock, the Scrollbar Status update in Begin() should use an updated e.g. size_y_for_scrollbars to avoid a 1 frame scrollbar flicker.
- tabs: re-ordering, close buttons, context menu, persistent order (#261, #351) - tabs: make EndTabBar fail if users doesn't respect BeginTabBar return value, for consistency/future-proofing.
- tabs: persistent order/focus in BeginTabBar() api (#261, #351)
- ext: stl-ish friendly extension (imgui_stl.h) that has wrapper for std::string, std::vector etc. - ext: stl-ish friendly extension (imgui_stl.h) that has wrapper for std::string, std::vector etc.

@ -1721,23 +1721,25 @@ void ImGui::ShowDemoWindow(bool* p_open)
if (ImGui::TreeNode("Basic")) if (ImGui::TreeNode("Basic"))
{ {
ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_None; ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_None;
ImGui::BeginTabBar("MyTabBar", tab_bar_flags); if (ImGui::BeginTabBar("MyTabBar", tab_bar_flags))
if (ImGui::BeginTabItem("Avocado"))
{ {
ImGui::Text("This is the Avocado tab!\nblah blah blah blah blah"); if (ImGui::BeginTabItem("Avocado"))
ImGui::EndTabItem(); {
} ImGui::Text("This is the Avocado tab!\nblah blah blah blah blah");
if (ImGui::BeginTabItem("Broccoli")) ImGui::EndTabItem();
{ }
ImGui::Text("This is the Broccoli tab!\nblah blah blah blah blah"); if (ImGui::BeginTabItem("Broccoli"))
ImGui::EndTabItem(); {
} ImGui::Text("This is the Broccoli tab!\nblah blah blah blah blah");
if (ImGui::BeginTabItem("Cucumber")) ImGui::EndTabItem();
{ }
ImGui::Text("This is the Cucumber tab!\nblah blah blah blah blah"); if (ImGui::BeginTabItem("Cucumber"))
ImGui::EndTabItem(); {
ImGui::Text("This is the Cucumber tab!\nblah blah blah blah blah");
ImGui::EndTabItem();
}
ImGui::EndTabBar();
} }
ImGui::EndTabBar();
ImGui::Separator(); ImGui::Separator();
ImGui::TreePop(); ImGui::TreePop();
} }
@ -1766,16 +1768,18 @@ void ImGui::ShowDemoWindow(bool* p_open)
} }
// Passing a bool* to BeginTabItem() is similar to passing one to Begin(): the underlying bool will be set to false when the tab is closed. // Passing a bool* to BeginTabItem() is similar to passing one to Begin(): the underlying bool will be set to false when the tab is closed.
ImGui::BeginTabBar("MyTabBar", tab_bar_flags); if (ImGui::BeginTabBar("MyTabBar", tab_bar_flags))
for (int n = 0; n < IM_ARRAYSIZE(opened); n++) {
if (opened[n] && ImGui::BeginTabItem(names[n], &opened[n])) for (int n = 0; n < IM_ARRAYSIZE(opened); n++)
{ if (opened[n] && ImGui::BeginTabItem(names[n], &opened[n]))
ImGui::Text("This is the %s tab!", names[n]); {
if (n & 1) ImGui::Text("This is the %s tab!", names[n]);
ImGui::Text("I am an odd tab."); if (n & 1)
ImGui::EndTabItem(); ImGui::Text("I am an odd tab.");
} ImGui::EndTabItem();
ImGui::EndTabBar(); }
ImGui::EndTabBar();
}
ImGui::Separator(); ImGui::Separator();
ImGui::TreePop(); ImGui::TreePop();
} }
@ -3952,41 +3956,42 @@ void ShowExampleAppDocuments(bool* p_open)
if (opt_target == Target_Tab) if (opt_target == Target_Tab)
{ {
ImGuiTabBarFlags tab_bar_flags = (opt_fitting_flags) | (opt_reorderable ? ImGuiTabBarFlags_Reorderable : 0); ImGuiTabBarFlags tab_bar_flags = (opt_fitting_flags) | (opt_reorderable ? ImGuiTabBarFlags_Reorderable : 0);
ImGui::BeginTabBar("##tabs", tab_bar_flags); if (ImGui::BeginTabBar("##tabs", tab_bar_flags))
{
if (opt_reorderable)
NotifyOfDocumentsClosedElsewhere(app);
if (opt_reorderable) // [DEBUG] Stress tests
NotifyOfDocumentsClosedElsewhere(app); //if ((ImGui::GetFrameCount() % 30) == 0) docs[1].Open ^= 1; // [DEBUG] Automatically show/hide a tab. Test various interactions e.g. dragging with this on.
//if (ImGui::GetIO().KeyCtrl) ImGui::SetTabItemSelected(docs[1].Name); // [DEBUG] Test SetTabItemSelected(), probably not very useful as-is anyway..
// [DEBUG] Stress tests // Submit Tabs
//if ((ImGui::GetFrameCount() % 30) == 0) docs[1].Open ^= 1; // [DEBUG] Automatically show/hide a tab. Test various interactions e.g. dragging with this on. for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++)
//if (ImGui::GetIO().KeyCtrl) ImGui::SetTabItemSelected(docs[1].Name); // [DEBUG] Test SetTabItemSelected(), probably not very useful as-is anyway.. {
MyDocument* doc = &app.Documents[doc_n];
if (!doc->Open)
continue;
// Submit Tabs ImGuiTabItemFlags tab_flags = (doc->Dirty ? ImGuiTabItemFlags_UnsavedDocument : 0);
for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++) bool visible = ImGui::BeginTabItem(doc->Name, &doc->Open, tab_flags);
{
MyDocument* doc = &app.Documents[doc_n];
if (!doc->Open)
continue;
ImGuiTabItemFlags tab_flags = (doc->Dirty ? ImGuiTabItemFlags_UnsavedDocument : 0); // Cancel attempt to close when unsaved add to save queue so we can display a popup.
bool visible = ImGui::BeginTabItem(doc->Name, &doc->Open, tab_flags); if (!doc->Open && doc->Dirty)
{
doc->Open = true;
doc->DoQueueClose();
}
// Cancel attempt to close when unsaved add to save queue so we can display a popup. MyDocument::DisplayContextMenu(doc);
if (!doc->Open && doc->Dirty) if (visible)
{ {
doc->Open = true; MyDocument::DisplayContents(doc);
doc->DoQueueClose(); ImGui::EndTabItem();
}
} }
MyDocument::DisplayContextMenu(doc); ImGui::EndTabBar();
if (visible)
{
MyDocument::DisplayContents(doc);
ImGui::EndTabItem();
}
} }
ImGui::EndTabBar();
} }
else if (opt_target == Target_Window) else if (opt_target == Target_Window)
{ {

Loading…
Cancel
Save