MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / Demo_SubplotItemSharing

Function Demo_SubplotItemSharing

Source/3rdParty/implot/implot_demo.cpp:1791–1832  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1789//-----------------------------------------------------------------------------
1790
1791void Demo_SubplotItemSharing() {
1792 IMGUI_DEMO_MARKER("Subplots/Item Sharing");
1793 static ImPlotSubplotFlags flags = ImPlotSubplotFlags_ShareItems;
1794 ImGui::CheckboxFlags("ImPlotSubplotFlags_ShareItems", (unsigned int*)&flags, ImPlotSubplotFlags_ShareItems);
1795 ImGui::CheckboxFlags("ImPlotSubplotFlags_ColMajor", (unsigned int*)&flags, ImPlotSubplotFlags_ColMajor);
1796 ImGui::BulletText("Drag and drop items from the legend onto plots (except for 'common')");
1797 static int rows = 2;
1798 static int cols = 3;
1799 static int id[] = {0,1,2,3,4,5};
1800 static int curj = -1;
1801 if (ImPlot::BeginSubplots("##ItemSharing", rows, cols, ImVec2(-1,400), flags)) {
1802 ImPlot::SetupLegend(ImPlotLocation_South, ImPlotLegendFlags_Sort|ImPlotLegendFlags_Horizontal);
1803 for (int i = 0; i < rows*cols; ++i) {
1804 if (ImPlot::BeginPlot("")) {
1805 float fc = 0.01f;
1806 ImPlot::PlotLineG("common",SinewaveGetter,&fc,1000);
1807 for (int j = 0; j < 6; ++j) {
1808 if (id[j] == i) {
1809 char label[8];
1810 float fj = 0.01f * (j+2);
1811 snprintf(label, sizeof(label), "data%d", j);
1812 ImPlot::PlotLineG(label,SinewaveGetter,&fj,1000);
1813 if (ImPlot::BeginDragDropSourceItem(label)) {
1814 curj = j;
1815 ImGui::SetDragDropPayload("MY_DND",nullptr,0);
1816 ImPlot::ItemIcon(GetLastItemColor()); ImGui::SameLine();
1817 ImGui::TextUnformatted(label);
1818 ImPlot::EndDragDropSource();
1819 }
1820 }
1821 }
1822 if (ImPlot::BeginDragDropTargetPlot()) {
1823 if (ImGui::AcceptDragDropPayload("MY_DND"))
1824 id[curj] = i;
1825 ImPlot::EndDragDropTarget();
1826 }
1827 ImPlot::EndPlot();
1828 }
1829 }
1830 ImPlot::EndSubplots();
1831 }
1832}
1833
1834//-----------------------------------------------------------------------------
1835

Callers

nothing calls this directly

Calls 15

BulletTextFunction · 0.85
BeginSubplotsFunction · 0.85
ImVec2Function · 0.85
SetupLegendFunction · 0.85
BeginPlotFunction · 0.85
PlotLineGFunction · 0.85
BeginDragDropSourceItemFunction · 0.85
ItemIconFunction · 0.85
GetLastItemColorFunction · 0.85
EndDragDropSourceFunction · 0.85
BeginDragDropTargetPlotFunction · 0.85
EndDragDropTargetFunction · 0.85

Tested by

no test coverage detected