Skip to main content

waft_test/
caption_style.rs

1//! The user's caption settings in memory, set by the test rather than the user: they answer the
2//! style the test gives and tell the app each time the test changes it.
3
4use std::cell::RefCell;
5use std::rc::Rc;
6
7use waft_embedder::{CaptionSettings, CaptionStyle, MediaChangeFuture};
8
9use crate::media::Changes;
10
11/// Caption settings that answer the style the test gives, telling the app each time the test
12/// changes it. Every clone is the same settings.
13#[derive(Clone)]
14pub struct MockCaptionSettings(Rc<CaptionSettingsShared>);
15
16struct CaptionSettingsShared {
17    style: RefCell<CaptionStyle>,
18    changes: Changes,
19}
20
21impl MockCaptionSettings {
22    /// Settings answering `style`.
23    pub fn new(style: CaptionStyle) -> MockCaptionSettings {
24        MockCaptionSettings(Rc::new(CaptionSettingsShared {
25            style: RefCell::new(style),
26            changes: Changes::default(),
27        }))
28    }
29
30    /// Answers `style` from now on, telling the app, as the system would once the user changed a
31    /// setting.
32    pub fn set_style(&self, style: CaptionStyle) {
33        *self.0.style.borrow_mut() = style;
34        self.0.changes.notify();
35    }
36}
37
38impl CaptionSettings for MockCaptionSettings {
39    fn style(&self) -> CaptionStyle {
40        self.0.style.borrow().clone()
41    }
42
43    fn changed(&self) -> MediaChangeFuture {
44        self.0.changes.next()
45    }
46}