From c8100777cb3032922333deaa82ac98b2806a4a52 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sat, 4 Jan 2025 12:38:59 -0500 Subject: [PATCH] Fix documentation for GtkCanvas: `reveal` doesn't actually redraw the backing store. --- docs/src/manual/canvas.md | 4 ++-- src/cairo.jl | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/src/manual/canvas.md b/docs/src/manual/canvas.md index ba9b1bab..ac255fc7 100644 --- a/docs/src/manual/canvas.md +++ b/docs/src/manual/canvas.md @@ -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) @@ -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) diff --git a/src/cairo.jl b/src/cairo.jl index 8e09364c..c1d249e4 100644 --- a/src/cairo.jl +++ b/src/cairo.jl @@ -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 @@ -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")