Add support for PgUp and PgDn scrolling #121
@ -56,7 +56,7 @@ impl Delta {
|
||||
fn as_usize(&self, state: &WidgetState) -> usize {
|
||||
match self {
|
||||
Delta::Line => 1,
|
||||
Delta::Page => state.height.checked_sub(1).unwrap_or(0),
|
||||
Delta::Page => state.height.saturating_sub(1),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,10 +174,10 @@ impl ArtistSelection {
|
||||
|
||||
fn increment_by(&mut self, artists: &[Artist], by: usize) {
|
||||
if let Some(index) = self.state.list.selected() {
|
||||
let result = index
|
||||
.checked_add(by)
|
||||
.filter(|i| i < &artists.len())
|
||||
.unwrap_or_else(|| artists.len() - 1);
|
||||
let mut result = index.saturating_add(by);
|
||||
if result >= artists.len() {
|
||||
result = artists.len() - 1;
|
||||
}
|
||||
if self.state.list.selected() != Some(result) {
|
||||
self.state.list.select(Some(result));
|
||||
self.album = AlbumSelection::initialise(&artists[result].albums);
|
||||
@ -203,7 +203,7 @@ impl ArtistSelection {
|
||||
|
||||
fn decrement_by(&mut self, artists: &[Artist], by: usize) {
|
||||
if let Some(index) = self.state.list.selected() {
|
||||
let result = index.checked_sub(by).unwrap_or(0);
|
||||
let result = index.saturating_sub(by);
|
||||
if self.state.list.selected() != Some(result) {
|
||||
self.state.list.select(Some(result));
|
||||
self.album = AlbumSelection::initialise(&artists[result].albums);
|
||||
@ -271,10 +271,10 @@ impl AlbumSelection {
|
||||
|
||||
fn increment_by(&mut self, albums: &[Album], by: usize) {
|
||||
if let Some(index) = self.state.list.selected() {
|
||||
let result = index
|
||||
.checked_add(by)
|
||||
.filter(|i| i < &albums.len())
|
||||
.unwrap_or_else(|| albums.len() - 1);
|
||||
let mut result = index.saturating_add(by);
|
||||
if result >= albums.len() {
|
||||
result = albums.len() - 1;
|
||||
}
|
||||
if self.state.list.selected() != Some(result) {
|
||||
self.state.list.select(Some(result));
|
||||
self.track = TrackSelection::initialise(&albums[result].tracks);
|
||||
@ -294,7 +294,7 @@ impl AlbumSelection {
|
||||
|
||||
fn decrement_by(&mut self, albums: &[Album], by: usize) {
|
||||
if let Some(index) = self.state.list.selected() {
|
||||
let result = index.checked_sub(by).unwrap_or(0);
|
||||
let result = index.saturating_sub(by);
|
||||
if self.state.list.selected() != Some(result) {
|
||||
self.state.list.select(Some(result));
|
||||
self.track = TrackSelection::initialise(&albums[result].tracks);
|
||||
@ -345,10 +345,10 @@ impl TrackSelection {
|
||||
|
||||
fn increment_by(&mut self, tracks: &[Track], by: usize) {
|
||||
if let Some(index) = self.state.list.selected() {
|
||||
let result = index
|
||||
.checked_add(by)
|
||||
.filter(|i| i < &tracks.len())
|
||||
.unwrap_or_else(|| tracks.len() - 1);
|
||||
let mut result = index.saturating_add(by);
|
||||
if result >= tracks.len() {
|
||||
result = tracks.len() - 1;
|
||||
}
|
||||
if self.state.list.selected() != Some(result) {
|
||||
self.state.list.select(Some(result));
|
||||
}
|
||||
@ -361,7 +361,7 @@ impl TrackSelection {
|
||||
|
||||
fn decrement_by(&mut self, _tracks: &[Track], by: usize) {
|
||||
if let Some(index) = self.state.list.selected() {
|
||||
let result = index.checked_sub(by).unwrap_or(0);
|
||||
let result = index.saturating_sub(by);
|
||||
if self.state.list.selected() != Some(result) {
|
||||
self.state.list.select(Some(result));
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ impl Ui {
|
||||
area,
|
||||
&mut state.list,
|
||||
);
|
||||
state.height = area.height.checked_sub(2).unwrap_or(0) as usize;
|
||||
state.height = area.height.saturating_sub(2) as usize;
|
||||
}
|
||||
|
||||
fn render_info_widget<B: Backend>(
|
||||
|
Loading…
Reference in New Issue
Block a user