Skip to content

Deno Window Manager: Cross-platform window creation and management

License

Notifications You must be signed in to change notification settings

deno-windowing/dwm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deno Window Manager

Tags Doc Checks License Sponsor

Cross-platform window management library for Deno.

Example

Creating an OpenGL Window

import {
  createWindow,
  getProcAddress,
  mainloop,
} from "jsr:@gfx/dwm";
import * as gl from "https://deno.land/x/gluten@0.1.3/api/gles23.2.ts";

const window = createWindow({
  title: "DenoGL",
  width: 800,
  height: 600,
  resizable: true,
  glVersion: "v3.2",
  gles: true,
});

gl.load(getProcAddress);

addEventListener("resize", (event) => {
  gl.Viewport(0, 0, event.width, event.height);
});

gl.ClearColor(0.0, 0.0, 0.0, 1.0);

function frame() {
  gl.Clear(gl.COLOR_BUFFER_BIT);
  window.swapBuffers();
}

await mainloop(frame);

Creating a Skia Canvas Window

import {
  mainloop,
  WindowCanvas,
} from "jsr:@gfx/dwm/ext/canvas";

const canvas = new WindowCanvas({
  title: "Skia Canvas",
  width: 800,
  height: 600,
  resizable: true,
});

canvas.onDraw = (ctx) => {
  ctx.fillStyle = "black";
  ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  ctx.fillStyle = "white";
  ctx.font = "30px Arial";
  ctx.textBaseline = "top";
  ctx.fillText("Hello World", 10, 10);
};

await mainloop(() => {
  canvas.draw();
});

See examples for more examples!

Usage

For drawing, you can use:

Since this module depends on unstable FFI API, you need to pass --unstable along with --allow-ffi, --allow-write and --allow-env.

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

Maintainers

License

Apache-2.0 licensed.

Copyright 2024 © The Deno Windowing Team