Skip to content

Commit

Permalink
add scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Jan 12, 2025
1 parent afb75fc commit e2f41dc
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions oryx-tui/src/section/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ratatui::{
text::Line,
widgets::{
Bar, BarChart, BarGroup, Block, BorderType, Borders, Cell, Clear, HighlightSpacing,
Padding, Row, Table,
Padding, Row, Scrollbar, ScrollbarOrientation, ScrollbarState, Table,
},
Frame,
};
Expand Down Expand Up @@ -125,7 +125,6 @@ impl Metrics {
self.metrics[self.state.offset..self.state.offset + self.window_height].to_vec()
};

// for (index, port_count_metric) in self.metrics[self.state.offset..].iter().enumerate() {
for (index, port_count_metric) in metrics_to_display.iter().enumerate() {
let metric = { port_count_metric.lock().unwrap().clone() };

Expand Down Expand Up @@ -179,6 +178,23 @@ impl Metrics {
}),
);
}

if self.metrics.len() > self.window_height {
let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
.begin_symbol(Some("↑"))
.end_symbol(Some("↓"));

let mut scrollbar_state = ScrollbarState::new(self.metrics.len())
.position(self.state.offset * self.window_height);
frame.render_stateful_widget(
scrollbar,
block.inner(Margin {
vertical: 1,
horizontal: 0,
}),
&mut scrollbar_state,
);
}
}

pub fn handle_keys(&mut self, key_event: KeyEvent) {
Expand Down

0 comments on commit e2f41dc

Please sign in to comment.