|
| 1 | +import imgui.extension.implot.ImPlot; |
| 2 | +import imgui.extension.implot.ImPlotContext; |
| 3 | +import imgui.flag.ImGuiCond; |
| 4 | +import imgui.internal.ImGui; |
| 5 | +import imgui.type.ImBoolean; |
| 6 | + |
| 7 | +import java.awt.*; |
| 8 | +import java.net.URI; |
| 9 | + |
| 10 | +public class ExampleImPlot { |
| 11 | + private static final String URL = "https://github.com/epezent/implot/tree/555ff68"; |
| 12 | + private static final ImBoolean showDemo = new ImBoolean(false); |
| 13 | + |
| 14 | + private static final Integer[] xs = {0, 1, 2, 3, 4, 5}; |
| 15 | + private static final Integer[] ys = {0, 1, 2, 3, 4, 5}; |
| 16 | + |
| 17 | + private final static ImPlotContext IMPLOT_CONTEXT; |
| 18 | + |
| 19 | + static { |
| 20 | + IMPLOT_CONTEXT = ImPlot.createContext(); |
| 21 | + } |
| 22 | + |
| 23 | + public static void show(ImBoolean showImPlotWindow) { |
| 24 | + ImGui.setNextWindowSize(500, 400, ImGuiCond.Once); |
| 25 | + ImGui.setNextWindowPos(ImGui.getMainViewport().getPosX() + 100, ImGui.getMainViewport().getPosY() + 100, ImGuiCond.Once); |
| 26 | + if (ImGui.begin("ImPlot Demo", showImPlotWindow)) { |
| 27 | + ImGui.text("This a demo for ImPlot"); |
| 28 | + |
| 29 | + ImGui.alignTextToFramePadding(); |
| 30 | + ImGui.text("Repo:"); |
| 31 | + ImGui.sameLine(); |
| 32 | + if (ImGui.button(URL)) { |
| 33 | + try { |
| 34 | + Desktop.getDesktop().browse(new URI(URL)); |
| 35 | + } catch (Exception e) { |
| 36 | + e.printStackTrace(); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + ImGui.checkbox("Show ImPlot Built-In Demo", showDemo); |
| 41 | + |
| 42 | + if (ImPlot.beginPlot("Example Plot")) { |
| 43 | + ImPlot.plotLine("Line", xs, ys); |
| 44 | + ImPlot.plotBars("Bars", xs, ys); |
| 45 | + ImPlot.endPlot(); |
| 46 | + } |
| 47 | + |
| 48 | + if (ImPlot.beginPlot("Example Scatterplot")) { |
| 49 | + ImPlot.plotScatter("Scatter", xs, ys); |
| 50 | + ImPlot.endPlot(); |
| 51 | + } |
| 52 | + |
| 53 | + if (showDemo.get()) { |
| 54 | + ImPlot.showDemoWindow(showDemo); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + ImGui.end(); |
| 59 | + } |
| 60 | +} |
0 commit comments