pub struct SharedWindow { /* private fields */ }Expand description
Shared Window is a window that can be shared between thread.
Implementations§
Sourcepub fn new(window: &mut Window) -> SharedWindow
pub fn new(window: &mut Window) -> SharedWindow
Examples found in repository?
examples/threads.rs (line 16)
13fn main() {
14 let mut window = Window::new(gust::WIDTH, gust::HEIGHT, "Hello");
15 let event_handler = EventHandler::new(&window);
16 let mut shared = SharedWindow::new(&mut window);
17 let (send, recv) = mpsc::channel();
18
19 let renderer = thread::spawn(move || {
20 render(&mut shared, recv);
21 });
22
23 window.poll(None);
24 while window.is_open() {
25 window.poll_events();
26
27 for event in event_handler.fetch() {
28 match event.1 {
29 pressed!(Escape) => window.close(),
30 _ => {}
31 }
32 }
33 }
34 send.send(()).ok().expect("Failed to send ()");
35
36 renderer.join().unwrap();
37}Sourcepub fn active(&mut self) -> bool
pub fn active(&mut self) -> bool
Examples found in repository?
examples/threads.rs (line 40)
39fn render(shared: &mut SharedWindow, recv: mpsc::Receiver<()>) {
40 shared.active();
41 let texture_rc =
42 Rc::new(Texture::from_path("examples/texture/Dirt.png").expect("Cannot open New.png"));
43 let sprite = Sprite::from(&texture_rc);
44
45 loop {
46 if recv.try_recv() == Ok(()) {
47 break;
48 }
49 shared.clear(Color::red());
50 shared.draw(&sprite);
51 shared.display();
52 }
53}Sourcepub fn display(&mut self)
pub fn display(&mut self)
Examples found in repository?
examples/threads.rs (line 51)
39fn render(shared: &mut SharedWindow, recv: mpsc::Receiver<()>) {
40 shared.active();
41 let texture_rc =
42 Rc::new(Texture::from_path("examples/texture/Dirt.png").expect("Cannot open New.png"));
43 let sprite = Sprite::from(&texture_rc);
44
45 loop {
46 if recv.try_recv() == Ok(()) {
47 break;
48 }
49 shared.clear(Color::red());
50 shared.draw(&sprite);
51 shared.display();
52 }
53}Sourcepub fn clear(&self, color: Color)
pub fn clear(&self, color: Color)
Examples found in repository?
examples/threads.rs (line 49)
39fn render(shared: &mut SharedWindow, recv: mpsc::Receiver<()>) {
40 shared.active();
41 let texture_rc =
42 Rc::new(Texture::from_path("examples/texture/Dirt.png").expect("Cannot open New.png"));
43 let sprite = Sprite::from(&texture_rc);
44
45 loop {
46 if recv.try_recv() == Ok(()) {
47 break;
48 }
49 shared.clear(Color::red());
50 shared.draw(&sprite);
51 shared.display();
52 }
53}Trait Implementations§
Source§fn draw<T: Drawable>(&mut self, drawable: &T)
fn draw<T: Drawable>(&mut self, drawable: &T)
Function that draw on itself needed by everything that can be draw.
fn projection(&self) -> &Matrix4<f32>
fn get_center(&self) -> Vector<f32>
fn get_sizes(&self) -> Vector<f32>
Source§fn draw_with_context_mut<T: DrawableMut>(
&mut self,
drawable: &mut T,
context: &mut Context<'_>,
)
fn draw_with_context_mut<T: DrawableMut>( &mut self, drawable: &mut T, context: &mut Context<'_>, )
Draw with context fonction if you want to define you own fonction
Source§fn draw_mut<T: DrawableMut>(&mut self, drawable: &mut T)
fn draw_mut<T: DrawableMut>(&mut self, drawable: &mut T)
Function that can draw a DrawableMut.
Auto Trait Implementations§
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SetParameter for T
impl<T> SetParameter for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.