pub struct Context<'a> { /* private fields */ }
Implementations§
Source§impl Context<'_>
impl Context<'_>
Sourcepub fn event_loop(&self) -> &EventLoop
pub fn event_loop(&self) -> &EventLoop
Examples found in repository?
examples/child_window.rs (line 26)
12 fn event(&mut self, cx: &Context, _key: Key, event: Event) -> Response {
13 if let Event::Window(event) = event {
14 match event {
15 WindowEvent::Frame => {
16 let window = &self.window.as_ref().unwrap();
17
18 let scale = window.scale();
19 let size = window.size();
20 let width = (scale * size.width) as usize;
21 let height = (scale * size.height) as usize;
22 self.framebuffer.resize(width * height, 0xFF00FFFF);
23 window.present(Bitmap::new(&self.framebuffer, width, height));
24 }
25 WindowEvent::Close => {
26 cx.event_loop().exit();
27 }
28 _ => {}
29 }
30 }
31
32 Response::Ignore
33 }
More examples
examples/basic.rs (line 72)
26 fn event(&mut self, cx: &Context, _key: Key, event: Event) -> Response {
27 if let Event::Window(event) = event {
28 match event {
29 WindowEvent::Expose(rects) => {
30 println!("expose: {:?}", rects);
31 }
32 WindowEvent::Frame => {
33 println!("frame");
34
35 let window = self.window.as_ref().unwrap();
36
37 let scale = window.scale();
38 self.width = (WIDTH as f64 * scale) as usize;
39 self.height = (HEIGHT as f64 * scale) as usize;
40 self.framebuffer.resize(self.width * self.height, 0xFFFF00FF);
41
42 window.present(Bitmap::new(&self.framebuffer, self.width, self.height));
43 }
44 WindowEvent::GainFocus => {
45 println!("gain focus");
46 }
47 WindowEvent::LoseFocus => {
48 println!("lose focus");
49 }
50 WindowEvent::MouseEnter => {
51 println!("mouse enter");
52 }
53 WindowEvent::MouseExit => {
54 println!("mouse exit");
55 }
56 WindowEvent::MouseMove(pos) => {
57 println!("mouse move: {:?}", pos);
58 }
59 WindowEvent::MouseDown(btn) => {
60 println!("mouse down: {:?}", btn);
61 return Response::Capture;
62 }
63 WindowEvent::MouseUp(btn) => {
64 println!("mouse up: {:?}", btn);
65 return Response::Capture;
66 }
67 WindowEvent::Scroll(delta) => {
68 println!("scroll: {:?}", delta);
69 return Response::Capture;
70 }
71 WindowEvent::Close => {
72 cx.event_loop().exit();
73 }
74 }
75 } else if let Event::Timer = event {
76 println!("timer");
77 }
78
79 Response::Ignore
80 }
Auto Trait Implementations§
impl<'a> Freeze for Context<'a>
impl<'a> !RefUnwindSafe for Context<'a>
impl<'a> !Send for Context<'a>
impl<'a> !Sync for Context<'a>
impl<'a> Unpin for Context<'a>
impl<'a> !UnwindSafe for Context<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more