Skip to content

Commit

Permalink
port: Drawing Area
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Sep 3, 2024
1 parent da811d6 commit 5d7fe6e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Drawing Area/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const drawingArea = workbench.builder.get_object("drawing_area");
const scaleRotate = workbench.builder.get_object("scale");
import Gtk from "gi://Gtk?version=4.0";
import cairo from "cairo";

const drawingArea = workbench.builder.get_object<Gtk.DrawingArea>(
"drawing_area",
);
const scaleRotate = workbench.builder.get_object<Gtk.Scale>("scale");

const triangle = [
[100, 100],
Expand All @@ -8,7 +13,9 @@ const triangle = [
];
var angle = 0;

drawingArea.set_draw_func((_self, cr, _width, _height) => {
// TS: the `cairo.Context` type is broken here
// See: https://github.com/gjsify/ts-for-gir/issues/194
drawingArea.set_draw_func((_self, cr: cairo.Context, _width, _height) => {
// Draw triangle in context
cr.translate(150, 150);
cr.rotate(angle);
Expand All @@ -20,6 +27,9 @@ drawingArea.set_draw_func((_self, cr, _width, _height) => {
cr.setSourceRGBA(1, 0, 1, 1);
cr.stroke();
// Freeing the context before returning from the callback

// @ts-expect-error this function is not exposed
// See: https://github.com/gjsify/ts-for-gir/issues/194
cr.$dispose();
});

Expand Down

0 comments on commit 5d7fe6e

Please sign in to comment.