diff --git a/Cargo.toml b/Cargo.toml index c7676958e1c..c144969a855 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ 'docs/reference/src/quickstart', 'examples/7guis', 'examples/gallery', + 'examples/material-gallery', 'examples/imagefilter/rust', 'examples/maps', 'examples/memory', @@ -70,7 +71,7 @@ members = [ default-members = [ 'api/rs/build', 'api/rs/slint', - 'examples/gallery', + 'examples/material-gallery', 'examples/memory', 'examples/printerdemo_old/rust', 'examples/printerdemo/rust', diff --git a/api/node/__test__/compiler.spec.mts b/api/node/__test__/compiler.spec.mts index 62b68b86e45..857a4e5cec6 100644 --- a/api/node/__test__/compiler.spec.mts +++ b/api/node/__test__/compiler.spec.mts @@ -27,10 +27,11 @@ test("get/set library paths", (t) => { libdir: "third_party/libbar/ui/", }; - t.deepEqual(compiler.libraryPaths, { - "libfile.slint": "third_party/libfoo/ui/lib.slint", - libdir: "third_party/libbar/ui/", - }); + t.deepEqual( + compiler.libraryPaths["libfile.slint"], + "third_party/libfoo/ui/lib.slint", + ); + t.deepEqual(compiler.libraryPaths.libdir, "third_party/libbar/ui/"); }); test("get/set style", (t) => { diff --git a/examples/material-gallery/Cargo.toml b/examples/material-gallery/Cargo.toml new file mode 100644 index 00000000000..b35df64a250 --- /dev/null +++ b/examples/material-gallery/Cargo.toml @@ -0,0 +1,42 @@ +# Copyright © SixtyFPS GmbH +# SPDX-License-Identifier: MIT + +[package] +name = "material-gallery" +version = "1.9.0" +authors = ["Slint Developers "] +edition = "2021" +build = "build.rs" +license = "MIT" +publish = false +description = "Slint Widgets Gallery Example" + +[[bin]] +path = "src/main.rs" +name = "material-gallery" + +[dependencies] +slint = { path = "../../api/rs/slint" } + +# Disable gettext on macOS due to https://github.com/Koka/gettext-rs/issues/114 +[target.'cfg(not(target_os = "macos"))'.dependencies] +slint = { path = "../../api/rs/slint", features=["gettext"] } + +[build-dependencies] +slint-build = { path = "../../api/rs/build" } + +# Remove the `#wasm#` to uncomment the wasm build. +# This is commented out by default because we don't want to build it as a library by default +# The CI has a script that does sed "s/#wasm# //" to generate the wasm build. + +#wasm# [lib] +#wasm# crate-type = ["cdylib"] +#wasm# path = "main.rs" +#wasm# +#wasm# [target.'cfg(target_arch = "wasm32")'.dependencies] +#wasm# wasm-bindgen = { version = "0.2" } +#wasm# web-sys = { version = "0.3", features=["console"] } +#wasm# console_error_panic_hook = "0.1.5" + +[package.metadata.bundle] +identifier = "com.slint.examples.material-gallery" diff --git a/examples/material-gallery/build.rs b/examples/material-gallery/build.rs new file mode 100644 index 00000000000..f93082aca2f --- /dev/null +++ b/examples/material-gallery/build.rs @@ -0,0 +1,6 @@ +// Copyright © SixtyFPS GmbH +// SPDX-License-Identifier: MIT + +fn main() { + slint_build::compile("ui/index.slint").unwrap(); +} diff --git a/examples/material-gallery/src/main.rs b/examples/material-gallery/src/main.rs new file mode 100644 index 00000000000..985ea7155e1 --- /dev/null +++ b/examples/material-gallery/src/main.rs @@ -0,0 +1,16 @@ +#[cfg(target_arch = "wasm32")] +// Copyright © SixtyFPS GmbH +// SPDX-License-Identifier: MIT +use wasm_bindgen::prelude::*; + +slint::include_modules!(); + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))] +pub fn main() { + // This provides better error messages in debug mode. + // It's disabled in release mode so it doesn't bloat up the file size. + #[cfg(all(debug_assertions, target_arch = "wasm32"))] + console_error_panic_hook::set_once(); + + MaterialGallery::new().unwrap().run().unwrap(); +} diff --git a/examples/material-gallery/ui/index.slint b/examples/material-gallery/ui/index.slint new file mode 100644 index 00000000000..a389652f328 --- /dev/null +++ b/examples/material-gallery/ui/index.slint @@ -0,0 +1,11 @@ +// Copyright © SixtyFPS GmbH +// SPDX-License-Identifier: MIT + +import { FilledButton } from "@slint/material.slint"; + +export component MaterialGallery inherits Window { + preferred-width: 600px; + preferred-height: 400px; + + FilledButton { } +} \ No newline at end of file diff --git a/internal/compiler/build.rs b/internal/compiler/build.rs index 844525ed191..1fb05af7c5c 100644 --- a/internal/compiler/build.rs +++ b/internal/compiler/build.rs @@ -42,6 +42,11 @@ fn widget_library() -> &'static [(&'static str, &'static BuiltinDirectory<'stati println!("cargo:rustc-env=SLINT_WIDGETS_LIBRARY={}", output_file_path.display()); + let mut slint_dir = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap()); + slint_dir.push("components"); + + println!("cargo:rustc-env=SLINT_COMPONENTS_LIBRARY={}", slint_dir.display()); + Ok(()) } diff --git a/internal/compiler/components/headless.slint b/internal/compiler/components/headless.slint new file mode 100644 index 00000000000..811a56c206f --- /dev/null +++ b/internal/compiler/components/headless.slint @@ -0,0 +1,4 @@ +// Copyright © SixtyFPS GmbH +// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 + +export { ButtonBase } from "headless/button-base.slint"; \ No newline at end of file diff --git a/internal/compiler/components/headless/button-base.slint b/internal/compiler/components/headless/button-base.slint new file mode 100644 index 00000000000..c48c4215f70 --- /dev/null +++ b/internal/compiler/components/headless/button-base.slint @@ -0,0 +1,10 @@ +// Copyright © SixtyFPS GmbH +// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 + +export component ButtonBase { + callback clicked <=> touch-area.clicked; + + touch-area := TouchArea {} + + @children +} diff --git a/internal/compiler/components/material.slint b/internal/compiler/components/material.slint new file mode 100644 index 00000000000..5138d73e423 --- /dev/null +++ b/internal/compiler/components/material.slint @@ -0,0 +1,4 @@ +// Copyright © SixtyFPS GmbH +// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 + +export { FilledButton } from "material/filled-button.slint"; \ No newline at end of file diff --git a/internal/compiler/components/material/filled-button.slint b/internal/compiler/components/material/filled-button.slint new file mode 100644 index 00000000000..68b40f3191a --- /dev/null +++ b/internal/compiler/components/material/filled-button.slint @@ -0,0 +1,6 @@ +// Copyright © SixtyFPS GmbH +// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 + +import { ButtonBase } from "@slint/headless.slint"; + +export component FilledButton inherits ButtonBase { } \ No newline at end of file diff --git a/internal/compiler/lib.rs b/internal/compiler/lib.rs index 776846ef2eb..8d5cdffec32 100644 --- a/internal/compiler/lib.rs +++ b/internal/compiler/lib.rs @@ -38,7 +38,7 @@ pub mod typeregister; pub mod passes; use crate::generator::OutputFormat; -use std::path::Path; +use std::path::{Path, PathBuf}; /// Specify how the resources are embedded by the compiler #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -199,10 +199,13 @@ impl CompilerConfiguration { _ => None, }; + let mut library_paths = HashMap::new(); + library_paths.insert("slint".to_string(), PathBuf::from(env!("SLINT_COMPONENTS_LIBRARY"))); + Self { embed_resources, include_paths: Default::default(), - library_paths: Default::default(), + library_paths, style: Default::default(), open_import_fallback: None, resource_url_mapper: None, diff --git a/internal/interpreter/api.rs b/internal/interpreter/api.rs index a0bd4a76e25..3bc77ef0135 100644 --- a/internal/interpreter/api.rs +++ b/internal/interpreter/api.rs @@ -694,7 +694,7 @@ impl Compiler { /// Sets the library paths used for looking up `@library` imports to the specified map of library names to paths. pub fn set_library_paths(&mut self, library_paths: HashMap) { - self.config.library_paths = library_paths; + self.config.library_paths.extend(library_paths); } /// Returns the library paths the component compiler is currently configured with.