Skip to content

Commit

Permalink
Reset slideshow when manually moved
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfbacon committed Mar 23, 2024
1 parent c51dfab commit ac581d5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,9 @@ impl SlideshowState {
};
}

fn advance(&mut self, config: &Config, secs: Duration) -> bool {
fn advance(&mut self, secs: Duration) -> bool {
match self {
Self::Active { remaining } => {
let has_elapsed = remaining.advance(secs);
if has_elapsed {
self.start(config);
}
has_elapsed
}
Self::Active { remaining } => remaining.advance(secs),
Self::Inactive => false,
}
}
Expand Down Expand Up @@ -85,6 +79,15 @@ impl SlideshowState {
self.set_active(slideshow_active, config);
}
}

fn reset(&mut self, config: &Config) {
match self {
Self::Active { remaining } => {
*remaining = config.slideshow.interval;
}
Self::Inactive => {}
}
}
}

pub struct App {
Expand Down Expand Up @@ -243,6 +246,7 @@ impl App {
};
let direction = NextPath { direction, mode };
self.image_state.next_path(direction);
self.slideshow.reset(&self.config);
}
}

Expand Down Expand Up @@ -467,7 +471,7 @@ impl App {

let next_from_slideshow = self
.slideshow
.advance(&self.config, Duration::new_secs_f32_saturating(elapsed));
.advance(Duration::new_secs_f32_saturating(elapsed));

if next_from_slideshow {
self.move_in(Direction::Right, MoveMode::RespectSlideshow);
Expand Down

0 comments on commit ac581d5

Please sign in to comment.