cursor/
cursor.rs

1use std::cell::UnsafeCell;
2
3use wx_rs::{self, CursorType, EventType};
4
5thread_local!(
6    static CURSORS: UnsafeCell<std::iter::Cycle<std::slice::Iter<'static, CursorType>>> = {
7        let cursors = &[CursorType::Arrow, CursorType::None, CursorType::Ibeam, CursorType::Hand, CursorType::Pencil, CursorType::NoEntry, CursorType::Cross, CursorType::Size, CursorType::SizeNESW];
8        UnsafeCell::new(cursors.iter().cycle())
9    }
10);
11
12use std::os::raw::c_void;
13extern "C" fn handle_event(event: *const c_void) {
14    match wx_rs::get_event_type(event) {
15        EventType::MouseLeftUp => {
16            let cursor = CURSORS.with(|r| unsafe { r.get().as_mut().unwrap().next().unwrap() });
17            println!("set_cursor: {:?}", cursor);
18            wx_rs::set_cursor(*cursor);
19        }
20        _ => (),
21    }
22}
23
24fn main() {
25    wx_rs::init_app("Hello!", 400, 300);
26    wx_rs::bind_canvas_events(handle_event);
27
28    wx_rs::run_app();
29}