Skip to content

Commit

Permalink
fix: header display when width changes
Browse files Browse the repository at this point in the history
Only show header when the cumulative header widths is less than the header section width
  • Loading branch information
mrjackwills committed Apr 17, 2024
1 parent 07e293a commit 4628803
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/ui/draw_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
// Need to add widths to this

let suffix = if data.help_visible { "exit" } else { "show" };
let info_text = format!("( h ) {suffix} help {MARGIN}",);
Expand All @@ -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::<Vec<_>>();

// 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))
Expand All @@ -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
Expand Down

0 comments on commit 4628803

Please sign in to comment.