Crate coop

source ·
Expand description

§coop

coop is a custom widget and component library for Slint with a custom simple, consistence and clean design.

§How to use

First of all you have to add coop and slint as dependency to the Cargo.toml file of your project and slint-build as build dependency.

§Cargo.toml

[package]
...
build = "build.rs"
edition = "2021"

[dependencies]
slint = { version = "1.6" }
coop = "0.1.0"
...

[build-dependencies]
slint-build = { version = "1.6" }

As next use the API of the slint-build crate in the build.rs file and coop to include the import paths.

§build.rs

fn main() {
  slint_build::compile_with_config(
         "ui/hello.slint",
         slint_build::CompilerConfiguration::new().with_library_paths(coop::import_paths()),
     )
     .unwrap();
}

coop can now be used inside of your Slint files:

§hello.slint

import { VerticalBox, FilledButton } from "@coop/pure.slint";

export component HelloWorld inherits Window {
    VerticalBox {
        FilledButton {
            text: "Click Me";
            clicked => { self.text = "Hello World"; }
        }
   }
}

Finally, use the [include_modules!] macro in your main.rs:

§main.rs

slint::include_modules!();
fn main() {
    HelloWorld::new().unwrap().run().unwrap();
}

Functions§

  • Provides the coop library paths used by slint-build to make them accessible through @coop in Slint.