Skip to content

Commit 75ce831

Browse files
committed
small pausing bug fixes and lints
1 parent 229b60b commit 75ce831

File tree

4 files changed

+11
-25
lines changed

4 files changed

+11
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ TODOs before release:
1717
- [ ] Documentation
1818
- [ ] Add `Cosmic` cargo feature for compatibility with both iced and System76's temporary fork.
1919
- [x] optimize for `as_subscription` logic
20-
- [ ] Add pause for looping animations
20+
- [x] Add pause for animations
2121

2222
Other TODOs:
2323
- [x] test for easing

examples/stopwatch/src/main.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use iced::alignment;
22
use iced::executor;
3-
use iced::time;
4-
use iced::widget::{button, column, container, row, text};
3+
use iced::widget::{button, column, row, text};
54
use iced::{Alignment, Application, Command, Event, Length, Settings, Subscription};
65

76
mod theme;
@@ -54,7 +53,7 @@ impl Application for Stopwatch {
5453
timeline.set_chain_paused(anim_background()).start();
5554
(
5655
Stopwatch {
57-
timeline: timeline,
56+
timeline,
5857
duration: Duration::default(),
5958
state: State::Idle,
6059
},
@@ -106,13 +105,7 @@ impl Application for Stopwatch {
106105
}
107106

108107
fn subscription(&self) -> Subscription<Message> {
109-
Subscription::batch(vec![
110-
match self.state {
111-
State::Idle => Subscription::none(),
112-
State::Ticking { .. } => time::every(Duration::from_millis(10)).map(Message::Tick),
113-
},
114-
self.timeline.as_subscription::<Event>().map(Message::Tick),
115-
])
108+
self.timeline.as_subscription::<Event>().map(Message::Tick)
116109
}
117110

118111
fn view(&self) -> Element<Message> {

examples/stopwatch/src/theme.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
*
99
*/
1010

11-
use iced::theme::palette::{self, Background};
1211
use iced::widget::{button, container, text};
1312
use iced::Background as B;
14-
use iced::{application, color, Color, Vector};
13+
use iced::{application, color, Vector};
1514

1615
#[derive(Default)]
1716
pub struct Theme;
@@ -76,6 +75,7 @@ impl container::StyleSheet for Theme {
7675
}
7776

7877
#[derive(Default)]
78+
#[allow(dead_code)]
7979
pub enum Button {
8080
#[default]
8181
Primary,
@@ -98,7 +98,6 @@ impl button::StyleSheet for Theme {
9898
border_width: 10.0,
9999
shadow_offset: Vector::new(3., 3.),
100100
border_color: color!(0x25, 0x63, 0xeb),
101-
..Default::default()
102101
},
103102
Button::Secondary => button::Appearance {
104103
background: color!(0x3c, 0x38, 0x36).into(),
@@ -114,7 +113,6 @@ impl button::StyleSheet for Theme {
114113
shadow_offset: Vector::new(5., 5.),
115114
border_color: color!(0xdc, 0x26, 0x26),
116115
border_width: 10.0,
117-
..Default::default()
118116
},
119117
_ => panic!("This isn't a custom style exmaple, just skipping these for now"),
120118
}

src/timeline.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct PendingChain {
5959
}
6060

6161
impl PendingChain {
62+
#[allow(clippy::new_ret_no_self)]
6263
pub fn new(
6364
id: widget::Id,
6465
repeat: Repeat,
@@ -123,9 +124,9 @@ impl Meta {
123124

124125
pub fn pause(&mut self, now: Instant) {
125126
if let Pause::Resumed(delay) = self.pause {
126-
self.pause = Pause::Paused(relative_time(&(now - delay), &self));
127+
self.pause = Pause::Paused(relative_time(&(now - delay), self));
127128
} else {
128-
self.pause = Pause::Paused(relative_time(&now, &self));
129+
self.pause = Pause::Paused(relative_time(&now, self));
129130
}
130131
}
131132

@@ -149,10 +150,7 @@ pub enum Pause {
149150

150151
impl Pause {
151152
pub fn is_playing(&self) -> bool {
152-
match self {
153-
Pause::Paused(_) => false,
154-
_ => true,
155-
}
153+
!matches!(self, Pause::Paused(_))
156154
}
157155
}
158156

@@ -298,7 +296,7 @@ impl Timeline {
298296
}
299297

300298
pub fn start(&mut self) {
301-
self.start_at(self.now);
299+
self.start_at(Instant::now());
302300
}
303301

304302
pub fn start_at(&mut self, now: Instant) {
@@ -416,9 +414,6 @@ impl Timeline {
416414
modifier.value,
417415
modifier.ease.tween(elapsed / duration),
418416
);
419-
if index == 8 && meta.length == Duration::from_secs(4) {
420-
println!("({percent}%) relative_now = {:?}", relative_now);
421-
}
422417

423418
return Some(Interped {
424419
previous,

0 commit comments

Comments
 (0)