简体   繁体   中英

How do you register a PointerPressed event handler for a CoreApp in the Rust Crate for Windows?

E0277 The trait IntoParam TypeEventHandler<CoreWindow, PointerEventArgs> bound is not satisfied error message

fn SetWindow(&mut self, window: &Option<CoreWindow>) -> Result<()> {
    let compositor = Compositor::new()?;
    let root = compositor.CreateContainerVisual()?;
    self.target = Some(compositor.CreateTargetForCurrentView()?);
    self.target.as_ref().unwrap().SetRoot(&root)?; // &root
    self.visuals = Some(root.Children()?);
    //window.unwrap().PointerPressed(handler: Param0)?;
    window.unwrap().PointerPressed(Self::OnPointerPressed)?;
    Ok(())
}

fn OnPointerPressed(win: CoreWindow, pea: PointerEventArgs) {
    //...
}

The above code now builds with the following edits to the end of the SetWindow function and the OnPointerPressed function:

    window.as_ref().unwrap().PointerPressed(
        TypedEventHandler::new(Self::OnPointerPressed))?;
    Ok(())
}

fn OnPointerPressed(_: &Option<CoreWindow>,
    args: &Option<PointerEventArgs>)
    -> Result<()> {
        Ok(())
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM