Skip to content

reveal() doesn't work but draw() does for GtkCanvas draw updates #81

@srikumarks

Description

@srikumarks

This is either a documentation bug or a code bug I'm not sure.

The doc recommends calling reveal(canvas) to queue a draw call for the canvas' assigned draw function. I see that the code just turns around and calls G_.queue_draw(widget). reveal seems to do nothing though. However, calling draw(canvas) directly seems to do the job. I found this via methods(draw).

Sample code below -

using Gtk4
c = GtkCanvas()
win = GtkWindow("Canvas")
color = Ref(0.0)
@guarded draw(c) do widget
    ctx = getgc(c)
    h = height(c)
    w = width(c)
    # Paint red rectangle
    rectangle(ctx, 0, 0, w, h/2)
    set_source_rgb(ctx, 1, color[], 0)
    fill(ctx)
    # Paint blue rectangle
    rectangle(ctx, 0, 3h/4, w, h/4)
    set_source_rgb(ctx, 0, 0, 1)
    fill(ctx)
end
win.child = c
# Change colour from red to yellow after 5 seconds
@async begin
    sleep(5)
    println("FIRE")
    color[] = 1.0 
    draw(c) # Putting reveal(c) here does not trigger a draw.
end

showall(win)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions