diff options
Diffstat (limited to '')
| -rw-r--r-- | examples/solar_system/src/main.rs | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 618f4206..5392f712 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -7,10 +7,9 @@ //! //! [1]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations#An_animated_solar_system use iced::{ - canvas, executor, window, Application, Canvas, Color, Command, Container, - Element, Length, Point, Settings, Size, Subscription, Vector, + canvas, executor, window, Application, Canvas, Color, Command, Element, + Length, Point, Settings, Size, Subscription, Vector, }; -use iced_native::input::{self, mouse}; use std::time::Instant; @@ -64,15 +63,9 @@ impl Application for SolarSystem { } fn view(&mut self) -> Element<Message> { - let canvas = Canvas::new(&mut self.state) - .width(Length::Fill) - .height(Length::Fill); - - Container::new(canvas) + Canvas::new(&mut self.state) .width(Length::Fill) .height(Length::Fill) - .center_x() - .center_y() .into() } } @@ -127,8 +120,14 @@ impl State { .map(|_| { ( Point::new( - rng.gen_range(0.0, width as f32), - rng.gen_range(0.0, height as f32), + rng.gen_range( + -(width as f32) / 2.0, + width as f32 / 2.0, + ), + rng.gen_range( + -(height as f32) / 2.0, + height as f32 / 2.0, + ), ), rng.gen_range(0.5, 1.0), ) @@ -138,24 +137,6 @@ impl State { } impl canvas::State for State { - fn update(&mut self, event: canvas::Event, _bounds: Size) { - match event { - canvas::Event::Mouse(mouse_event) => match mouse_event { - mouse::Event::CursorMoved { x, y } => { - self.cursor_position = Point::new(x, y); - } - mouse::Event::Input { - button: mouse::Button::Left, - state: input::ButtonState::Released, - } => { - self.stars.push((self.cursor_position, 2.0)); - self.space_cache.clear(); - } - _ => {} - }, - } - } - fn draw(&self, bounds: Size) -> Vec<canvas::Geometry> { vec