pub trait Global<'a, Component> {
// Required method
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 {
in property<color> foreground-color;
in property<color> background-color;
}
export component App inherits Window {
background: Palette.background-color;
Text {
text: "Hello";
color: Palette.foreground-color;
}
// ...
}
}
let app = App::new().unwrap();
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 documentation 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§
fn get(component: &'a Component) -> Self
fn get(component: &'a Component) -> Self
Returns a reference that’s tied to the life time of the provided component.
Object Safety§
This trait is not object safe.