From c22269bff3085012d326a0df77bf27ad5bcb41b7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 05:33:47 +0100 Subject: Introduce `Program` API --- examples/loading_spinners/src/main.rs | 46 ++++++++++++----------------------- 1 file changed, 15 insertions(+), 31 deletions(-) (limited to 'examples/loading_spinners') diff --git a/examples/loading_spinners/src/main.rs b/examples/loading_spinners/src/main.rs index 93a4605e..bf36dc8d 100644 --- a/examples/loading_spinners/src/main.rs +++ b/examples/loading_spinners/src/main.rs @@ -1,6 +1,5 @@ -use iced::executor; use iced::widget::{column, container, row, slider, text}; -use iced::{Application, Command, Element, Length, Settings, Theme}; +use iced::{Element, Length}; use std::time::Duration; @@ -12,51 +11,28 @@ use circular::Circular; use linear::Linear; pub fn main() -> iced::Result { - LoadingSpinners::run(Settings { - antialiasing: true, - ..Default::default() - }) + iced::sandbox(LoadingSpinners::update, LoadingSpinners::view) + .title("Loading Spinners - Iced") + .antialiased() + .run() } struct LoadingSpinners { cycle_duration: f32, } -impl Default for LoadingSpinners { - fn default() -> Self { - Self { - cycle_duration: 2.0, - } - } -} - #[derive(Debug, Clone, Copy)] enum Message { CycleDurationChanged(f32), } -impl Application for LoadingSpinners { - type Message = Message; - type Flags = (); - type Executor = executor::Default; - type Theme = Theme; - - fn new(_flags: Self::Flags) -> (Self, Command) { - (Self::default(), Command::none()) - } - - fn title(&self) -> String { - String::from("Loading Spinners - Iced") - } - - fn update(&mut self, message: Message) -> Command { +impl LoadingSpinners { + fn update(&mut self, message: Message) { match message { Message::CycleDurationChanged(duration) => { self.cycle_duration = duration; } } - - Command::none() } fn view(&self) -> Element { @@ -115,3 +91,11 @@ impl Application for LoadingSpinners { .into() } } + +impl Default for LoadingSpinners { + fn default() -> Self { + Self { + cycle_duration: 2.0, + } + } +} -- cgit