Struct Context

Source
pub struct Context<'a> { /* private fields */ }

Implementations§

Source§

impl Context<'_>

Source

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
Hide additional 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.