-
I have a keyboard handler which is a global in my slint file. Im trying to store an array of points in there. I figured i should store my data on the slint side, and have my functions on the rust side.
slint
rust let ui_weak = ui.as_weak();
let keyboard_handler = ui.global::<VirtualKeyboardHandler>();
//let keyboard_handler_weak = keyboard_handler.as_weak(); // <- this doesnt work
keyboard_handler.on_mouse_moved(|x: f32, y: f32| {
let point = LogicalPosition::new(x, y);
let array = keyboard_handler.get_mouse_position_history();
keyboard_handler.set_mouse_position_history(array);
info!("{}, {}", x, y);
}); errors:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
in-out property <[[Point]]> mouse_position_history; // <- is this correct for an array of points(x,y)?? That is an array of array of point. An array of point would just be For your rust error, you need to move the ui_weak in the closur and yhen you can call global again let ui_weak = ui.as_weak();
let keyboard_handler = ui.global::<VirtualKeyboardHandler>();
// added `move`
keyboard_handler.on_mouse_moved(move |x: f32, y: f32| {
// use ui_weak to access the keyboard_handler
let ui = ui_weak.unwrap();
let keyboard_handler = ui.global::<VirtualKeyboardHandler>();
let point = LogicalPosition::new(x, y);
let array = keyboard_handler.get_mouse_position_history();
keyboard_handler.set_mouse_position_history(array);
info!("{}, {}", x, y);
}); |
Beta Was this translation helpful? Give feedback.
-
Thanks! Ive got the assigning working also. Heres the full code for anyone else looking for how to do this: // Create an empty VecModel and put it in an Rc, convert to ModelRc and assign
let the_model : Rc<VecModel<LogicalPosition>> = Rc::new(VecModel::default());
let the_model_rc = ModelRc::from(the_model.clone());
keyboard_handler.set_mouse_position_history(the_model_rc);
// callback
keyboard_handler.on_mouse_moved({
let ui_weak = ui.as_weak();
move |x: f32, y: f32| {
let ui= ui_weak.unwrap();
let keyboard_handler = ui.global::<VirtualKeyboardHandler>();
let point = LogicalPosition::new(x, y);
the_model.push(point);
let the_model_rc = ModelRc::from(the_model.clone());
keyboard_handler.set_mouse_position_history(the_model_rc);
info!("{}, {}", x, y);
}
}); |
Beta Was this translation helpful? Give feedback.
That is an array of array of point. An array of point would just be
[Point]
For your rust error, you need to move the ui_weak in the closur and yhen you can call global again