lucide_slint/lib.rs
1//! <p align="center">
2//! <a href="https://github.com/cnlancehu/lucide-slint">
3//! <img src="https://github.com/cnlancehu/lucide-slint/raw/main/assets/logo-dark.svg" width="600">
4//! </a>
5//! </p>
6//!
7//! # Lucide Slint
8//! Implementation of the [lucide icon library](https://github.com/lucide-icons/lucide) for Slint.
9//!
10//! # Installation
11//! In an existing Slint project, run the following command to add lucide-slint as a **build** dependency:
12//!
13//! ```bash
14//! cargo add lucide-slint --build
15//! ```
16//!
17//! Add the following to your `build.rs` file to import `lucide-slint` as a Slint library:
18//!
19//! ```rust
20//! use std::{collections::HashMap, path::PathBuf};
21//!
22//! fn main() {
23//! let library = HashMap::from([(
24//! "lucide".to_string(),
25//! PathBuf::from(lucide_slint::get_slint_file_path().to_string()),
26//! )]);
27//! let config = slint_build::CompilerConfiguration::new().with_library_paths(library);
28//!
29//! // Specify your Slint code entry here
30//! slint_build::compile_with_config("ui/main.slint", config).expect("Slint build failed");
31//! }
32//! ```
33//!
34//! # Usage
35//! Then you can use lucide icons in your Slint files like this:
36//!
37//! ```slint
38//! import { PlayIcon } from "@lucide";
39//!
40//! export component App inherits Window {
41//! VerticalBox {
42//! PlayIcon {
43//! size: 24px;
44//! colorize: #fff;
45//! }
46//! }
47//! }
48//! ```
49//!
50//! The Icon component inherits an [`Image element`](https://docs.slint.dev/latest/docs/slint/reference/elements/image/), so you can set properties like `vertical-tiling`, `width`, etc.
51//!
52//! ```slint
53//! import { FlowerIcon } from "@lucide";
54//!
55//! FlowerIcon {
56//! size: 36px;
57//! width: 100%;
58//! height: 100%;
59//! opacity: 0.7;
60//! vertical-tiling: round;
61//! horizontal-tiling: round;
62//! }
63//! ```
64//!
65//! Or if you just want to use the raw [image](https://docs.slint.dev/latest/docs/slint/reference/primitive-types/#image) data, you can access the icon via `Icons`:
66//!
67//! ```slint
68//! import { Icons } from "@lucide";
69//!
70//! Button {
71//! text: "Back";
72//! icon: Icons.ArrowLeftIcon;
73//! colorize-icon: true;
74//! }
75//!
76//! // equivalent to
77//! Button {
78//! text: "Back";
79//! icon: @image-url("icons/arrow-left.svg"); // The path is actually relative to the lucide-slint package, use `Icons.ArrowLeftIcon` instead.
80//! colorize-icon: true;
81//! }
82//! ```
83//!
84//! # Available Icons
85//!
86//! For a complete list of available icons, visit the [Lucide Icons](https://lucide.dev/icons/) website.
87//!
88//! To use an icon in Slint:
89//! 1. Find your desired icon (e.g., `a-arrow-down`)
90//! 2. Click **Copy Component Name** to get the PascalCase name (e.g., `AArrowDown`)
91//! 
92//! 3. Append `Icon` to the component name: `AArrowDownIcon`
93//!
94//! **Example:**
95//!
96//! ```slint
97//! import { AArrowDownIcon } from "@lucide";
98//!
99//! AArrowDownIcon { }
100//! ```
101
102/// Returns the file path to the `lib.slint` file included in this crate.
103///
104/// ## Example in `build.rs`
105///
106/// ```rust
107/// use std::{collections::HashMap, path::PathBuf};
108///
109/// fn main() {
110/// let library = HashMap::from([(
111/// "lucide".to_string(),
112/// PathBuf::from(lucide_slint::get_slint_file_path().to_string()),
113/// )]);
114/// let config = slint_build::CompilerConfiguration::new().with_library_paths(library);
115///
116/// // Specify your Slint code entry here
117/// slint_build::compile_with_config("ui/main.slint", config).expect("Slint build failed");
118/// }
119/// ```
120pub fn get_slint_file_path() -> &'static str {
121 concat!(env!("CARGO_MANIFEST_DIR"), "/lib.slint")
122}