@@ -1361,31 +1361,35 @@ void Demo_SubplotAxisLinking() {
13611361
13621362void Demo_LegendOptions () {
13631363 static ImPlotLocation loc = ImPlotLocation_East;
1364- static bool h = false ; static bool o = true ;
13651364 ImGui::CheckboxFlags (" North" , (unsigned int *)&loc, ImPlotLocation_North); ImGui::SameLine ();
13661365 ImGui::CheckboxFlags (" South" , (unsigned int *)&loc, ImPlotLocation_South); ImGui::SameLine ();
13671366 ImGui::CheckboxFlags (" West" , (unsigned int *)&loc, ImPlotLocation_West); ImGui::SameLine ();
1368- ImGui::CheckboxFlags (" East" , (unsigned int *)&loc, ImPlotLocation_East); ImGui::SameLine ();
1369- ImGui::Checkbox (" Horizontal##2" , &h); ImGui::SameLine ();
1370- ImGui::Checkbox (" Outside" , &o);
1367+ ImGui::CheckboxFlags (" East" , (unsigned int *)&loc, ImPlotLocation_East);
1368+
1369+ static ImPlotLegendFlags flags = 0 ;
1370+
1371+ CHECKBOX_FLAG (flags, ImPlotLegendFlags_Horizontal);
1372+ CHECKBOX_FLAG (flags, ImPlotLegendFlags_Outside);
1373+ CHECKBOX_FLAG (flags, ImPlotLegendFlags_Sort);
13711374
13721375 ImGui::SliderFloat2 (" LegendPadding" , (float *)&GetStyle ().LegendPadding , 0 .0f , 20 .0f , " %.0f" );
13731376 ImGui::SliderFloat2 (" LegendInnerPadding" , (float *)&GetStyle ().LegendInnerPadding , 0 .0f , 10 .0f , " %.0f" );
13741377 ImGui::SliderFloat2 (" LegendSpacing" , (float *)&GetStyle ().LegendSpacing , 0 .0f , 5 .0f , " %.0f" );
13751378
13761379 if (ImPlot::BeginPlot (" ##Legend" ,ImVec2 (-1 ,0 ))) {
1377- ImPlotLegendFlags flags = ImPlotLegendFlags_None;
1378- if (h) flags |= ImPlotLegendFlags_Horizontal;
1379- if (o) flags |= ImPlotLegendFlags_Outside;
13801380 ImPlot::SetupLegend (loc, flags);
1381- static MyImPlot::WaveData data1 (0.001 , 0.2 , 2 , 0.75 );
1382- static MyImPlot::WaveData data2 (0.001 , 0.2 , 4 , 0.25 );
1383- static MyImPlot::WaveData data3 (0.001 , 0.2 , 6 , 0.5 );
1384- ImPlot::PlotLineG (" Item 1" , MyImPlot::SineWave, &data1, 1000 ); // "Item 1" added to legend
1385- ImPlot::PlotLineG (" Item 2##IDText" , MyImPlot::SawWave, &data2, 1000 ); // "Item 2" added to legend, text after ## used for ID only
1381+ static MyImPlot::WaveData data1 (0.001 , 0.2 , 4 , 0.2 );
1382+ static MyImPlot::WaveData data2 (0.001 , 0.2 , 4 , 0.4 );
1383+ static MyImPlot::WaveData data3 (0.001 , 0.2 , 4 , 0.6 );
1384+ static MyImPlot::WaveData data4 (0.001 , 0.2 , 4 , 0.8 );
1385+ static MyImPlot::WaveData data5 (0.001 , 0.2 , 4 , 1.0 );
1386+
1387+ ImPlot::PlotLineG (" Item B" , MyImPlot::SawWave, &data1, 1000 ); // "Item B" added to legend
1388+ ImPlot::PlotLineG (" Item A##IDText" , MyImPlot::SawWave, &data2, 1000 ); // "Item A" added to legend, text after ## used for ID only
13861389 ImPlot::PlotLineG (" ##NotListed" , MyImPlot::SawWave, &data3, 1000 ); // plotted, but not added to legend
1387- ImPlot::PlotLineG (" Item 3" , MyImPlot::SineWave, &data1, 1000 ); // "Item 3" added to legend
1388- ImPlot::PlotLineG (" Item 3" , MyImPlot::SawWave, &data2, 1000 ); // combined with previous "Item 3"
1390+ ImPlot::PlotLineG (" Item C" , MyImPlot::SawWave, &data4, 1000 ); // "Item C" added to legend
1391+ ImPlot::PlotLineG (" Item C" , MyImPlot::SawWave, &data5, 1000 ); // combined with previous "Item C"
1392+
13891393 ImPlot::EndPlot ();
13901394 }
13911395}
0 commit comments