Introduce Program API
This commit is contained in:
parent
0524e9b457
commit
c22269bff3
43 changed files with 1141 additions and 831 deletions
|
|
@ -1,20 +1,18 @@
|
|||
use std::{f32::consts::PI, time::Instant};
|
||||
|
||||
use iced::executor;
|
||||
use iced::mouse;
|
||||
use iced::widget::canvas::{
|
||||
self, stroke, Cache, Canvas, Geometry, Path, Stroke,
|
||||
};
|
||||
use iced::{
|
||||
Application, Command, Element, Length, Point, Rectangle, Renderer,
|
||||
Settings, Subscription, Theme,
|
||||
};
|
||||
use iced::{Element, Length, Point, Rectangle, Renderer, Subscription, Theme};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
Arc::run(Settings {
|
||||
antialiasing: true,
|
||||
..Settings::default()
|
||||
})
|
||||
iced::sandbox(Arc::update, Arc::view)
|
||||
.title("Arc - Iced")
|
||||
.subscription(Arc::subscription)
|
||||
.theme(|_| Theme::Dark)
|
||||
.antialiased()
|
||||
.run()
|
||||
}
|
||||
|
||||
struct Arc {
|
||||
|
|
@ -27,30 +25,9 @@ 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: Cache::default(),
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Arc - Iced")
|
||||
}
|
||||
|
||||
fn update(&mut self, _: Message) -> Command<Message> {
|
||||
impl Arc {
|
||||
fn update(&mut self, _: Message) {
|
||||
self.cache.clear();
|
||||
|
||||
Command::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
|
|
@ -60,16 +37,21 @@ impl Application for Arc {
|
|||
.into()
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
Theme::Dark
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
iced::time::every(std::time::Duration::from_millis(10))
|
||||
.map(|_| Message::Tick)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Arc {
|
||||
fn default() -> Self {
|
||||
Arc {
|
||||
start: Instant::now(),
|
||||
cache: Cache::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Message> canvas::Program<Message> for Arc {
|
||||
type State = ();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue