slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.95k stars 568 forks source link

Deno API #1992

Closed ogoffart closed 2 weeks ago

ogoffart commented 1 year ago

With the new napi based node Slint port it is now possible to use Slint with deno e.g. by using the slint-ui npm package.

Example

import * as slint from "npm:slint-ui@1.3.2";

const ui = slint.loadFile(".ui/main_window.slint") as any;
const mainWindow = new ui.MainWindow();

await mainWindow.run();

A complex example of using Slint with Deno can be found at https://codeberg.org/flovansl/co_sl/src/branch/main/apps/coop_local/deno.

The Slint support for Deno can be improved further following these steps:

originally description Expose the Slint API for Deno.

( originates from https://github.com/slint-ui/slint/discussions/1969 )

sigmaSd commented 1 year ago

Just some general notes, for ffi deno can call into dynamic lib with Deno.dlopen

There are libraries that makes the downloading and caching of the dynamic library automatic for the user https://github.com/denosaurs/plug is the most used

There also higher level wrappers https://github.com/denoland/deno_bindgen

sigmaSd commented 8 months ago

After this pr have landed https://github.com/slint-ui/slint/pull/4357

deno seems to work now with its npm compat (I haven't tested much)

a.ts

import * as slint from "npm:slint-ui@1.4.0-nightly.202411718";

let ui = slint.loadFile("main.slint");
let demo = new ui.Demo();

await demo.run();

main.slint

import { AboutSlint, Button, VerticalBox } from "std-widgets.slint";
export component Demo {
    in-out property <string> greeting <=> label.text;
    VerticalBox {
        alignment: start;
        label := Text {
            text: "Hello World!";
            font-size: 24px;
            horizontal-alignment: center;
        }
        AboutSlint {
            preferred-height: 150px;
        }
        HorizontalLayout { alignment: center; Button { text: "OK!"; } }
    }
}

deno run --allow-read --allow-ffi --allow-sys a.ts

omarcosr commented 8 months ago

I didn't find a way to compile with deno or node, is there an example?

hunger commented 8 months ago

@omarcosr: If I understood #1991 correctly, then you should be able to just use binaries now. The issue includes a little deno example that reportedly does just that.

FloVanGH commented 2 weeks ago

We do not plan to implement a pure deno port in the near future. But it is already possible to use Slint with deno through the npm module. How to use the npm module also from deno is documented.

I close this now, but if we plan to do a deno port in the future the issue can be reopened.