Skip to main content

Bitmap

Struct Bitmap 

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

Implementations§

Source§

impl<'a> Bitmap<'a>

Source

pub fn new(data: &'a [u32], width: usize, height: usize) -> Bitmap<'a>

Examples found in repository?
examples/child_window.rs (line 26)
16    fn handle_event(&mut self, event: Event) -> Response {
17        match event {
18            Event::Frame => {
19                let window = &self.window.as_ref().unwrap();
20
21                let scale = window.scale();
22                let size = window.size();
23                let width = (scale * size.width) as usize;
24                let height = (scale * size.height) as usize;
25                self.framebuffer.resize(width * height, 0xFF00FFFF);
26                window.present(Bitmap::new(&self.framebuffer, width, height));
27            }
28            Event::Close => {
29                self.event_loop.exit();
30            }
31            _ => {}
32        }
33
34        Response::Ignore
35    }
36}
37
38struct ChildState {
39    framebuffer: Vec<u32>,
40    window: Option<Window>,
41}
42
43impl ChildState {
44    fn handle_event(&mut self, event: Event) -> Response {
45        match event {
46            Event::Frame => {
47                let window = &self.window.as_ref().unwrap();
48
49                let scale = window.scale();
50                let size = window.size();
51                let width = (scale * size.width) as usize;
52                let height = (scale * size.height) as usize;
53                self.framebuffer.resize(width * height, 0xFFFF00FF);
54                window.present(Bitmap::new(&self.framebuffer, width, height));
55            }
56            _ => {}
57        }
58
59        Response::Ignore
60    }
More examples
Hide additional examples
examples/basic.rs (line 41)
26    fn handle_event(&mut self, event: Event) -> Response {
27        match event {
28            Event::Expose(rects) => {
29                println!("expose: {:?}", rects);
30            }
31            Event::Frame => {
32                println!("frame");
33
34                let window = self.window.as_ref().unwrap();
35
36                let scale = window.scale();
37                self.width = (WIDTH as f64 * scale) as usize;
38                self.height = (HEIGHT as f64 * scale) as usize;
39                self.framebuffer.resize(self.width * self.height, 0xFFFF00FF);
40
41                window.present(Bitmap::new(&self.framebuffer, self.width, self.height));
42            }
43            Event::GainFocus => {
44                println!("gain focus");
45            }
46            Event::LoseFocus => {
47                println!("lose focus");
48            }
49            Event::MouseEnter => {
50                println!("mouse enter");
51            }
52            Event::MouseExit => {
53                println!("mouse exit");
54            }
55            Event::MouseMove(pos) => {
56                println!("mouse move: {:?}", pos);
57            }
58            Event::MouseDown(btn) => {
59                println!("mouse down: {:?}", btn);
60                return Response::Capture;
61            }
62            Event::MouseUp(btn) => {
63                println!("mouse up: {:?}", btn);
64                return Response::Capture;
65            }
66            Event::Scroll(delta) => {
67                println!("scroll: {:?}", delta);
68                return Response::Capture;
69            }
70            Event::Close => {
71                self.event_loop.exit();
72            }
73        }
74
75        Response::Ignore
76    }
Source

pub fn data(&self) -> &'a [u32]

Source

pub fn width(&self) -> usize

Source

pub fn height(&self) -> usize

Auto Trait Implementations§

§

impl<'a> Freeze for Bitmap<'a>

§

impl<'a> RefUnwindSafe for Bitmap<'a>

§

impl<'a> Send for Bitmap<'a>

§

impl<'a> Sync for Bitmap<'a>

§

impl<'a> Unpin for Bitmap<'a>

§

impl<'a> UnsafeUnpin for Bitmap<'a>

§

impl<'a> UnwindSafe for Bitmap<'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.