You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to invoke a global callback from rust and handling it in slint. Using component callbacks works fine, but I did not find any documentation doing it for global callbacks.
The idea is to have a global callback in the Settings namespace. This global callback can be called from rust with invoke_global_callback_invoked_from_rust(). In slint I wanna react on the call with something like
Is there a way to react on global callback invokations from rust?
Invoking component callback from rust and handling in slint
Invoking component callback from slint and handling in rust
Invoking global callback from rust and handling in slint
Invoking global callback from slint and handling in rust
Setting global property from rust and slint component properties change
lib.rs
use std::error::Error;
slint::include_modules!();pubfnapp() -> Result<(),Box<dynError>>{let ui = AppWindow::new()?;// Invoking a global callback from rust. Slint components shall react on it
ui.global::<Settings>().invoke_global_callback_invoked_from_rust("Invoked a global callback from rust".into());// Invoking a component callback works fine
ui.invoke_test_input_from_rust("Invoked a component callback from rust.".into());
ui.on_component_callback({let ui_handle = ui.as_weak();move || {let ui = ui_handle.unwrap();// Setting a global property works fine
ui.global::<Settings>().set_text("Globally property changed from rust from the component callback".into());}});// Callback handler from the global. Will be triggered when in slint the global callback gets executed
ui.global::<Settings>().on_global_callback_invoked_from_slint({let ui_handle = ui.as_weak();move || {let ui = ui_handle.unwrap();
ui.global::<Settings>().set_text("Globally property changed from rust from the global callback".into());}});
ui.run()?;Ok(())}
mainwin.slint
import { Button, VerticalBox } from"std-widgets.slint";
// Exporting the global again from the main slint file to be able to access it from rustexport { Settings } from"settings.slint";
// Import to access from the AppWindow componentimport { Settings } from"settings.slint";
exportcomponentAppWindowinheritsWindow {
property<string> text: "No component callback invoke triggered from rust";
property<string> text2: "No global callback invoke triggered from rust";
callbackcomponent_callback(); // Implemented in rust// Invoked in the rust codecallbacktest_input_from_rust(string);
test_input_from_rust(input) => {
text = input;
}
// // Does not work yet!// Settings.global_callback_invoked_from_rust => {// text2 = input;// }VerticalBox {
Text { text: root.text; }
Text { text: root.text2; }
Text { text: Settings.text; }
// Trigger component callback implemented in rust// In rust we change the global property `Settings.text`// Which will trigger a change of the TextLabel textButton {
text: "Invoke component callback";
clicked => {
root.component_callback();
}
}
// Trigger global callback implemented in rustButton {
text: "Invoke global settings callback";
clicked => {
Settings.global_callback_invoked_from_slint();
}
}
}
}
settings.slint
exportglobalSettings {
callbackglobal_callback_invoked_from_slint();
callbackglobal_callback_invoked_from_rust(t: string);
// When this property is set in rust, the// property of some components changesinproperty<string> text: "No callback triggered. Click one of the buttons below";
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am trying to invoke a global callback from rust and handling it in slint. Using component callbacks works fine, but I did not find any documentation doing it for global callbacks.
The idea is to have a global callback in the
Settings
namespace. This global callback can be called from rust withinvoke_global_callback_invoked_from_rust()
. In slint I wanna react on the call with something likeSettings.global_callback_invoked_from_rust => { ... }
Is there a way to react on global callback invokations from rust?
lib.rs
mainwin.slint
settings.slint
Beta Was this translation helpful? Give feedback.
All reactions