diff options
author | 2022-07-27 06:49:20 +0200 | |
---|---|---|
committer | 2022-07-27 06:49:20 +0200 | |
commit | ff2519b1d43d481987351a83b6dd7237524c21f0 (patch) | |
tree | 5731eeb7eb1247d4a8951de0d5bc5d8102640559 /examples/pure/arc | |
parent | c44267b85f7aaa2997e3caf1323b837d95818c22 (diff) | |
download | iced-ff2519b1d43d481987351a83b6dd7237524c21f0.tar.gz iced-ff2519b1d43d481987351a83b6dd7237524c21f0.tar.bz2 iced-ff2519b1d43d481987351a83b6dd7237524c21f0.zip |
Replace stateful widgets with new `iced_pure` API
Diffstat (limited to 'examples/pure/arc')
-rw-r--r-- | examples/pure/arc/Cargo.toml | 9 | ||||
-rw-r--r-- | examples/pure/arc/README.md | 14 | ||||
-rw-r--r-- | examples/pure/arc/src/main.rs | 124 |
3 files changed, 0 insertions, 147 deletions
diff --git a/examples/pure/arc/Cargo.toml b/examples/pure/arc/Cargo.toml deleted file mode 100644 index 22113cf1..00000000 --- a/examples/pure/arc/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "arc" -version = "0.1.0" -authors = ["ThatsNoMoon <git@thatsnomoon.dev>"] -edition = "2021" -publish = false - -[dependencies] -iced = { path = "../../..", features = ["pure", "canvas", "tokio", "debug"] } diff --git a/examples/pure/arc/README.md b/examples/pure/arc/README.md deleted file mode 100644 index 303253da..00000000 --- a/examples/pure/arc/README.md +++ /dev/null @@ -1,14 +0,0 @@ -## Arc - -An application that uses the `Canvas` widget to draw a rotating arc. - -This is a simple demo for https://github.com/iced-rs/iced/pull/1358. - -The __[`main`]__ file contains all the code of the example. - -You can run it with `cargo run`: -``` -cargo run --package arc -``` - -[`main`]: src/main.rs diff --git a/examples/pure/arc/src/main.rs b/examples/pure/arc/src/main.rs deleted file mode 100644 index df0e1e8a..00000000 --- a/examples/pure/arc/src/main.rs +++ /dev/null @@ -1,124 +0,0 @@ -use std::{f32::consts::PI, time::Instant}; - -use iced::executor; -use iced::pure::widget::canvas::{ - self, Cache, Canvas, Cursor, Geometry, Path, Stroke, -}; -use iced::pure::{Application, Element}; -use iced::{Command, Length, Point, Rectangle, Settings, Subscription, Theme}; - -pub fn main() -> iced::Result { - Arc::run(Settings { - antialiasing: true, - ..Settings::default() - }) -} - -struct Arc { - start: Instant, - cache: Cache, -} - -#[derive(Debug, Clone, Copy)] -enum Message { - Tick, -} - -impl Application for Arc { - type Executor = executor::Default; - type Message = Message; - type Theme = Theme; - type Flags = (); - - fn new(_flags: ()) -> (Self, Command<Message>) { - ( - Arc { - start: Instant::now(), - cache: Default::default(), - }, - Command::none(), - ) - } - - fn title(&self) -> String { - String::from("Arc - Iced") - } - - fn update(&mut self, _: Message) -> Command<Message> { - self.cache.clear(); - - Command::none() - } - - fn subscription(&self) -> Subscription<Message> { - iced::time::every(std::time::Duration::from_millis(10)) - .map(|_| Message::Tick) - } - - fn view(&self) -> Element<Message> { - Canvas::new(self) - .width(Length::Fill) - .height(Length::Fill) - .into() - } - - fn theme(&self) -> Theme { - Theme::Dark - } -} - -impl<Message> canvas::Program<Message> for Arc { - type State = (); - - fn draw( - &self, - _state: &Self::State, - theme: &Theme, - bounds: Rectangle, - _cursor: Cursor, - ) -> Vec<Geometry> { - let geometry = self.cache.draw(bounds.size(), |frame| { - let palette = theme.palette(); - - let center = frame.center(); - let radius = frame.width().min(frame.height()) / 5.0; - - let start = Point::new(center.x, center.y - radius); - - let angle = (self.start.elapsed().as_millis() % 10_000) as f32 - / 10_000.0 - * 2.0 - * PI; - - let end = Point::new( - center.x + radius * angle.cos(), - center.y + radius * angle.sin(), - ); - - let circles = Path::new(|b| { - b.circle(start, 10.0); - b.move_to(end); - b.circle(end, 10.0); - }); - - frame.fill(&circles, palette.text); - - let path = Path::new(|b| { - b.move_to(start); - b.arc_to(center, end, 50.0); - b.line_to(end); - }); - - frame.stroke( - &path, - Stroke { - color: palette.text, - width: 10.0, - ..Stroke::default() - }, - ); - }); - - vec![geometry] - } -} |