Skip to content

Commit

Permalink
Add Gtk4 example using Plots package
Browse files Browse the repository at this point in the history
  • Loading branch information
jheinen committed Aug 30, 2024
1 parent 74873f1 commit 17c4707
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/gtk4_plots_ex.jl
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 17c4707

Please sign in to comment.