logo
pub trait Global<'a, Component> {
    fn get(component: &'a Component) -> Self;
}
Expand description

This trait is used to obtain references to global singletons exported in .slint markup. Alternatively, you can use ComponentHandle::global to obtain access.

This trait is implemented by the compiler for each global singleton that’s exported.

Example

The following example of .slint markup defines a global singleton called Palette, exports it and modifies it from Rust code:

slint::slint!{
export global Palette := {
    property<color> foreground-color;
    property<color> background-color;
}

export App := Window {
   background: Palette.background-color;
   Text {
      text: "Hello";
      color: Palette.foreground-color;
   }
   // ...
}
}
let app = App::new();
app.global::<Palette>().set_background_color(slint::Color::from_rgb_u8(0, 0, 0));

// alternate way to access the global singleton:
Palette::get(&app).set_foreground_color(slint::Color::from_rgb_u8(255, 255, 255));

See also the language reference for global singletons for more information.

Note: Only globals that are exported or re-exported from the main .slint file will be exposed in the API

Required Methods

Returns a reference that’s tied to the life time of the provided component.

Implementors