Skip to content

Commit

Permalink
Fix documentation for GtkCanvas: reveal doesn't actually redraw the…
Browse files Browse the repository at this point in the history
… backing store.
  • Loading branch information
jwahlstrand committed Jan 4, 2025
1 parent bc78872 commit c810077
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/src/manual/canvas.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ win = GtkWindow(c, "Canvas")
end
```
This `draw` function will be called each time the window is resized or otherwise needs to refresh its display.
If you need to force a redraw of the canvas, you can call `reveal` on the canvas widget.
If you need to force a redraw of the canvas, you can call `draw(c)`.

![canvas](figures/canvas.png)

Expand Down Expand Up @@ -86,7 +86,7 @@ w = GtkWindow(canvas,"CairoMakie example")

@guarded draw(canvas) do widget
global f, ax, p = lines(1:10)
CairoMakie.autolimits!(ax)
CairoMakie.autolimits!(ax)
screen = CairoMakie.Screen(f.scene, config, Gtk4.cairo_surface(canvas))
CairoMakie.resize!(f.scene, Gtk4.width(widget), Gtk4.height(widget))
CairoMakie.cairo_draw(screen, f.scene)
Expand Down
12 changes: 12 additions & 0 deletions src/cairo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ mutable struct GtkCanvas <: GtkDrawingArea # NOT a GType
end
const GtkCanvasLeaf = GtkCanvas

"""
resize(config::Function, widget::GtkCanvas)
Set a function `config` to be called whenever the `GtkCanvas`'s size is changed and
trigger a redraw. The `config` function should have a single argument, the `GtkCanvas`,
from which the `CairoSurface` can be retrieved using [`getgc`](@ref).
"""
function resize(config::Function, widget::GtkCanvas)
widget.resize = config
if G_.get_realized(widget) && widget.is_sized
Expand All @@ -102,6 +109,11 @@ function draw(redraw::Function, widget::GtkCanvas)
nothing
end

"""
draw(widget::GtkCanvas)
Triggers a redraw of the canvas using a previously set `redraw` function.
"""
function draw(widget::GtkCanvas)
if !isdefined(widget, :back)
#@warn("backing store not defined")
Expand Down

0 comments on commit c810077

Please sign in to comment.