diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.rs | 2 | ||||
| -rw-r--r-- | src/cue_view.rs | 6 | ||||
| -rw-r--r-- | src/subtitle_view.rs | 6 | ||||
| -rw-r--r-- | src/util/mod.rs | 2 | ||||
| -rw-r--r-- | src/util/option_tracker.rs | 43 |
5 files changed, 7 insertions, 52 deletions
diff --git a/src/app.rs b/src/app.rs index 066980c..d6b731c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -12,7 +12,7 @@ use crate::{ subtitle_view::{SubtitleView, SubtitleViewMsg, SubtitleViewOutput}, tracks::{SUBTITLE_TRACKS, StreamIndex, SubtitleCue}, transcript::{Transcript, TranscriptMsg, TranscriptOutput}, - util::{OptionTracker, Tracker}, + util::Tracker, }; pub struct App { diff --git a/src/cue_view.rs b/src/cue_view.rs index c031720..fbf2520 100644 --- a/src/cue_view.rs +++ b/src/cue_view.rs @@ -8,10 +8,10 @@ use relm4::prelude::*; use relm4::{ComponentParts, SimpleComponent}; use unicode_segmentation::UnicodeSegmentation; -use crate::util::OptionTracker; +use crate::util::Tracker; pub struct CueView { - text: OptionTracker<String>, + text: Tracker<Option<String>>, // byte ranges for the words in `text` word_ranges: Vec<Range<usize>>, } @@ -71,7 +71,7 @@ impl SimpleComponent for CueView { sender: relm4::ComponentSender<Self>, ) -> relm4::ComponentParts<Self> { let model = Self { - text: OptionTracker::new(None), + text: Tracker::new(None), word_ranges: Vec::new(), }; diff --git a/src/subtitle_view.rs b/src/subtitle_view.rs index 50494b8..fd98c60 100644 --- a/src/subtitle_view.rs +++ b/src/subtitle_view.rs @@ -1,11 +1,11 @@ use crate::cue_view::{CueView, CueViewMsg, CueViewOutput}; -use crate::util::OptionTracker; +use crate::util::Tracker; use gtk::prelude::*; use relm4::prelude::*; pub struct SubtitleView { primary_cue: Controller<CueView>, - secondary_cue: OptionTracker<String>, + secondary_cue: Tracker<Option<String>>, } #[derive(Debug)] @@ -67,7 +67,7 @@ impl SimpleComponent for SubtitleView { CueViewOutput::MouseEnter => SubtitleViewOutput::SetHoveringCue(true), CueViewOutput::MouseLeave => SubtitleViewOutput::SetHoveringCue(false), }), - secondary_cue: OptionTracker::default(), + secondary_cue: Tracker::new(None), }; let widgets = view_output!(); diff --git a/src/util/mod.rs b/src/util/mod.rs index 600d572..4d19eff 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,5 +1,3 @@ -mod option_tracker; mod tracker; -pub use option_tracker::OptionTracker; pub use tracker::Tracker; diff --git a/src/util/option_tracker.rs b/src/util/option_tracker.rs deleted file mode 100644 index 3c19ee5..0000000 --- a/src/util/option_tracker.rs +++ /dev/null @@ -1,43 +0,0 @@ -pub struct OptionTracker<T> { - inner: Option<T>, - dirty: bool, -} - -/// Tracks changes to an inner Option<T>. Any change using `set` will cause the -/// tracker to be marked as dirty, unless both the current and new value are -/// `None`. This should be used when changes from `Some(something)` to -/// `Some(something_different)` are rare, or when comparing inner values is more -/// expensive than performing an update which will mark the tracker as clean. -impl<T> OptionTracker<T> { - pub fn new(inner: Option<T>) -> Self { - Self { inner, dirty: true } - } - - pub fn get(&self) -> &Option<T> { - &self.inner - } - - pub fn set(&mut self, value: Option<T>) { - match (&self.inner, &value) { - (None, None) => {} - _ => self.dirty = true, - } - - self.inner = value; - } - - pub fn is_dirty(&self) -> bool { - self.dirty - } - - /// Marks the tracker as clean. - pub fn reset(&mut self) { - self.dirty = false; - } -} - -impl<T> Default for OptionTracker<T> { - fn default() -> Self { - Self::new(Option::default()) - } -} |