From 17c4707458190a881f59893c765f83b6ac54ce70 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Fri, 30 Aug 2024 16:24:29 +0200 Subject: [PATCH] Add Gtk4 example using Plots package --- examples/gtk4_plots_ex.jl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/gtk4_plots_ex.jl diff --git a/examples/gtk4_plots_ex.jl b/examples/gtk4_plots_ex.jl new file mode 100644 index 0000000..375666f --- /dev/null +++ b/examples/gtk4_plots_ex.jl @@ -0,0 +1,35 @@ +using Gtk4 +using Plots +using Printf + +c = GtkCanvas() + +function _plot(ctx, w, h) + ENV["GKS_WSTYPE"] = "142" + ENV["GKSconid"] = @sprintf("%lu", UInt64(ctx.ptr)) + gr(show=true) + plot(randn(10, 3), size=(w, h)) +end + +@guarded draw(c) do widget + ctx = getgc(c) + w = width(c) + h = height(c) + @show w, h + rectangle(ctx, 0, 0, w, h) + set_source_rgb(ctx, 1, 1, 1) + fill(ctx) + _plot(ctx, w, h) +end + +win = GtkWindow("Gtk4 example", 600, 450) +win[] = c + +e = GtkEventControllerMotion(c) + +function on_motion(controller, x, y) + win.title = @sprintf("(%g, %g)", x, y) + reveal(c) # triggers a redraw +end + +signal_connect(on_motion, e, "motion")