|
|
@ -199,11 +199,11 @@ impl Menu {
|
|
|
|
Action::None
|
|
|
|
Action::None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Scroll down by SCROLL_LINES, if possible.
|
|
|
|
fn action_page_down(&mut self) -> Action {
|
|
|
|
fn action_page_down(&mut self) -> Action {
|
|
|
|
let lines = self.lines.len();
|
|
|
|
// If there are fewer menu items than screen lines, just
|
|
|
|
|
|
|
|
// select the final link and do nothing else.
|
|
|
|
// fewer lines than visible rows, just select last link
|
|
|
|
if self.lines.len() < self.rows() {
|
|
|
|
if lines < self.rows() {
|
|
|
|
|
|
|
|
if !self.links.is_empty() {
|
|
|
|
if !self.links.is_empty() {
|
|
|
|
self.link = self.links.len() - 1;
|
|
|
|
self.link = self.links.len() - 1;
|
|
|
|
return Action::Redraw;
|
|
|
|
return Action::Redraw;
|
|
|
@ -211,34 +211,38 @@ impl Menu {
|
|
|
|
return Action::None;
|
|
|
|
return Action::None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let padding = self.padding_bottom();
|
|
|
|
// If we've already scrolled too far, select the final link
|
|
|
|
if self.scroll < padding {
|
|
|
|
// and do nothing.
|
|
|
|
self.scroll += SCROLL_LINES;
|
|
|
|
if self.scroll >= self.final_scroll() {
|
|
|
|
if self.scroll > padding {
|
|
|
|
self.scroll = self.final_scroll();
|
|
|
|
self.scroll = padding;
|
|
|
|
|
|
|
|
if !self.links.is_empty() {
|
|
|
|
|
|
|
|
self.link = self.links.len() - 1;
|
|
|
|
|
|
|
|
return Action::Redraw;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if !self.links.is_empty() {
|
|
|
|
|
|
|
|
self.link = self.links.len() - 1;
|
|
|
|
self.link = self.links.len() - 1;
|
|
|
|
return Action::Redraw;
|
|
|
|
return Action::Redraw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(dir) = self.link_visibility(self.link) {
|
|
|
|
|
|
|
|
match dir {
|
|
|
|
// Scroll...
|
|
|
|
LinkPos::Above => {
|
|
|
|
self.scroll += SCROLL_LINES;
|
|
|
|
let scroll = self.scroll;
|
|
|
|
|
|
|
|
if let Some(&pos) = self.links.iter().skip(self.link).find(|&&i| i >= scroll) {
|
|
|
|
// ...but don't go past the final line.
|
|
|
|
self.link = self.lines.get(pos).unwrap().link;
|
|
|
|
if self.scroll > self.final_scroll() {
|
|
|
|
return Action::Redraw;
|
|
|
|
self.scroll = self.final_scroll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the selected link isn't visible...
|
|
|
|
|
|
|
|
if Some(LinkPos::Above) == self.link_visibility(self.link) {
|
|
|
|
|
|
|
|
// ...find the next one that is.
|
|
|
|
|
|
|
|
if let Some(&next_link_pos) = self
|
|
|
|
|
|
|
|
.links
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.skip(self.link + 1)
|
|
|
|
|
|
|
|
.find(|&&i| i >= self.scroll)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if let Some(next_link_line) = self.lines.get(next_link_pos) {
|
|
|
|
|
|
|
|
self.link = next_link_line.link;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LinkPos::Below => {}
|
|
|
|
|
|
|
|
LinkPos::Visible => {}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Action::None
|
|
|
|
|
|
|
|
|
|
|
|
Action::Redraw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn action_page_up(&mut self) -> Action {
|
|
|
|
fn action_page_up(&mut self) -> Action {
|
|
|
@ -338,8 +342,8 @@ impl Menu {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// how many rows to pad with blank lines at the end of the page
|
|
|
|
/// Final `self.scroll` value.
|
|
|
|
fn padding_bottom(&self) -> usize {
|
|
|
|
fn final_scroll(&self) -> usize {
|
|
|
|
let padding = (self.rows() as f64 * 0.9) as usize;
|
|
|
|
let padding = (self.rows() as f64 * 0.9) as usize;
|
|
|
|
if self.lines.len() > padding {
|
|
|
|
if self.lines.len() > padding {
|
|
|
|
self.lines.len() - padding
|
|
|
|
self.lines.len() - padding
|
|
|
@ -379,7 +383,7 @@ impl Menu {
|
|
|
|
// no links or final link selected already
|
|
|
|
// no links or final link selected already
|
|
|
|
if self.links.is_empty() || new_link >= self.links.len() {
|
|
|
|
if self.links.is_empty() || new_link >= self.links.len() {
|
|
|
|
// if there are more rows, scroll down
|
|
|
|
// if there are more rows, scroll down
|
|
|
|
if self.lines.len() >= self.rows() && self.scroll < self.padding_bottom() {
|
|
|
|
if self.lines.len() >= self.rows() && self.scroll < self.final_scroll() {
|
|
|
|
self.scroll += 1;
|
|
|
|
self.scroll += 1;
|
|
|
|
return Action::Redraw;
|
|
|
|
return Action::Redraw;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|