Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multiple JuliaCanvas'es #102

Open
a-ill opened this issue Dec 3, 2020 · 6 comments
Open

Using multiple JuliaCanvas'es #102

a-ill opened this issue Dec 3, 2020 · 6 comments

Comments

@a-ill
Copy link

a-ill commented Dec 3, 2020

Is there a way to have multiple JuliaCanvas'es displaying different content? It seems that if I update one of them, then others also get updated.

barche added a commit that referenced this issue Dec 28, 2020
@barche
Copy link
Collaborator

barche commented Dec 28, 2020

I have added an example for this here: https://github.com/barche/QML.jl/blob/master/example/canvas_twice.jl

You should use a separate callback function for each canvas.

@barche barche closed this as completed Dec 28, 2020
@belliavesha
Copy link

Hello
I just couldn't figure out how to have a list (or even a dynamic list) of canvases. For example, I would need a set of canvases with circles of different radii (with a set of corresponding sliders). What would be a decent way to do that?

I have added an example for this here: https://github.com/barche/QML.jl/blob/master/example/canvas_twice.jl

You should use a separate callback function for each canvas.

@barche
Copy link
Collaborator

barche commented Jan 15, 2021

I just couldn't figure out how to have a list (or even a dynamic list) of canvases. For example, I would need a set of canvases with circles of different radii (with a set of corresponding sliders). What would be a decent way to do that?

You can use any QML component that takes a listmodel, and store the parameters for the canvas in a ListModel. The gltriangle example is also based on this, it uses a Repeater that takes a listmodel with the triangle corners, and represents each corner using a Rectangle "delegate" as it's called in QML. So you could create delegates that contain a JuliaCanvas, and then it should work. For the gltriangle example, the delegate is defined here:

https://github.com/barche/QML.jl/blob/0f03c09e43b161069b9bd53f07fb365ac90add38/example/qml/gltriangle.qml#L23-L57

@belliavesha
Copy link

belliavesha commented Jan 16, 2021

I tried to do that, but each JuliaCanvas must have its own paintFunction. I couldn't manage to create callback functions in a loop. safe_cfunction macro claims, that paint_canvas is not defined. My code Julia code is something like that.

mutable struct Circle
    number::Int
    radius::Float64
    render_function::CxxWrap.CxxWrapCore.SafeCFunction
end

circles = Circle[]
N = 5

function paint_nth_canvas(buffer, n)
    ...
end

for n in 1:N
    function paint_canvas(buffer::Array{UInt32, 1},
            width32::Int32,
            height32::Int32)
        width::Int = width32
        height::Int = height32
        buffer = reshape(buffer, width, height)
        buffer = reinterpret(ARGB32, buffer)
        paint_nth_canvas(buffer,i)
    end
    paint_canvas_wrapped = @safe_cfunction(paint_canvas, Cvoid, (Array{UInt32,1}, Int32, Int32))    
    push!(circles, Circle(i, 10.5*i^2 , paint_canvas_wrapped) )
end

circleModel = ListModel(circles)

@barche
Copy link
Collaborator

barche commented Jan 19, 2021

You need to add a $ before the function name in the @safe_cfunction call, but this fails due to a bug in CxxWrap, should be fixed with JuliaInterop/CxxWrap.jl#282 but let's wait for the tests to pass :)

@barche barche reopened this Jan 19, 2021
@barche
Copy link
Collaborator

barche commented Jan 19, 2021

OK, updating CxxWrap to version v0.11.2 and adding the $ like this should fix it:

paint_canvas_wrapped = @safe_cfunction($paint_canvas, Cvoid, (Array{UInt32,1}, Int32, Int32))

See the @cfunction macro docs for info on why the $ is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants