summaryrefslogtreecommitdiffstats
path: root/examples/solar_system/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/solar_system/src/main.rs')
-rw-r--r--examples/solar_system/src/main.rs55
1 files changed, 17 insertions, 38 deletions
diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs
index 4cc625da..a84e86a3 100644
--- a/examples/solar_system/src/main.rs
+++ b/examples/solar_system/src/main.rs
@@ -6,8 +6,6 @@
//! Inspired by the example found in the MDN docs[1].
//!
//! [1]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations#An_animated_solar_system
-use iced::application;
-use iced::executor;
use iced::mouse;
use iced::widget::canvas;
use iced::widget::canvas::gradient;
@@ -15,8 +13,8 @@ use iced::widget::canvas::stroke::{self, Stroke};
use iced::widget::canvas::Path;
use iced::window;
use iced::{
- Application, Color, Command, Element, Length, Point, Rectangle, Renderer,
- Settings, Size, Subscription, Theme, Vector,
+ Color, Element, Length, Point, Rectangle, Renderer, Size, Subscription,
+ Theme, Vector,
};
use std::time::Instant;
@@ -24,12 +22,14 @@ use std::time::Instant;
pub fn main() -> iced::Result {
tracing_subscriber::fmt::init();
- SolarSystem::run(Settings {
- antialiasing: true,
- ..Settings::default()
- })
+ iced::sandbox(SolarSystem::update, SolarSystem::view)
+ .subscription(SolarSystem::subscription)
+ .theme(SolarSystem::theme)
+ .title("Solar System - Iced")
+ .run()
}
+#[derive(Default)]
struct SolarSystem {
state: State,
}
@@ -39,33 +39,13 @@ enum Message {
Tick(Instant),
}
-impl Application for SolarSystem {
- type Executor = executor::Default;
- type Message = Message;
- type Theme = Theme;
- type Flags = ();
-
- fn new(_flags: ()) -> (Self, Command<Message>) {
- (
- SolarSystem {
- state: State::new(),
- },
- Command::none(),
- )
- }
-
- fn title(&self) -> String {
- String::from("Solar system - Iced")
- }
-
- fn update(&mut self, message: Message) -> Command<Message> {
+impl SolarSystem {
+ fn update(&mut self, message: Message) {
match message {
Message::Tick(instant) => {
self.state.update(instant);
}
}
-
- Command::none()
}
fn view(&self) -> Element<Message> {
@@ -76,14 +56,7 @@ impl Application for SolarSystem {
}
fn theme(&self) -> Theme {
- Theme::Dark
- }
-
- fn style(&self, _theme: &Theme) -> application::Appearance {
- application::Appearance {
- background_color: Color::BLACK,
- text_color: Color::WHITE,
- }
+ Theme::Moonfly
}
fn subscription(&self) -> Subscription<Message> {
@@ -224,3 +197,9 @@ impl<Message> canvas::Program<Message> for State {
vec![background, system]
}
}
+
+impl Default for State {
+ fn default() -> Self {
+ Self::new()
+ }
+}