Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

material: base setup components import #6497

Open
wants to merge 6 commits into
base: feature/material
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
'docs/reference/src/quickstart',
'examples/7guis',
'examples/gallery',
'examples/material-gallery',
'examples/imagefilter/rust',
'examples/maps',
'examples/memory',
Expand Down Expand Up @@ -70,7 +71,7 @@ members = [
default-members = [
'api/rs/build',
'api/rs/slint',
'examples/gallery',
'examples/material-gallery',
Comment on lines -73 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to change the default really? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, thanks

'examples/memory',
'examples/printerdemo_old/rust',
'examples/printerdemo/rust',
Expand Down
9 changes: 5 additions & 4 deletions api/node/__test__/compiler.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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/");
Comment on lines -30 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this can be un-done if you separate the fields (see comment further below).

});

test("get/set style", (t) => {
Expand Down
42 changes: 42 additions & 0 deletions examples/material-gallery/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright © SixtyFPS GmbH <[email protected]>
# SPDX-License-Identifier: MIT

[package]
name = "material-gallery"
version = "1.9.0"
authors = ["Slint Developers <[email protected]>"]
edition = "2021"
build = "build.rs"
license = "MIT"
publish = false
description = "Slint Widgets Gallery Example"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Slint Material Widgets Gallery Example"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure


[[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"
6 changes: 6 additions & 0 deletions examples/material-gallery/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: MIT

fn main() {
slint_build::compile("ui/index.slint").unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have main.slint, app-window.slint, index.slint - it would really be nice to reduce that set eventually :).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I will change it.

}
16 changes: 16 additions & 0 deletions examples/material-gallery/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[cfg(target_arch = "wasm32")]
// Copyright © SixtyFPS GmbH <[email protected]>
// 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();
}
11 changes: 11 additions & 0 deletions examples/material-gallery/ui/index.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: MIT

import { FilledButton } from "@slint/material.slint";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can bike shed about this later, but I think we should offer a library as full encapsulated (so @my-library) instead of also exposing file paths. That's just asking to access internal .slint files and end up with accidental public API.

I'd go with something like @slint/material-widgets/1 or so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of .slint because we are doing the same with the std-widgets. But I see not problem to do it without to file extension


export component MaterialGallery inherits Window {
preferred-width: 600px;
preferred-height: 400px;

FilledButton { }
}
5 changes: 5 additions & 0 deletions internal/compiler/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Comment on lines +45 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an issue with this, which is that it doesn't work when the slint-compiler is used from Node.js, C++, or WASM, or the LSP. In those cases the directory doesn't exist like that anymore. That's why the compiler ships the widgets built-in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes true. OK then I need to handle this like the std-widgets


println!("cargo:rustc-env=SLINT_COMPONENTS_LIBRARY={}", slint_dir.display());

Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/components/headless.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// 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";
10 changes: 10 additions & 0 deletions internal/compiler/components/headless/button-base.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// 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
}
4 changes: 4 additions & 0 deletions internal/compiler/components/material.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// 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";
6 changes: 6 additions & 0 deletions internal/compiler/components/material/filled-button.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// 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 { }
7 changes: 5 additions & 2 deletions internal/compiler/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/interpreter/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, PathBuf>) {
self.config.library_paths = library_paths;
self.config.library_paths.extend(library_paths);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not quite right. What if the developer calls set_library_paths twice? That should replace the previous call, shouldn't it?

I think the builtin library mapping may need to be a separate field within the compiler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what I am reference in my comment below ;-)

}

/// Returns the library paths the component compiler is currently configured with.
Expand Down
Loading