T
T
Tynkute2020-07-30 14:34:08
Rust
Tynkute, 2020-07-30 14:34:08

SDL2 Rust, how to handle button click event?

Hello.
I ran into an incident, I did not find any information about this in the documentation.
How to handle a button click on the screen?
Something similar to button.onclick() in js.
https://pastebin.com/DawvaqrG

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Lesnikov, 2020-07-30
@Tynkute

Handle Event::MouseButtonDown event?
The examples include :

match event {
    Event::Quit{..} |
    Event::KeyDown {keycode: Option::Some(Keycode::Escape), ..} =>
        break 'mainloop,
    Event::MouseButtonDown {x, y, ..} => {
        canvas.fill_rect(Rect::new(x, y, 1, 1))?;
        canvas.present();
    }
    _ => {}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question