Fix rollover of list selection
This commit is contained in:
parent
331c55f572
commit
3a73641951
|
@ -56,24 +56,38 @@ pub struct ListSelection {
|
|||
}
|
||||
|
||||
impl ListSelection {
|
||||
fn change_value(&mut self, max: usize, f: fn(usize)->usize) {
|
||||
if let Some(cur_selection) = self.selection {
|
||||
self.selection = Some(f(cur_selection)%max);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn increment(&mut self, max: usize) {
|
||||
fn add_one(value: usize) -> usize {
|
||||
value + 1
|
||||
if let Some(cur_selection) = self.selection {
|
||||
self.selection = Some({
|
||||
if cur_selection + 1 >= max {
|
||||
0
|
||||
}
|
||||
|
||||
else {
|
||||
cur_selection + 1
|
||||
}
|
||||
});
|
||||
}
|
||||
self.change_value(max, add_one)
|
||||
}
|
||||
|
||||
pub fn decrement(&mut self, max: usize) {
|
||||
fn sub_one(value: usize) -> usize {
|
||||
value - 1
|
||||
if let Some(cur_selection) = self.selection {
|
||||
self.selection = Some({
|
||||
if cur_selection - 1 >= max {
|
||||
if max - 1 > 0 {
|
||||
max - 1
|
||||
}
|
||||
|
||||
else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
cur_selection - 1
|
||||
}
|
||||
});
|
||||
}
|
||||
self.change_value(max, sub_one)
|
||||
}
|
||||
|
||||
pub fn activate(&mut self) {
|
||||
|
@ -169,7 +183,7 @@ impl ConsoleUI {
|
|||
Ok(UIState::Alive)
|
||||
}
|
||||
},
|
||||
_ => Ok(UIState::Alive)
|
||||
_ => Ok(UIState::Alive)
|
||||
}
|
||||
},
|
||||
Event::Tick => {
|
||||
|
@ -240,9 +254,9 @@ impl ConsoleUI {
|
|||
|
||||
fn render_stats(frame: &mut ConsoleFrame, layout: Rect, content_selection: &ListSelection, data: &mut ConsoleUIData) {
|
||||
let layout = Layout::default().direction(Direction::Vertical).constraints([
|
||||
Constraint::Min(3),
|
||||
Constraint::Min(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Max(3),
|
||||
Constraint::Max(3),
|
||||
]).split(layout).to_vec();
|
||||
let content_list = List::new({
|
||||
let mut vec = Vec::new();
|
||||
|
@ -315,21 +329,14 @@ impl ConsoleUIData {
|
|||
if let Some(section) = memory_map.sections.last() {
|
||||
return section.adr + section.size as u64;
|
||||
}
|
||||
|
||||
0u64
|
||||
}
|
||||
|
||||
self.highest_adr = get_last_section_end_adr(memory_map);
|
||||
self.list = vec![
|
||||
String::from("Schwimmflugel 0"),
|
||||
String::from("Schwimmflugel 1"),
|
||||
String::from("Schwimmflugel 2"),
|
||||
String::from("Schwimmflugel 3"),
|
||||
String::from("Schwimmflugel 4"),
|
||||
String::from("Schwimmflugel 5"),
|
||||
String::from("Schwimmflugel 6"),
|
||||
String::from("Schwimmflugel 7"),
|
||||
];
|
||||
self.list = vec![String::from("<overall usage>")];
|
||||
for section in &memory_map.sections {
|
||||
self.list.push(section.name.clone());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue