fix: loading icon color & shifting, closes #15
This commit is contained in:
+27
-11
@@ -337,6 +337,7 @@ fn make_chart<'a, T: Stats + Display>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Draw heading bar at top of program, always visible
|
/// Draw heading bar at top of program, always visible
|
||||||
|
/// TODO Should seperate into loading icon/headers/help functions
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub fn heading_bar<B: Backend>(
|
pub fn heading_bar<B: Backend>(
|
||||||
area: Rect,
|
area: Rect,
|
||||||
@@ -347,10 +348,10 @@ pub fn heading_bar<B: Backend>(
|
|||||||
sorted_by: Option<(Header, SortedOrder)>,
|
sorted_by: Option<(Header, SortedOrder)>,
|
||||||
gui_state: &Arc<Mutex<GuiState>>,
|
gui_state: &Arc<Mutex<GuiState>>,
|
||||||
) {
|
) {
|
||||||
let block = || Block::default().style(Style::default().bg(Color::Magenta).fg(Color::Black));
|
let block = |fg: Color| Block::default().style(Style::default().bg(Color::Magenta).fg(fg));
|
||||||
let info_visible = gui_state.lock().show_help;
|
let info_visible = gui_state.lock().show_help;
|
||||||
|
|
||||||
f.render_widget(block(), area);
|
f.render_widget(block(Color::Black), area);
|
||||||
|
|
||||||
// Generate a bloack for the header, if the header is currently being used to sort a column, then highlight it white
|
// Generate a bloack for the header, if the header is currently being used to sort a column, then highlight it white
|
||||||
let header_block = |x: &Header| {
|
let header_block = |x: &Header| {
|
||||||
@@ -380,8 +381,7 @@ pub fn heading_bar<B: Backend>(
|
|||||||
let block = header_block(header);
|
let block = header_block(header);
|
||||||
let text = match header {
|
let text = match header {
|
||||||
Header::State => format!(
|
Header::State => format!(
|
||||||
" {}{:>width$}{ic}",
|
"{:>width$}{ic}",
|
||||||
loading_icon,
|
|
||||||
header,
|
header,
|
||||||
ic = block.1,
|
ic = block.1,
|
||||||
width = width - block.2,
|
width = width - block.2,
|
||||||
@@ -393,7 +393,6 @@ pub fn heading_bar<B: Backend>(
|
|||||||
ic = block.1,
|
ic = block.1,
|
||||||
width = width - block.2
|
width = width - block.2
|
||||||
),
|
),
|
||||||
|
|
||||||
_ => format!(
|
_ => format!(
|
||||||
"{}{:>width$}{ic}",
|
"{}{:>width$}{ic}",
|
||||||
MARGIN,
|
MARGIN,
|
||||||
@@ -438,6 +437,7 @@ pub fn heading_bar<B: Backend>(
|
|||||||
let column_width = if column_width > 0 { column_width } else { 1 };
|
let column_width = if column_width > 0 { column_width } else { 1 };
|
||||||
let splits = if has_containers {
|
let splits = if has_containers {
|
||||||
vec![
|
vec![
|
||||||
|
Constraint::Min(2),
|
||||||
Constraint::Min(column_width.try_into().unwrap_or_default()),
|
Constraint::Min(column_width.try_into().unwrap_or_default()),
|
||||||
Constraint::Min(info_width.try_into().unwrap_or_default()),
|
Constraint::Min(info_width.try_into().unwrap_or_default()),
|
||||||
]
|
]
|
||||||
@@ -450,12 +450,20 @@ pub fn heading_bar<B: Backend>(
|
|||||||
.constraints(splits.as_ref())
|
.constraints(splits.as_ref())
|
||||||
.split(area);
|
.split(area);
|
||||||
if has_containers {
|
if has_containers {
|
||||||
let container_splits = header_data.iter().map(|i| i.2).collect::<Vec<_>>();
|
// Draw loading icon, or not, and a prefix with a single space
|
||||||
|
let loading_icon = format!("{:>2}", loading_icon);
|
||||||
|
let loading_paragraph = Paragraph::new(loading_icon)
|
||||||
|
.block(block(Color::White))
|
||||||
|
.alignment(Alignment::Center);
|
||||||
|
f.render_widget(loading_paragraph, split_bar[0]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let container_splits = header_data.iter().map(|i| i.2).collect::<Vec<_>>();
|
||||||
let headers_section = Layout::default()
|
let headers_section = Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints(container_splits.as_ref())
|
.constraints(container_splits.as_ref())
|
||||||
.split(split_bar[0]);
|
.split(split_bar[1]);
|
||||||
|
|
||||||
// draw the actual header blocks
|
// draw the actual header blocks
|
||||||
for (index, (paragraph, header, _)) in header_data.into_iter().enumerate() {
|
for (index, (paragraph, header, _)) in header_data.into_iter().enumerate() {
|
||||||
@@ -465,13 +473,21 @@ pub fn heading_bar<B: Backend>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let paragraph = Paragraph::new(info_text)
|
/// show/hide help
|
||||||
.block(block())
|
let color = if info_visible {
|
||||||
|
Color::White
|
||||||
|
} else {
|
||||||
|
Color::Black
|
||||||
|
};
|
||||||
|
let help_paragraph = Paragraph::new(info_text)
|
||||||
|
.block(block(color))
|
||||||
.alignment(Alignment::Right);
|
.alignment(Alignment::Right);
|
||||||
|
|
||||||
// If no containers, don't display the headers, could maybe do this first?
|
// If no containers, don't display the headers, could maybe do this first?
|
||||||
let index = if has_containers { 1 } else { 0 };
|
let help_index = if has_containers { 2 } else { 0 };
|
||||||
f.render_widget(paragraph, split_bar[index]);
|
// render help info
|
||||||
|
|
||||||
|
f.render_widget(help_paragraph, split_bar[help_index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// From a given &str, return the maximum number of chars on a single line
|
/// From a given &str, return the maximum number of chars on a single line
|
||||||
|
|||||||
+3
-1
@@ -59,6 +59,7 @@ pub enum BoxLocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BoxLocation {
|
impl BoxLocation {
|
||||||
|
/// Screen is divided into 3x3 sections
|
||||||
pub const fn get_indexes(self) -> (usize, usize) {
|
pub const fn get_indexes(self) -> (usize, usize) {
|
||||||
match self {
|
match self {
|
||||||
Self::TopLeft => (0, 0),
|
Self::TopLeft => (0, 0),
|
||||||
@@ -258,9 +259,10 @@ impl GuiState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// If is_loading has any entries, return the current loading_icon, else an emtpy string
|
/// If is_loading has any entries, return the current loading_icon, else an emtpy string
|
||||||
|
// Option<String>?
|
||||||
pub fn get_loading(&mut self) -> String {
|
pub fn get_loading(&mut self) -> String {
|
||||||
if self.is_loading.is_empty() {
|
if self.is_loading.is_empty() {
|
||||||
String::new()
|
String::from(" ")
|
||||||
} else {
|
} else {
|
||||||
self.loading_icon.to_string()
|
self.loading_icon.to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user