From 4628803b2b9fe63522d033b192763ed6ff5b57dd Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Wed, 17 Apr 2024 15:10:33 +0000 Subject: [PATCH] fix: header display when width changes Only show header when the cumulative header widths is less than the header section width --- src/ui/draw_blocks.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ui/draw_blocks.rs b/src/ui/draw_blocks.rs index a48312d..f37fd17 100644 --- a/src/ui/draw_blocks.rs +++ b/src/ui/draw_blocks.rs @@ -498,13 +498,7 @@ pub fn heading_bar( (Header::Tx, data.columns.net_tx.1), ]; - let header_data = header_meta - .iter() - .map(|i| { - let header_block = gen_header(&i.0, i.1.into()); - (header_block.0, i.0, Constraint::Max(header_block.1)) - }) - .collect::>(); + // Need to add widths to this let suffix = if data.help_visible { "exit" } else { "show" }; let info_text = format!("( h ) {suffix} help {MARGIN}",); @@ -526,7 +520,26 @@ pub fn heading_bar( .direction(Direction::Horizontal) .constraints(splits) .split(area); + if data.has_containers { + let header_section_width = split_bar[1].width; + + let mut counter = 0; + + // Only show a header if the header cumulative header width is less than the header section width + let header_data = header_meta + .iter() + .filter_map(|i| { + let header_block = gen_header(&i.0, i.1.into()); + counter += header_block.1; + if counter <= header_section_width { + Some((header_block.0, i.0, Constraint::Max(header_block.1))) + } else { + None + } + }) + .collect::>(); + // Draw loading icon, or not, and a prefix with a single space let loading_paragraph = Paragraph::new(format!("{:>2}", data.loading_icon)) .block(block(Color::White)) @@ -539,7 +552,6 @@ pub fn heading_bar( .constraints(container_splits) .split(split_bar[1]); - // draw the actual header blocks for (index, (paragraph, header, _)) in header_data.into_iter().enumerate() { let rect = headers_section[index]; gui_state