ahgilak / deno_gi

Deno port of Gnome libraries (such as Gtk).
https://deno.land/x/deno_gi
33 stars 2 forks source link
deno gobject-introspection gtk

Deno GI

Deno port of Gnome libraries (such as Gtk).

Early Stage and Unstable

Usage

You must specify --allow-ffi and --unstable-ffi flags to run your program.

deno run --allow-ffi --unstable-ffi <file>

Loading a library

Import libraries from gir.deno.dev to load them.

Loading Gtk:

import Gtk from "https://gir.deno.dev/Gtk-4.0";

Creating Objects

Objects are initialized using creation functions or javascript constructors.

Creating a GtkButton:

const button = Gtk.Button.new_with_label("Click Me!");

or

const button = new Gtk.Button({ label: "Click Me!" });

Signals

Signals are connected using on method.

Connecting clicked signal to a button:

button.connect("clicked", () => {
  console.log("Clicked");
});

Example

import Gtk from "https://gir.deno.dev/Gtk-4.0";

const app = new Gtk.Application();

app.connect("activate", () => {
  const win = new Gtk.ApplicationWindow({ application: app });
  const contentArea = new Gtk.Box();
  const label = new Gtk.Label({ label: "Hello World!" });

  contentArea.append(label);
  win.set_child(contentArea);
  win.present();
});

app.run([]);

See more examples on examples folder.

Dependencies

Deno GI depends on gobject-introspection.

Fedora

dnf install gobject-introspection

Ubuntu

apt install gobject-introspection

Arch

pacman -S gobject-introspection

macOS

brew install gobject-introspection

Windows

  1. Install MSYS2.
  2. Add C:\msys64\mingw64\bin to system path.
  3. Run in msys shell:
pacman -S mingw-w64-x86_64-gobject-introspection

Additional libraries such as gtk4 and libadwaita are used in examples. Their installation process is the same as gobject-introspection.

Related Projects