change: hide table gap if widget height is small

This commit is contained in:
Clement Tsang 2020-05-09 16:23:15 -04:00 committed by GitHub
parent 2e4d6a34aa
commit 90272777f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 11 deletions

View File

@ -9,13 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features ### Features
- ~~[#114](https://github.com/ClementTsang/bottom/pull/114): Process state per process (originally in 0.4.0, moved to later).~~ - TODO: ~~[#114](https://github.com/ClementTsang/bottom/pull/114): Process state per process (originally in 0.4.0, moved to later).~~
- Moving down the CPU list will show only the corresponding graph. - TODO: ~~Moving down the CPU list will show only the corresponding graph.~~
### Changes ### Changes
- Automatically hide time axis labels if the window gets too small. - Automatically hide time axis labels if the widget gets too small.
- Automatically hide table gap if the widget gets too small.
### Bug Fixes ### Bug Fixes

View File

@ -123,7 +123,7 @@ impl CpuGraphWidget for Painter {
cpu_widget_state.autohide_timer = None; cpu_widget_state.autohide_timer = None;
Axis::default().bounds([-(cpu_widget_state.current_display_time as f64), 0.0]) Axis::default().bounds([-(cpu_widget_state.current_display_time as f64), 0.0])
} }
} else if draw_loc.height < 7 { } else if draw_loc.height < TIME_LABEL_HEIGHT_LIMIT {
Axis::default().bounds([-(cpu_widget_state.current_display_time as f64), 0.0]) Axis::default().bounds([-(cpu_widget_state.current_display_time as f64), 0.0])
} else { } else {
Axis::default() Axis::default()

View File

@ -51,9 +51,13 @@ impl DiskTableWidget for Painter {
disk_table_state.select(Some( disk_table_state.select(Some(
(disk_widget_state.scroll_state.current_scroll_position - start_position) as usize, (disk_widget_state.scroll_state.current_scroll_position - start_position) as usize,
)); ));
let sliced_vec = &mut disk_data[start_position as usize..]; let sliced_vec = &mut disk_data[start_position as usize..];
let disk_rows = sliced_vec.iter().map(|disk| Row::Data(disk.iter())); let disk_rows = sliced_vec.iter().map(|disk| Row::Data(disk.iter()));
let table_gap = if draw_loc.height < TABLE_GAP_HEIGHT_LIMIT {
0
} else {
app_state.app_config_fields.table_gap
};
// Calculate widths // Calculate widths
// TODO: [PRETTY] Ellipsis on strings? // TODO: [PRETTY] Ellipsis on strings?
@ -123,7 +127,7 @@ impl DiskTableWidget for Painter {
.map(|calculated_width| Constraint::Length(*calculated_width as u16)) .map(|calculated_width| Constraint::Length(*calculated_width as u16))
.collect::<Vec<_>>()), .collect::<Vec<_>>()),
) )
.header_gap(app_state.app_config_fields.table_gap), .header_gap(table_gap),
margined_draw_loc[0], margined_draw_loc[0],
disk_table_state, disk_table_state,
); );

View File

@ -44,7 +44,7 @@ impl MemGraphWidget for Painter {
mem_widget_state.autohide_timer = None; mem_widget_state.autohide_timer = None;
Axis::default().bounds([-(mem_widget_state.current_display_time as f64), 0.0]) Axis::default().bounds([-(mem_widget_state.current_display_time as f64), 0.0])
} }
} else if draw_loc.height < 7 { } else if draw_loc.height < TIME_LABEL_HEIGHT_LIMIT {
Axis::default().bounds([-(mem_widget_state.current_display_time as f64), 0.0]) Axis::default().bounds([-(mem_widget_state.current_display_time as f64), 0.0])
} else { } else {
Axis::default() Axis::default()

View File

@ -94,7 +94,7 @@ impl NetworkGraphWidget for Painter {
Axis::default() Axis::default()
.bounds([-(network_widget_state.current_display_time as f64), 0.0]) .bounds([-(network_widget_state.current_display_time as f64), 0.0])
} }
} else if draw_loc.height < 7 { } else if draw_loc.height < TIME_LABEL_HEIGHT_LIMIT {
Axis::default().bounds([-(network_widget_state.current_display_time as f64), 0.0]) Axis::default().bounds([-(network_widget_state.current_display_time as f64), 0.0])
} else { } else {
Axis::default() Axis::default()

View File

@ -104,6 +104,11 @@ impl ProcessTableWidget for Painter {
(proc_widget_state.scroll_state.current_scroll_position - start_position) (proc_widget_state.scroll_state.current_scroll_position - start_position)
as usize, as usize,
)); ));
let table_gap = if draw_loc.height < TABLE_GAP_HEIGHT_LIMIT {
0
} else {
app_state.app_config_fields.table_gap
};
// Draw! // Draw!
let is_proc_widget_grouped = proc_widget_state.is_grouped; let is_proc_widget_grouped = proc_widget_state.is_grouped;
@ -253,7 +258,7 @@ impl ProcessTableWidget for Painter {
}) })
.collect::<Vec<_>>()), .collect::<Vec<_>>()),
) )
.header_gap(app_state.app_config_fields.table_gap), .header_gap(table_gap),
margined_draw_loc[0], margined_draw_loc[0],
proc_table_state, proc_table_state,
); );

View File

@ -52,9 +52,13 @@ impl TempTableWidget for Painter {
temp_table_state.select(Some( temp_table_state.select(Some(
(temp_widget_state.scroll_state.current_scroll_position - start_position) as usize, (temp_widget_state.scroll_state.current_scroll_position - start_position) as usize,
)); ));
let sliced_vec = &temp_sensor_data[start_position as usize..]; let sliced_vec = &temp_sensor_data[start_position as usize..];
let temperature_rows = sliced_vec.iter().map(|temp_row| Row::Data(temp_row.iter())); let temperature_rows = sliced_vec.iter().map(|temp_row| Row::Data(temp_row.iter()));
let table_gap = if draw_loc.height < TABLE_GAP_HEIGHT_LIMIT {
0
} else {
app_state.app_config_fields.table_gap
};
// Calculate widths // Calculate widths
let width = f64::from(draw_loc.width); let width = f64::from(draw_loc.width);
@ -123,7 +127,7 @@ impl TempTableWidget for Painter {
.map(|calculated_width| Constraint::Length(*calculated_width as u16)) .map(|calculated_width| Constraint::Length(*calculated_width as u16))
.collect::<Vec<_>>()), .collect::<Vec<_>>()),
) )
.header_gap(app_state.app_config_fields.table_gap), .header_gap(table_gap),
margined_draw_loc[0], margined_draw_loc[0],
temp_table_state, temp_table_state,
); );

View File

@ -23,6 +23,10 @@ pub const NUM_COLOURS: i32 = 256;
// The minimum threshold when resizing tables // The minimum threshold when resizing tables
pub const FORCE_MIN_THRESHOLD: usize = 5; pub const FORCE_MIN_THRESHOLD: usize = 5;
// Limits for when we should stop showing table gaps/labels (anything less means not shown)
pub const TABLE_GAP_HEIGHT_LIMIT: u16 = 7;
pub const TIME_LABEL_HEIGHT_LIMIT: u16 = 7;
// Side borders // Side borders
lazy_static! { lazy_static! {
pub static ref SIDE_BORDERS: tui::widgets::Borders = pub static ref SIDE_BORDERS: tui::widgets::Borders =