blob: 219b9a46561c6e6c7e51261f5a0468d06932e9ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#[derive(Debug)]
pub struct ContentList<T> {
pub list: Vec<T>,
pub index: usize,
}
impl<T> ContentList<T> {
pub fn new() -> Self {
ContentList {
list: Vec::new(),
index: 0,
}
}
// Go to next item in list
pub fn next(&mut self) {
let len = self.list.len();
if len != 0 {
if self.index < len - 1 {
self.index += 1;
}
}
// let len = self.list.len();
// if len != 0 {
// if self.index == self.list.len() - 1 {
// self.index = 0;
// } else {
// self.index += 1;
// }
// }
}
/// Go to previous item in list
pub fn prev(&mut self) {
if self.index != 0 {
self.index -= 1;
}
// if self.index == 0 {
// let len = self.list.len();
// if len != 0 {
// self.index = len - 1;
// }
// } else {
// self.index -= 1;
// }
}
pub fn reset_index(&mut self) {
self.index = 0;
}
}
|