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 := {
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().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.