summaryrefslogtreecommitdiffstats
path: root/examples/loading_spinners/src/main.rs
diff options
context:
space:
mode:
authorLibravatar Nick Senger <dev@nsenger.com>2023-06-07 15:19:11 -0700
committerLibravatar Nick Senger <dev@nsenger.com>2023-06-07 15:42:13 -0700
commit2ebc92319711e6fa0dda310939257334625b59c9 (patch)
tree3643af813fbb72e4308893cd33d383c7a0c12986 /examples/loading_spinners/src/main.rs
parentcdfb8b30680de164280b8b90fbc08a1638e597e2 (diff)
downloadiced-2ebc92319711e6fa0dda310939257334625b59c9.tar.gz
iced-2ebc92319711e6fa0dda310939257334625b59c9.tar.bz2
iced-2ebc92319711e6fa0dda310939257334625b59c9.zip
feat: use lyon for easing
Diffstat (limited to 'examples/loading_spinners/src/main.rs')
-rw-r--r--examples/loading_spinners/src/main.rs118
1 files changed, 118 insertions, 0 deletions
diff --git a/examples/loading_spinners/src/main.rs b/examples/loading_spinners/src/main.rs
new file mode 100644
index 00000000..a78e9590
--- /dev/null
+++ b/examples/loading_spinners/src/main.rs
@@ -0,0 +1,118 @@
+use iced::executor;
+use iced::widget::{column, container, row, slider, text};
+use iced::{Application, Command, Element, Length, Settings, Theme};
+
+use std::time::Duration;
+
+mod circular;
+mod easing;
+mod linear;
+
+use circular::Circular;
+use linear::Linear;
+
+pub fn main() -> iced::Result {
+ LoadingSpinners::run(Settings {
+ antialiasing: true,
+ ..Default::default()
+ })
+}
+
+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<Message>) {
+ (Self::default(), Command::none())
+ }
+
+ fn title(&self) -> String {
+ String::from("Loading Spinners - Iced")
+ }
+
+ fn update(&mut self, message: Message) -> Command<Message> {
+ match message {
+ Message::CycleDurationChanged(duration) => {
+ self.cycle_duration = duration;
+ }
+ }
+
+ Command::none()
+ }
+
+ fn view(&self) -> Element<Message> {
+ let column = [
+ &easing::EMPHASIZED,
+ &easing::EMPHASIZED_DECELERATE,
+ &easing::EMPHASIZED_ACCELERATE,
+ &easing::STANDARD,
+ &easing::STANDARD_DECELERATE,
+ &easing::STANDARD_ACCELERATE,
+ ]
+ .iter()
+ .zip([
+ "Emphasized:",
+ "Emphasized Decelerate:",
+ "Emphasized Accelerate:",
+ "Standard:",
+ "Standard Decelerate:",
+ "Standard Accelerate:",
+ ])
+ .fold(column![], |column, (easing, label)| {
+ column.push(
+ row![
+ text(label).width(250),
+ Linear::new().easing(easing).cycle_duration(
+ Duration::from_secs_f32(self.cycle_duration)
+ ),
+ Circular::new().easing(easing).cycle_duration(
+ Duration::from_secs_f32(self.cycle_duration)
+ )
+ ]
+ .align_items(iced::Alignment::Center)
+ .spacing(20.0),
+ )
+ })
+ .spacing(20);
+
+ container(
+ column.push(
+ row(vec![
+ text("Cycle duration:").into(),
+ slider(1.0..=1000.0, self.cycle_duration * 100.0, |x| {
+ Message::CycleDurationChanged(x / 100.0)
+ })
+ .width(200.0)
+ .into(),
+ text(format!("{:.2}s", self.cycle_duration)).into(),
+ ])
+ .align_items(iced::Alignment::Center)
+ .spacing(20.0),
+ ),
+ )
+ .width(Length::Fill)
+ .height(Length::Fill)
+ .center_x()
+ .center_y()
+ .into()
+ }
+}