1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
// SPDX-FileCopyrightText: 2024 vivi developers <vivi-ui@tuta.io>
// SPDX-License-Identifier: MIT
/*!
* # vivi
*
* `vivi` is a custom component library for [Slint](https://slint.dev/).
*
* ## How to use
*
* First of all you have to add slint` as dependency to the `Cargo.toml` file of your project and `vivi` and slint-build` as build
* dependency.
*
* ### Cargo.toml
*
* ```toml
* [package]
* ...
* build = "build.rs"
* edition = "2021"
*
* [dependencies]
* slint = { version = "1.6" }
* ...
*
* [build-dependencies]
* slint-build = { version = "1.6" }
* vivi_ui = "0.1.0"
* ```
* As next use the API of the slint-build crate in the `build.rs` file and vivi to include the import paths.
*
* ### build.rs
*
* ```ignore
* fn main() {
* slint_build::compile_with_config(
* "ui/index.slint",
* slint_build::CompilerConfiguration::new().with_library_paths(vivi_ui::import_paths()),
* )
* .unwrap();
* }
* ```
*
* `vivi` can now be used inside of your Slint files:
*
* ### index.slint
*
* ```slint
* import { MagicVerticalBox, FilledButton } from "@vivi/magic.slint";
*
* export component HelloWorld inherits Window {
* MagicVerticalBox {
* FilledButton {
* text: "Click Me";
* clicked => { self.text = "Hello World"; }
* }
* }
* }
* ````
*
* Finally, use the [`include_modules!`] macro in your `main.rs`:
*
* ### main.rs
*
* ```ignore
* slint::include_modules!();
* fn main() {
* HelloWorld::new().unwrap().run().unwrap();
* }
* ```
*
*/
use std::env;
use std::path::PathBuf;
use std::collections::HashMap;
const LIB_NAME: &str = "vivi";
/// Provides the `vivi` library paths used by slint-build to make them accessible through `@vivi` in Slint.
///
/// ```ignore
/// fn main() {
/// slint_build::compile_with_config(
/// "ui/index.slint",
/// slint_build::CompilerConfiguration::new().with_library_paths(vivi::import_paths()),
/// )
/// .unwrap();
/// }
/// ```
///
/// Import `vivi` library in `ui/main.slint`
///
/// ```slint
/// import { FilledButton } from "@vivi/magic.slint";
/// ````
pub fn import_paths() -> HashMap<String, PathBuf> {
let mut import_paths = HashMap::new();
let ui_lib_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("ui");
import_paths.insert(LIB_NAME.to_string(), ui_lib_path);
import_paths
}