slint-ui / slint

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

Js: a slint´...´ template function #4480

Open ogoffart opened 8 months ago

ogoffart commented 8 months ago

Imagine:

import * as slint from "npm:slint-ui";
let demo = slint`
    import { AboutSlint } from "std-widgets.slint";
    export component Demo inherits Window { AboutSlint {} } 
`.Demo();
demo.show();
await slint.runEventLoop();

slint could be a tagged template that just calls loadSource Is it possible to have it both as a tagged template and as a "namespace" with the runEventLoop and other classes and interface?

Also we can extend the LSP and language to also highlight code in a slint` template the same way we highlight inside a rust macro. (Grep for extract_rust_macro and see slint.injections.json)

tronical commented 8 months ago

Is it possible to have it both as a tagged template and as a "namespace" with the runEventLoop and other classes and interface?

I don't believe that is possible. It would have to be

import { slint }, * as the_rest from "slint-ui";
let instance = slint`...`;

I thought about this but I'm not sure anymore it's really worth the "convenience", for two reasons:

If we want to have a way of creating a component instance from just a string, why don't we use a regular function?

let instance = slint.createInstanceFromString(export component App { ... });