Skip to content

access & use a global in a closure? #7400

Closed Answered by ogoffart
Gibbz asked this question in Q&A
Discussion options

You must be logged in to vote
      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 [Point]

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 = keyboa…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Gibbz
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants