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