2
0
mirror of https://github.com/xvxx/phetch synced 2024-11-03 03:40:20 +00:00

circular navigation

This commit is contained in:
dvkt 2019-12-27 10:52:52 -08:00
parent c815c01df4
commit 8d88eb9088

View File

@ -212,7 +212,7 @@ impl Menu {
} }
let padding = self.padding_bottom(); let padding = self.padding_bottom();
if self.scroll <= padding { if self.scroll < padding {
self.scroll += SCROLL_LINES; self.scroll += SCROLL_LINES;
if self.scroll > padding { if self.scroll > padding {
self.scroll = padding; self.scroll = padding;
@ -221,24 +221,26 @@ impl Menu {
return Action::Redraw; return Action::Redraw;
} }
} }
if let Some(dir) = self.link_visibility(self.link) {
match dir {
LinkPos::Above => {
let scroll = self.scroll;
if let Some(&pos) =
self.links.iter().skip(self.link).find(|&&i| i >= scroll)
{
self.link = self.lines.get(pos).unwrap().link;
}
}
LinkPos::Below => {}
LinkPos::Visible => {}
}
}
Action::Redraw
} else { } else {
Action::None if !self.links.is_empty() {
self.link = self.links.len() - 1;
return Action::Redraw;
}
} }
if let Some(dir) = self.link_visibility(self.link) {
match dir {
LinkPos::Above => {
let scroll = self.scroll;
if let Some(&pos) = self.links.iter().skip(self.link).find(|&&i| i >= scroll) {
self.link = self.lines.get(pos).unwrap().link;
return Action::Redraw;
}
}
LinkPos::Below => {}
LinkPos::Visible => {}
}
}
Action::None
} }
fn action_page_up(&mut self) -> Action { fn action_page_up(&mut self) -> Action {
@ -283,6 +285,10 @@ impl Menu {
return if self.scroll > 0 { return if self.scroll > 0 {
self.scroll -= 1; self.scroll -= 1;
Action::Redraw Action::Redraw
} else if !self.links.is_empty() {
self.link = self.links.len() - 1;
self.scroll_to(self.link);
Action::Redraw
} else { } else {
Action::None Action::None
}; };
@ -379,7 +385,10 @@ impl Menu {
self.scroll += 1; self.scroll += 1;
return Action::Redraw; return Action::Redraw;
} else { } else {
return Action::None; // wrap around
self.link = 0;
self.scroll_to(self.link);
return Action::Redraw;
} }
} }