2019-09-17 05:53:20 +02:00
|
|
|
use tui_temp_fork::{
|
|
|
|
backend,
|
2019-09-11 05:37:20 +02:00
|
|
|
layout::{Constraint, Direction, Layout},
|
2019-09-13 22:15:00 +02:00
|
|
|
style::{Color, Modifier, Style},
|
2019-09-11 05:37:20 +02:00
|
|
|
widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Row, Table, Widget},
|
|
|
|
Terminal,
|
|
|
|
};
|
2019-09-12 04:10:49 +02:00
|
|
|
|
2019-09-15 07:29:49 +02:00
|
|
|
use crate::{app, utils::error};
|
2019-09-15 03:48:29 +02:00
|
|
|
|
2019-09-25 22:43:13 +02:00
|
|
|
const COLOUR_LIST : [Color; 6] = [
|
|
|
|
Color::Red,
|
|
|
|
Color::Green,
|
|
|
|
Color::LightYellow,
|
|
|
|
Color::LightBlue,
|
|
|
|
Color::LightCyan,
|
|
|
|
Color::LightMagenta,
|
|
|
|
];
|
2019-09-12 05:15:25 +02:00
|
|
|
const TEXT_COLOUR : Color = Color::Gray;
|
2019-09-12 05:23:14 +02:00
|
|
|
const GRAPH_COLOUR : Color = Color::Gray;
|
|
|
|
const BORDER_STYLE_COLOUR : Color = Color::Gray;
|
2019-09-17 04:39:57 +02:00
|
|
|
const HIGHLIGHTED_BORDER_STYLE_COLOUR : Color = Color::LightBlue;
|
2019-09-12 04:10:49 +02:00
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct CanvasData {
|
2019-09-15 06:06:57 +02:00
|
|
|
pub rx_display : String,
|
|
|
|
pub tx_display : String,
|
2019-09-15 03:48:29 +02:00
|
|
|
pub network_data_rx : Vec<(f64, f64)>,
|
|
|
|
pub network_data_tx : Vec<(f64, f64)>,
|
2019-09-12 04:10:49 +02:00
|
|
|
pub disk_data : Vec<Vec<String>>,
|
|
|
|
pub temp_sensor_data : Vec<Vec<String>>,
|
|
|
|
pub process_data : Vec<Vec<String>>,
|
|
|
|
pub mem_data : Vec<(f64, f64)>,
|
|
|
|
pub swap_data : Vec<(f64, f64)>,
|
|
|
|
pub cpu_data : Vec<(String, Vec<(f64, f64)>)>,
|
|
|
|
}
|
|
|
|
|
2019-09-17 05:53:20 +02:00
|
|
|
pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state : &mut app::App, canvas_data : &CanvasData) -> error::Result<()> {
|
2019-09-12 05:23:14 +02:00
|
|
|
let border_style : Style = Style::default().fg(BORDER_STYLE_COLOUR);
|
2019-09-17 04:39:57 +02:00
|
|
|
let highlighted_border_style : Style = Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR);
|
2019-09-12 05:23:14 +02:00
|
|
|
|
2019-09-12 04:10:49 +02:00
|
|
|
terminal.draw(|mut f| {
|
2019-09-16 22:18:42 +02:00
|
|
|
//debug!("Drawing!");
|
2019-09-12 04:10:49 +02:00
|
|
|
let vertical_chunks = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(1)
|
2019-09-15 07:29:49 +02:00
|
|
|
.constraints([Constraint::Percentage(34), Constraint::Percentage(34), Constraint::Percentage(33)].as_ref())
|
2019-09-12 04:10:49 +02:00
|
|
|
.split(f.size());
|
2019-09-12 05:15:25 +02:00
|
|
|
|
2019-09-12 04:10:49 +02:00
|
|
|
let middle_chunks = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.margin(0)
|
2019-09-16 22:18:42 +02:00
|
|
|
.constraints([Constraint::Percentage(60), Constraint::Percentage(40)].as_ref())
|
2019-09-12 04:10:49 +02:00
|
|
|
.split(vertical_chunks[1]);
|
2019-09-15 03:48:29 +02:00
|
|
|
|
|
|
|
let middle_divided_chunk_2 = Layout::default()
|
2019-09-12 04:10:49 +02:00
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(0)
|
|
|
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
|
|
|
.split(middle_chunks[1]);
|
2019-09-12 05:15:25 +02:00
|
|
|
|
2019-09-12 04:10:49 +02:00
|
|
|
let bottom_chunks = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.margin(0)
|
|
|
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
|
|
|
.split(vertical_chunks[2]);
|
|
|
|
|
|
|
|
// Set up blocks and their components
|
|
|
|
// CPU usage graph
|
|
|
|
{
|
2019-09-13 22:15:00 +02:00
|
|
|
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
|
2019-09-25 22:43:13 +02:00
|
|
|
let y_axis = Axis::default()
|
|
|
|
.style(Style::default().fg(GRAPH_COLOUR))
|
|
|
|
.bounds([-0.5, 100.5])
|
|
|
|
.labels(&["0%", "100%"]);
|
2019-09-12 04:10:49 +02:00
|
|
|
|
|
|
|
let mut dataset_vector : Vec<Dataset> = Vec::new();
|
2019-09-15 07:29:49 +02:00
|
|
|
|
2019-09-12 04:10:49 +02:00
|
|
|
for (i, cpu) in canvas_data.cpu_data.iter().enumerate() {
|
2019-09-15 07:29:49 +02:00
|
|
|
let mut avg_cpu_exist_offset = 0;
|
2019-09-16 22:18:42 +02:00
|
|
|
if app_state.show_average_cpu {
|
2019-09-15 07:29:49 +02:00
|
|
|
if i == 0 {
|
|
|
|
// Skip, we want to render the average cpu last!
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
avg_cpu_exist_offset = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-12 04:10:49 +02:00
|
|
|
dataset_vector.push(
|
|
|
|
Dataset::default()
|
|
|
|
.name(&cpu.0)
|
2019-09-25 07:54:38 +02:00
|
|
|
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
2019-09-15 07:29:49 +02:00
|
|
|
.style(Style::default().fg(COLOUR_LIST[i - avg_cpu_exist_offset % COLOUR_LIST.len()]))
|
2019-09-12 04:10:49 +02:00
|
|
|
.data(&(cpu.1)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-16 22:18:42 +02:00
|
|
|
if !canvas_data.cpu_data.is_empty() && app_state.show_average_cpu {
|
2019-09-15 07:29:49 +02:00
|
|
|
dataset_vector.push(
|
|
|
|
Dataset::default()
|
|
|
|
.name(&canvas_data.cpu_data[0].0)
|
2019-09-25 07:54:38 +02:00
|
|
|
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
2019-09-15 07:29:49 +02:00
|
|
|
.style(Style::default().fg(COLOUR_LIST[canvas_data.cpu_data.len() - 1 % COLOUR_LIST.len()]))
|
|
|
|
.data(&(canvas_data.cpu_data[0].1)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-12 04:10:49 +02:00
|
|
|
Chart::default()
|
2019-09-17 04:39:57 +02:00
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.title("CPU Usage")
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_application_position {
|
|
|
|
app::ApplicationPosition::CPU => highlighted_border_style,
|
|
|
|
_ => border_style,
|
|
|
|
}),
|
|
|
|
)
|
2019-09-12 04:10:49 +02:00
|
|
|
.x_axis(x_axis)
|
|
|
|
.y_axis(y_axis)
|
|
|
|
.datasets(&dataset_vector)
|
2019-09-12 05:15:25 +02:00
|
|
|
.render(&mut f, vertical_chunks[0]);
|
2019-09-12 04:10:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Memory usage graph
|
|
|
|
{
|
2019-09-13 22:15:00 +02:00
|
|
|
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
|
2019-09-25 22:43:13 +02:00
|
|
|
let y_axis = Axis::default()
|
|
|
|
.style(Style::default().fg(GRAPH_COLOUR))
|
|
|
|
.bounds([-0.5, 100.5])
|
|
|
|
.labels(&["0%", "100%"]); // Offset as the zero value isn't drawn otherwise...
|
2019-09-25 08:13:10 +02:00
|
|
|
let mem_name = "RAM:".to_string() + &format!("{:3}%", (canvas_data.mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64));
|
|
|
|
let swap_name = "SWP:".to_string() + &format!("{:3}%", (canvas_data.swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64));
|
|
|
|
|
|
|
|
let mut mem_canvas_vec : Vec<Dataset> = vec![Dataset::default()
|
|
|
|
.name(&mem_name)
|
|
|
|
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
|
|
|
.style(Style::default().fg(Color::LightBlue))
|
|
|
|
.data(&canvas_data.mem_data)];
|
|
|
|
|
2019-09-25 08:45:09 +02:00
|
|
|
if !(&canvas_data.swap_data).is_empty() && (&canvas_data.swap_data).last().unwrap().1 >= 0.0 {
|
2019-09-25 08:13:10 +02:00
|
|
|
mem_canvas_vec.push(
|
|
|
|
Dataset::default()
|
|
|
|
.name(&swap_name)
|
|
|
|
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
|
|
|
.style(Style::default().fg(Color::LightYellow))
|
|
|
|
.data(&canvas_data.swap_data),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-12 04:10:49 +02:00
|
|
|
Chart::default()
|
2019-09-17 04:39:57 +02:00
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.title("Memory Usage")
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_application_position {
|
|
|
|
app::ApplicationPosition::MEM => highlighted_border_style,
|
|
|
|
_ => border_style,
|
|
|
|
}),
|
|
|
|
)
|
2019-09-12 04:10:49 +02:00
|
|
|
.x_axis(x_axis)
|
|
|
|
.y_axis(y_axis)
|
2019-09-25 08:13:10 +02:00
|
|
|
.datasets(&mem_canvas_vec)
|
2019-09-12 05:15:25 +02:00
|
|
|
.render(&mut f, middle_chunks[0]);
|
2019-09-12 04:10:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Temperature table
|
2019-09-14 22:46:14 +02:00
|
|
|
{
|
2019-09-25 22:43:13 +02:00
|
|
|
let num_rows = i64::from(middle_divided_chunk_2[0].height) - 3;
|
|
|
|
let start_position = get_start_position(
|
|
|
|
num_rows,
|
|
|
|
&(app_state.scroll_direction),
|
|
|
|
&mut app_state.previous_temp_position,
|
|
|
|
&mut app_state.currently_selected_temperature_position,
|
|
|
|
);
|
|
|
|
|
|
|
|
let sliced_vec : Vec<Vec<String>> = (&canvas_data.temp_sensor_data[start_position as usize..]).to_vec();
|
|
|
|
let mut disk_counter = 0;
|
|
|
|
|
|
|
|
let temperature_rows = sliced_vec.iter().map(|disk| {
|
|
|
|
Row::StyledData(
|
|
|
|
disk.iter(),
|
|
|
|
if disk_counter == app_state.currently_selected_temperature_position - start_position {
|
|
|
|
// TODO: This is what controls the highlighting!
|
|
|
|
disk_counter = -1;
|
|
|
|
Style::default().fg(Color::Black).bg(Color::Cyan)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if disk_counter >= 0 {
|
|
|
|
disk_counter += 1;
|
|
|
|
}
|
|
|
|
Style::default().fg(TEXT_COLOUR)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2019-09-15 03:48:29 +02:00
|
|
|
let width = f64::from(middle_divided_chunk_2[0].width);
|
2019-09-14 22:46:14 +02:00
|
|
|
Table::new(["Sensor", "Temp"].iter(), temperature_rows)
|
2019-09-17 04:39:57 +02:00
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.title("Temperatures")
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_application_position {
|
|
|
|
app::ApplicationPosition::TEMP => highlighted_border_style,
|
|
|
|
_ => border_style,
|
|
|
|
}),
|
|
|
|
)
|
2019-09-14 22:46:14 +02:00
|
|
|
.header_style(Style::default().fg(Color::LightBlue))
|
|
|
|
.widths(&[(width * 0.45) as u16, (width * 0.4) as u16])
|
2019-09-15 03:48:29 +02:00
|
|
|
.render(&mut f, middle_divided_chunk_2[0]);
|
2019-09-14 22:46:14 +02:00
|
|
|
}
|
2019-09-12 04:10:49 +02:00
|
|
|
|
2019-09-14 22:46:14 +02:00
|
|
|
// Disk usage table
|
|
|
|
{
|
2019-09-25 22:43:13 +02:00
|
|
|
let num_rows = i64::from(middle_divided_chunk_2[1].height) - 3;
|
|
|
|
let start_position = get_start_position(
|
|
|
|
num_rows,
|
|
|
|
&(app_state.scroll_direction),
|
|
|
|
&mut app_state.previous_disk_position,
|
|
|
|
&mut app_state.currently_selected_disk_position,
|
|
|
|
);
|
|
|
|
|
|
|
|
let sliced_vec : Vec<Vec<String>> = (&canvas_data.disk_data[start_position as usize..]).to_vec();
|
|
|
|
let mut disk_counter = 0;
|
|
|
|
|
|
|
|
let disk_rows = sliced_vec.iter().map(|disk| {
|
|
|
|
Row::StyledData(
|
|
|
|
disk.iter(),
|
|
|
|
if disk_counter == app_state.currently_selected_disk_position - start_position {
|
|
|
|
// TODO: This is what controls the highlighting!
|
|
|
|
disk_counter = -1;
|
|
|
|
Style::default().fg(Color::Black).bg(Color::Cyan)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if disk_counter >= 0 {
|
|
|
|
disk_counter += 1;
|
|
|
|
}
|
|
|
|
Style::default().fg(TEXT_COLOUR)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2019-09-17 04:39:57 +02:00
|
|
|
// TODO: We may have to dynamically remove some of these table elements based on size...
|
2019-09-15 03:48:29 +02:00
|
|
|
let width = f64::from(middle_divided_chunk_2[1].width);
|
2019-09-15 20:16:18 +02:00
|
|
|
Table::new(["Disk", "Mount", "Used", "Total", "Free", "R/s", "W/s"].iter(), disk_rows)
|
2019-09-17 04:39:57 +02:00
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.title("Disk Usage")
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_application_position {
|
|
|
|
app::ApplicationPosition::DISK => highlighted_border_style,
|
|
|
|
_ => border_style,
|
|
|
|
}),
|
|
|
|
)
|
2019-09-14 22:46:14 +02:00
|
|
|
.header_style(Style::default().fg(Color::LightBlue).modifier(Modifier::BOLD))
|
2019-09-15 07:32:08 +02:00
|
|
|
.widths(&[
|
2019-09-17 02:33:25 +02:00
|
|
|
(width * 0.18).floor() as u16,
|
|
|
|
(width * 0.14).floor() as u16,
|
|
|
|
(width * 0.11).floor() as u16,
|
|
|
|
(width * 0.11).floor() as u16,
|
|
|
|
(width * 0.11).floor() as u16,
|
|
|
|
(width * 0.11).floor() as u16,
|
|
|
|
(width * 0.11).floor() as u16,
|
2019-09-15 07:32:08 +02:00
|
|
|
])
|
2019-09-15 03:48:29 +02:00
|
|
|
.render(&mut f, middle_divided_chunk_2[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Network graph
|
|
|
|
{
|
|
|
|
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
|
2019-09-25 22:43:13 +02:00
|
|
|
let y_axis = Axis::default()
|
|
|
|
.style(Style::default().fg(GRAPH_COLOUR))
|
|
|
|
.bounds([-0.5, 1_000_000.5])
|
|
|
|
.labels(&["0GB", "1GB"]);
|
2019-09-15 03:48:29 +02:00
|
|
|
Chart::default()
|
2019-09-17 04:39:57 +02:00
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.title("Network")
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_application_position {
|
|
|
|
app::ApplicationPosition::NETWORK => highlighted_border_style,
|
|
|
|
_ => border_style,
|
|
|
|
}),
|
|
|
|
)
|
2019-09-15 03:48:29 +02:00
|
|
|
.x_axis(x_axis)
|
|
|
|
.y_axis(y_axis)
|
|
|
|
.datasets(&[
|
|
|
|
Dataset::default()
|
2019-09-15 06:06:57 +02:00
|
|
|
.name(&(canvas_data.rx_display))
|
2019-09-25 07:54:38 +02:00
|
|
|
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
2019-09-15 03:48:29 +02:00
|
|
|
.style(Style::default().fg(Color::LightBlue))
|
|
|
|
.data(&canvas_data.network_data_rx),
|
|
|
|
Dataset::default()
|
2019-09-15 06:06:57 +02:00
|
|
|
.name(&(canvas_data.tx_display))
|
2019-09-25 07:54:38 +02:00
|
|
|
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
2019-09-15 03:48:29 +02:00
|
|
|
.style(Style::default().fg(Color::LightYellow))
|
|
|
|
.data(&canvas_data.network_data_tx),
|
|
|
|
])
|
|
|
|
.render(&mut f, bottom_chunks[0]);
|
2019-09-14 22:46:14 +02:00
|
|
|
}
|
2019-09-12 04:10:49 +02:00
|
|
|
|
|
|
|
// Processes table
|
2019-09-14 22:46:14 +02:00
|
|
|
{
|
|
|
|
let width = f64::from(bottom_chunks[1].width);
|
2019-09-16 22:18:42 +02:00
|
|
|
|
|
|
|
// Admittedly this is kinda a hack... but we need to:
|
|
|
|
// * Scroll
|
|
|
|
// * Show/hide elements based on scroll position
|
|
|
|
// As such, we use a process_counter to know when we've hit the process we've currently scrolled to. We also need to move the list - we can
|
|
|
|
// do so by hiding some elements!
|
|
|
|
let num_rows = i64::from(bottom_chunks[1].height) - 3;
|
|
|
|
|
2019-09-25 22:43:13 +02:00
|
|
|
let start_position = get_start_position(
|
|
|
|
num_rows,
|
|
|
|
&(app_state.scroll_direction),
|
|
|
|
&mut app_state.previous_process_position,
|
|
|
|
&mut app_state.currently_selected_process_position,
|
|
|
|
);
|
2019-09-16 22:18:42 +02:00
|
|
|
|
2019-09-17 01:05:44 +02:00
|
|
|
/*debug!(
|
2019-09-17 00:47:49 +02:00
|
|
|
"START POSN: {}, PREV POSN: {}, CURRENT SELECTED POSN: {}, NUM ROWS: {}",
|
|
|
|
start_position, app_state.previous_process_position, app_state.currently_selected_process_position, num_rows
|
2019-09-17 01:05:44 +02:00
|
|
|
);*/
|
2019-09-16 22:18:42 +02:00
|
|
|
|
|
|
|
let sliced_vec : Vec<Vec<String>> = (&canvas_data.process_data[start_position as usize..]).to_vec();
|
2019-09-25 22:43:13 +02:00
|
|
|
let mut process_counter = 0;
|
2019-09-16 22:18:42 +02:00
|
|
|
|
|
|
|
let process_rows = sliced_vec.iter().map(|process| {
|
|
|
|
Row::StyledData(
|
|
|
|
process.iter(),
|
|
|
|
if process_counter == app_state.currently_selected_process_position - start_position {
|
|
|
|
// TODO: This is what controls the highlighting!
|
|
|
|
process_counter = -1;
|
|
|
|
Style::default().fg(Color::Black).bg(Color::Cyan)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if process_counter >= 0 {
|
|
|
|
process_counter += 1;
|
|
|
|
}
|
|
|
|
Style::default().fg(TEXT_COLOUR)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
2019-09-14 22:46:14 +02:00
|
|
|
Table::new(["PID", "Name", "CPU%", "Mem%"].iter(), process_rows)
|
2019-09-17 04:39:57 +02:00
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.title("Processes")
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_application_position {
|
|
|
|
app::ApplicationPosition::PROCESS => highlighted_border_style,
|
|
|
|
_ => border_style,
|
|
|
|
}),
|
|
|
|
)
|
2019-09-14 22:46:14 +02:00
|
|
|
.header_style(Style::default().fg(Color::LightBlue))
|
|
|
|
.widths(&[(width * 0.2) as u16, (width * 0.35) as u16, (width * 0.2) as u16, (width * 0.2) as u16])
|
|
|
|
.render(&mut f, bottom_chunks[1]);
|
|
|
|
}
|
2019-09-12 04:10:49 +02:00
|
|
|
})?;
|
|
|
|
|
2019-09-16 22:18:42 +02:00
|
|
|
//debug!("Finished drawing.");
|
|
|
|
|
2019-09-12 04:10:49 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
2019-09-25 22:43:13 +02:00
|
|
|
|
|
|
|
fn get_start_position(
|
|
|
|
num_rows : i64, scroll_direction : &app::ScrollDirection, previous_position : &mut i64, currently_selected_position : &mut i64,
|
|
|
|
) -> i64 {
|
|
|
|
match scroll_direction {
|
|
|
|
app::ScrollDirection::DOWN => {
|
|
|
|
if *currently_selected_position < num_rows {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
else if *currently_selected_position - num_rows < *previous_position {
|
|
|
|
*previous_position
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*previous_position = *currently_selected_position - num_rows + 1;
|
|
|
|
*previous_position
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app::ScrollDirection::UP => {
|
|
|
|
if *currently_selected_position == *previous_position - 1 {
|
|
|
|
*previous_position = if *previous_position > 0 { *previous_position - 1 } else { 0 };
|
|
|
|
*previous_position
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*previous_position
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|