Comments (10)
Is ImageCompare
in the module load path? If so, simply running revise()
will trigger the update. If not, you need to use includet
instead of include
to load the script.
➜ ~ cat ImageCompare.jl
module ImageCompare
using CImGui
#@run include(joinpath(pathof(CImGui), "..", "..", "demo", "demo.jl"))
#@run include(joinpath(pathof(CImGui), "..", "..", "examples", "demo.jl"))
include(joinpath(pathof(CImGui), "..", "..", "examples", "Renderer.jl"))
using .Renderer
function ui()
CImGui.Begin("Hello ImGui!")
CImGui.Button("My Button") && @show "triggered"
CImGui.End()
CImGui.ShowMetricsWindow()
end
function test()
# Default: without hotloading
# Renderer.render(title = "IMGUI Window") do
# CImGui.Begin("Hello ImGui")
# CImGui.Button("My Button") && @show "triggered"
# CImGui.End()
# CImGui.ShowMetricsWindow()
# end
Renderer.render(ui, title = "IMGUI Window", hotloading=true)
end
export test
end
➜ ~ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.5.3 (2020-11-09)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> includet("ImageCompare.jl")
WARNING: replacing module Renderer.
julia> using .ImageCompare
julia> test()
Task (runnable) @0x00000001139918d0
shell> vim ImageCompare.jl
julia> revise()
shell> cat ImageCompare.jl
module ImageCompare
using CImGui
#@run include(joinpath(pathof(CImGui), "..", "..", "demo", "demo.jl"))
#@run include(joinpath(pathof(CImGui), "..", "..", "examples", "demo.jl"))
include(joinpath(pathof(CImGui), "..", "..", "examples", "Renderer.jl"))
using .Renderer
function ui()
CImGui.Begin("Hello ImGui again!")
CImGui.Button("My Button") && @show "triggered"
CImGui.End()
CImGui.ShowMetricsWindow()
end
function test()
# Default: without hotloading
# Renderer.render(title = "IMGUI Window") do
# CImGui.Begin("Hello ImGui")
# CImGui.Button("My Button") && @show "triggered"
# CImGui.End()
# CImGui.ShowMetricsWindow()
# end
Renderer.render(ui, title = "IMGUI Window", hotloading=true)
end
export test
end
from cimgui.jl.
FWIW, here is an example of how to hook a Julia function to a CImGui widget by using Redux.jl.
ReduxImGui.jl is an experimental project for doing state-management with CImGui, you can take it as an example of how to use Redux.jl, but it's still WIP and may contain design flaws, so I wouldn't recommend to use it in practice.
from cimgui.jl.
Thanks Gnimuc! I'm still not clear on how hotloading is supposed to work, but I'll keep watching your project and try it out when I have some more time. :-)
BTW I did a ] add Revise
so IIUC I don't need to includet
, simply using ImageCompare
should do the trick.
from cimgui.jl.
I'm still not clear on how hotloading is supposed to work,
I'm pretty sure all the magic happened on the Revise.jl side. It is probably because those UI functions are running in an async mode that the explicit use of Revise.revise()
is needed.
BTW I did a
] add Revise
so IIUC I don't need toincludet
, simplyusing ImageCompare
should do the trick.
Yes, there is no need to use includet
for packages. The result I posted above is for doing a quick test in the REPL, that's why I need includet
and using .ImageCompare
.
from cimgui.jl.
Hi Gnumic, I finally took time this week-end to revisit Julia and try again to get this working. I got many of the examples working. Thanks a lot for all your work! I also greatly learned from your post: #39 and was planning to close this issue since that post resolves it, but...
The code in your post was working fine on Julia 1.5.2 (IRCC) but later today I upgraded to Julia 1.6.0 and since then, the final code doesn't seem to work - it stops right away, silently. It looks like infinite_loop
only gets called once, and ui
no longer gets called. Can you check if this happens for you as well? Maybe there was a breaking change in Julia? Just in case I re-cut-and-pasted your final code, to no avail.
Thank you!
from cimgui.jl.
@claforte, sorry for the late response. I missed the GitHub notification. The following code works fine on my machine in a fresh REPL.
using CImGui
include(joinpath(pathof(CImGui), "..", "..", "examples", "Renderer.jl"))
using .Renderer
mutable struct MyStates
arr::Vector{Cfloat}
is_stop::Bool
end
# nothing special, just a simple initialization
state_holder = MyStates(Cfloat[sin(x) for x in 0:0.01:2pi], false)
# this method is left intact
update!(arr) = foreach(1:50:600) do i
arr[i] = sin(time()+i)
end
# we only need to add a helper method for multiple dispatch
update!(state::MyStates) = update!(state.arr)
# this is the UI function, whenever the structure of `MyStates` is changed,
# the corresponding changes should be applied
function ui(state::MyStates)
CImGui.Begin("Hello ImGui")
CImGui.PlotLines("sine wave", state.arr, length(state.arr))
CImGui.End()
end
# automatically set the flag when the function gets invoked
function infinite_loop(state::MyStates)
state.is_stop = false
@async while true
state.is_stop && break
update!(state)
yield()
end
end
Renderer.render(()->ui(state_holder), width = 360, height = 480, title = "A simple UI")
infinite_loop(state_holder)
from cimgui.jl.
BTW, I was using the master branch, not the release.
from cimgui.jl.
Thanks Gnimuc! This one works for me on Julia 1.6.0. I'll compare with what I had and I should be able to fix my problem. Thanks a lot!
from cimgui.jl.
I guess you probably started two imgui contexts(two UI windows) at the same time(this is actually very likely if you follow the tutorial from the start). ImGui works best with one single context, so multi-context triggered undefined behavior which in turn caused the crash.
from cimgui.jl.
OK! Yeah, I just restarted the Julia REPL before running your example, that's a likely explanation.
from cimgui.jl.
Related Issues (20)
- update to v1.80 HOT 4
- Long text example crash (`MethodError: no method matching Clipper(::Int64)`) HOT 1
- InvisibleButton should take three arguments HOT 4
- Examples on master branch do not work?
- Tag a 1.82.0 release? HOT 7
- Memory leak HOT 15
- Difficulties with current Renderer.jl HOT 2
- No GUI shown with compiled julia app using CImGui HOT 14
- CImGui fails precompilation at `idGET_FLT_MAX()` HOT 1
- Columns - Horizontal Scroll demo not working in v1.79.0 HOT 3
- TagBot trigger issue HOT 6
- the CImGui.Text(text) function segfaults on aarm (v1.82) HOT 15
- Example code doesn't actually run HOT 6
- Input widgets with different IDs conflict with each other? HOT 5
- How can I get ImGuiWindowClass?
- The getproperty and setproperty! method of ImNodesStyle was not provided
- On some Windows machine, got glfwCreateWindow error HOT 2
- Regenerate new wrapper libraries for fresh ImGui and ImPlot versions? HOT 1
- An error occurs when I use ImGuiTextFilter in a package
- SDL Backend Support? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cimgui.jl.