diff options
author | 2023-01-13 20:33:59 +0100 | |
---|---|---|
committer | 2023-01-13 20:33:59 +0100 | |
commit | 597af315af714f3ecadd195516e80506504dcb26 (patch) | |
tree | 200d0447efc60c9066b762c9f1a00ce55d66def7 /examples | |
parent | d2b66805b350b4bd2ca5cb2818a6c05e3cfb5235 (diff) | |
parent | 507820a8438cec25074f92b72e118e0931fa7f9f (diff) | |
download | iced-597af315af714f3ecadd195516e80506504dcb26.tar.gz iced-597af315af714f3ecadd195516e80506504dcb26.tar.bz2 iced-597af315af714f3ecadd195516e80506504dcb26.zip |
Merge pull request #1647 from iced-rs/feature/widget-request-redraw
Widget-driven animations
Diffstat (limited to 'examples')
-rw-r--r-- | examples/events/Cargo.toml | 2 | ||||
-rw-r--r-- | examples/events/src/main.rs | 24 | ||||
-rw-r--r-- | examples/exit/src/main.rs | 26 | ||||
-rw-r--r-- | examples/solar_system/src/main.rs | 3 |
4 files changed, 26 insertions, 29 deletions
diff --git a/examples/events/Cargo.toml b/examples/events/Cargo.toml index 8ad04a36..8c56e471 100644 --- a/examples/events/Cargo.toml +++ b/examples/events/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" publish = false [dependencies] -iced = { path = "../.." } +iced = { path = "../..", features = ["debug"] } iced_native = { path = "../../native" } diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs index 234e1423..4ae8d6fb 100644 --- a/examples/events/src/main.rs +++ b/examples/events/src/main.rs @@ -1,11 +1,12 @@ use iced::alignment; use iced::executor; use iced::widget::{button, checkbox, container, text, Column}; +use iced::window; use iced::{ Alignment, Application, Command, Element, Length, Settings, Subscription, Theme, }; -use iced_native::{window, Event}; +use iced_native::Event; pub fn main() -> iced::Result { Events::run(Settings { @@ -18,7 +19,6 @@ pub fn main() -> iced::Result { struct Events { last: Vec<iced_native::Event>, enabled: bool, - should_exit: bool, } #[derive(Debug, Clone)] @@ -50,31 +50,29 @@ impl Application for Events { if self.last.len() > 5 { let _ = self.last.remove(0); } + + Command::none() } Message::EventOccurred(event) => { if let Event::Window(window::Event::CloseRequested) = event { - self.should_exit = true; + window::close() + } else { + Command::none() } } Message::Toggled(enabled) => { self.enabled = enabled; - } - Message::Exit => { - self.should_exit = true; - } - }; - Command::none() + Command::none() + } + Message::Exit => window::close(), + } } fn subscription(&self) -> Subscription<Message> { iced_native::subscription::events().map(Message::EventOccurred) } - fn should_exit(&self) -> bool { - self.should_exit - } - fn view(&self) -> Element<Message> { let events = Column::with_children( self.last diff --git a/examples/exit/src/main.rs b/examples/exit/src/main.rs index 5d518d2f..6152f627 100644 --- a/examples/exit/src/main.rs +++ b/examples/exit/src/main.rs @@ -1,5 +1,7 @@ +use iced::executor; use iced::widget::{button, column, container}; -use iced::{Alignment, Element, Length, Sandbox, Settings}; +use iced::window; +use iced::{Alignment, Application, Command, Element, Length, Settings, Theme}; pub fn main() -> iced::Result { Exit::run(Settings::default()) @@ -8,7 +10,6 @@ pub fn main() -> iced::Result { #[derive(Default)] struct Exit { show_confirm: bool, - exit: bool, } #[derive(Debug, Clone, Copy)] @@ -17,28 +18,27 @@ enum Message { Exit, } -impl Sandbox for Exit { +impl Application for Exit { + type Executor = executor::Default; type Message = Message; + type Theme = Theme; + type Flags = (); - fn new() -> Self { - Self::default() + fn new(_flags: ()) -> (Self, Command<Message>) { + (Self::default(), Command::none()) } fn title(&self) -> String { String::from("Exit - Iced") } - fn should_exit(&self) -> bool { - self.exit - } - - fn update(&mut self, message: Message) { + fn update(&mut self, message: Message) -> Command<Message> { match message { - Message::Confirm => { - self.exit = true; - } + Message::Confirm => window::close(), Message::Exit => { self.show_confirm = true; + + Command::none() } } } diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 9e303576..9a4ee754 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -9,7 +9,6 @@ use iced::application; use iced::executor; use iced::theme::{self, Theme}; -use iced::time; use iced::widget::canvas; use iced::widget::canvas::gradient::{self, Gradient}; use iced::widget::canvas::stroke::{self, Stroke}; @@ -90,7 +89,7 @@ impl Application for SolarSystem { } fn subscription(&self) -> Subscription<Message> { - time::every(time::Duration::from_millis(10)).map(Message::Tick) + window::frames().map(Message::Tick) } } |