livesplit_core/run/editor/
segment_row.rs1use super::{parse_positive, Editor, ParseError};
2use crate::{settings::Image, util::PopulateString, TimeSpan};
3
4pub struct SegmentRow<'editor> {
7 index: usize,
8 editor: &'editor mut Editor,
9}
10
11impl<'a> SegmentRow<'a> {
12 pub(super) fn new(index: usize, editor: &'a mut Editor) -> Self {
13 SegmentRow { index, editor }
14 }
15
16 pub fn icon(&self) -> &Image {
18 self.editor.run.segment(self.index).icon()
19 }
20
21 pub fn set_icon<D: Into<Image>>(&mut self, image: D) {
23 self.editor.run.segment_mut(self.index).set_icon(image);
24 self.editor.raise_run_edited();
25 }
26
27 pub fn remove_icon(&mut self) {
29 self.editor.run.segment_mut(self.index).set_icon([]);
30 self.editor.raise_run_edited();
31 }
32
33 pub fn name(&self) -> &str {
35 self.editor.run.segment(self.index).name()
36 }
37
38 pub fn set_name<S>(&mut self, name: S)
40 where
41 S: PopulateString,
42 {
43 self.editor.run.segment_mut(self.index).set_name(name);
44 self.editor.raise_run_edited();
45 }
46
47 pub fn split_time(&self) -> Option<TimeSpan> {
49 let method = self.editor.selected_method;
50 self.editor
51 .run
52 .segment(self.index)
53 .personal_best_split_time()[method]
54 }
55
56 pub fn set_split_time(&mut self, time: Option<TimeSpan>) {
58 let method = self.editor.selected_method;
59 self.editor
60 .run
61 .segment_mut(self.index)
62 .personal_best_split_time_mut()[method] = time;
63 self.editor.times_modified();
64 self.editor.fix();
65 }
66
67 pub fn parse_and_set_split_time(&mut self, time: &str) -> Result<(), ParseError> {
70 self.set_split_time(parse_positive(time)?);
71 Ok(())
72 }
73
74 pub fn segment_time(&self) -> Option<TimeSpan> {
76 self.editor.segment_times[self.index]
77 }
78
79 pub fn set_segment_time(&mut self, time: Option<TimeSpan>) {
81 self.editor.segment_times[self.index] = time;
82 self.editor.fix_splits_from_segments();
83 self.editor.times_modified();
84 self.editor.fix();
85 }
86
87 pub fn parse_and_set_segment_time(&mut self, time: &str) -> Result<(), ParseError> {
90 self.set_segment_time(parse_positive(time)?);
91 Ok(())
92 }
93
94 pub fn best_segment_time(&self) -> Option<TimeSpan> {
96 let method = self.editor.selected_method;
97 self.editor.run.segment(self.index).best_segment_time()[method]
98 }
99
100 pub fn set_best_segment_time(&mut self, time: Option<TimeSpan>) {
102 let method = self.editor.selected_method;
103 self.editor
104 .run
105 .segment_mut(self.index)
106 .best_segment_time_mut()[method] = time;
107 self.editor.times_modified();
108 self.editor.fix();
109 }
110
111 pub fn parse_and_set_best_segment_time(&mut self, time: &str) -> Result<(), ParseError> {
114 self.set_best_segment_time(parse_positive(time)?);
115 Ok(())
116 }
117
118 pub fn comparison_time(&self, comparison: &str) -> Option<TimeSpan> {
121 let method = self.editor.selected_method;
122 self.editor.run.segment(self.index).comparison(comparison)[method]
123 }
124
125 pub fn set_comparison_time(&mut self, comparison: &str, time: Option<TimeSpan>) {
127 let method = self.editor.selected_method;
128 self.editor
129 .run
130 .segment_mut(self.index)
131 .comparison_mut(comparison)[method] = time;
132 self.editor.times_modified();
133 self.editor.fix();
134 }
135
136 pub fn parse_and_set_comparison_time(
139 &mut self,
140 comparison: &str,
141 time: &str,
142 ) -> Result<(), ParseError> {
143 self.set_comparison_time(comparison, parse_positive(time)?);
144 Ok(())
145 }
146}