-
-
Save sairus7/c87a7dc82af4859dd0c2f8dc58d361c0 to your computer and use it in GitHub Desktop.
Julia MWE using CImGui.jl and ImPlot.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Pkg | |
Pkg.add(name="CImGui", rev="master") | |
Pkg.add(name="ImPlot", rev="main") | |
using CImGui | |
using ImPlot | |
include(joinpath(pathof(ImPlot), "..", "..", "demo", "Renderer.jl")) | |
using .Renderer | |
using CImGui.CSyntax | |
const USERDATA = Dict{String, Any}( | |
"xy1" => (zeros(Float32, 1001), zeros(Float32, 1001)), | |
"xy2" => (zeros(Float32, 11), zeros(Float32, 11)), | |
) | |
const STORAGE = Dict{UInt32, Any}() | |
get_uistate(key::String, default = nothing) = get(STORAGE, CImGui.GetID(key), default) | |
set_uistate(key::String, value) = STORAGE[CImGui.GetID(key)] = value | |
function test_buttons() | |
for i = 1:3 | |
n = get_uistate("counter_$i", 0) | |
if CImGui.Button("Clicked $n times###$i") | |
n += 1 | |
set_uistate("counter_$i", n) | |
#@show n | |
end | |
end | |
if CImGui.Button("Reset") | |
for i = 1:3 | |
set_uistate("counter_$i", 0) | |
end | |
end | |
end | |
function ui() | |
CImGui.Begin("Window") | |
xs1, ys1 = USERDATA["xy1"] | |
xs2, ys2 = USERDATA["xy2"] | |
check = get_uistate("time_checkbox", false) | |
if @c CImGui.Checkbox("Click me to animate plot", &check) | |
set_uistate("time_checkbox", check) | |
end | |
if check | |
DEMO_TIME = CImGui.GetTime() | |
for i in eachindex(xs1) | |
xs1[i] = (i - 1) * 0.001 | |
ys1[i] = 0.5 + 0.5 * sin(50 * (xs1[i] + DEMO_TIME / 10)) | |
end | |
for i in eachindex(xs2) | |
xs2[i] = (i - 1) * 0.1 | |
ys2[i] = xs2[i] * xs2[i] | |
end | |
end | |
CImGui.BulletText("Anti-aliasing can be enabled from the plot's context menu (see Help).") | |
if ImPlot.BeginPlot("Line Plot", "x", "f(x)") | |
ImPlot.PlotLine("sin(x)", xs1, ys1, length(xs1)) | |
ImPlot.SetNextMarkerStyle(ImPlotMarker_Circle) | |
ImPlot.PlotLine("x^2", xs2, ys2, length(xs2)) | |
ImPlot.EndPlot() | |
end | |
test_buttons() | |
CImGui.End() | |
end | |
# # main functinon | |
function show_gui() | |
Renderer.render( | |
ui, # function object | |
width = 1360, | |
height = 780, | |
title = "", | |
hotloading = true | |
) | |
return nothing | |
end | |
show_gui() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cesr42
I've seen the same error on one Windows 10 machine, while on the others it works fine.