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