Skip to content

Commit b27b8fe

Browse files
committed
doc: Document how to use slint libraries with Python & NodeJS
... and added examples to all, including C++ and Rust.
1 parent 3b15d18 commit b27b8fe

File tree

1 file changed

+60
-3
lines changed
  • docs/astro/src/content/docs/guide/language/coding

1 file changed

+60
-3
lines changed

docs/astro/src/content/docs/guide/language/coding/file.mdx

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description: The `.slint` File
88
import CodeSnippetMD from '@slint/common-files/src/components/CodeSnippetMD.astro';
99
import Link from '@slint/common-files/src/components/Link.astro';
1010
import LangRefLink from '@slint/common-files/src/components/LangRefLink.astro';
11+
import { Tabs, TabItem } from '@astrojs/starlight/components';
1112

1213

1314
You write user interfaces in the Slint language and saved in files with the `.slint` extension.
@@ -343,9 +344,65 @@ The path to each library, as file or directory, must be defined separately at co
343344
Use one of the following methods to help the Slint compiler resolve libraries to the correct
344345
path on disk:
345346

346-
* When using Rust and `build.rs`, call <LangRefLink lang="rust-slint-build" relpath="struct.CompilerConfiguration#method.with_library_paths">`with_library_paths`</LangRefLink>
347-
to provide a mapping from library name to path.
348-
* When using C++, use `LIBRARY_PATHS` with <LangRefLink lang="cpp" relpath="cmake_reference#slint-target-sources">`slint_target_sources`</LangRefLink>.
347+
<Tabs syncKey="dev-language">
348+
<TabItem label="C++">
349+
* Specify `LIBRARY_PATHS` with <LangRefLink lang="cpp" relpath="cmake_reference#slint-target-sources">`slint_target_sources`</LangRefLink>. For example:
350+
351+
```cmake
352+
slint_target_sources(my_application
353+
ui/main.slint
354+
LIBRARY_PATHS
355+
material=${CMAKE_CURRENT_SOURCE_DIR}/material-1.0/material.slint
356+
)
357+
```
358+
359+
</TabItem>
360+
<TabItem label="Rust">
361+
* In `build.rs`, call <LangRefLink lang="rust-slint-build" relpath="struct.CompilerConfiguration#method.with_library_paths">`with_library_paths`</LangRefLink>
362+
to provide a mapping from library name to path. For example:
363+
364+
```rust
365+
// build.rs
366+
fn main() {
367+
let manifest_dir = std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap());
368+
let library_paths = std::collections::HashMap::from([(
369+
"example".to_string(),
370+
manifest_dir.join("third_party/example/ui/lib.slint"),
371+
)]);
372+
let config = slint_build::CompilerConfiguration::new().with_library_paths(library_paths);
373+
slint_build::compile_with_config("ui/main.slint", config).unwrap();
374+
}
375+
```
376+
377+
</TabItem>
378+
<TabItem label="NodeJS">
379+
* Provide the `libraryPaths` map with <LangRefLink lang="nodejs" relpath="functions/loadFile">`loadFile`</LangRefLink> in `LoadFileOptions`. For example:
380+
381+
```javascript
382+
let ui = slint.loadFile("/path/to/main.slint", {
383+
libraryPaths: {
384+
"material": "/path/to/material-1.0/material.slint"
385+
}
386+
});
387+
```
388+
389+
</TabItem>
390+
<TabItem label="Python">
391+
* Provide the `library_paths` dict with <LangRefLink lang="python" relpath="slint#load_file">`load_file`</LangRefLink>. For example:
392+
393+
```python
394+
ui = slint.load_file(
395+
"/path/to/main.slint",
396+
library_paths={
397+
"material": "/path/to/material-1.0/material.slint"
398+
},
399+
)
400+
```
401+
402+
</TabItem>
403+
</Tabs>
404+
405+
349406
* When invoking the `slint-viewer` from the command line, pass `-Lmylibrary=/path/to/my/library` for each component
350407
library.
351408
* When using the VS Code extension, configure the Slint extension's library path

0 commit comments

Comments
 (0)