Skip to content

ahgilak/deno_gi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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