From 7a67ba051c569b4c38accada7110ea0d4526fc32 Mon Sep 17 00:00:00 2001 From: Philipp Reiter Date: Mon, 29 Apr 2024 21:26:28 +0200 Subject: [PATCH] fix: Apply base style to truncated elements --- CHANGELOG.md | 3 +++ src/widget.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 914c16c..e25262e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +0.8.3 - +=================== +- Fix: Apply base style to truncated items Released -------- diff --git a/src/widget.rs b/src/widget.rs index c7d17a7..04f00c9 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -177,10 +177,10 @@ impl<'a, T: ListableWidget> StatefulWidget for List<'a, T> { }; if state.selected().is_some_and(|s| s == i + offset) { if let Some(item) = highlighted.take() { - render_item(item, area, buf, i, num_items, &scroll_direction); + render_item(item, area, buf, i, num_items, &scroll_direction, self.style); } } else if let Some(item) = items_in_view.next() { - render_item(item, area, buf, i, num_items, &scroll_direction); + render_item(item, area, buf, i, num_items, &scroll_direction, self.style); } pos_scroll_axis += size as u16; } @@ -194,6 +194,7 @@ fn render_item( pos: usize, num_items: usize, scroll_direction: &ScrollAxis, + base_style: Style, ) { let item_size = item.size(scroll_direction) as u16; @@ -201,7 +202,7 @@ fn render_item( if area.height < item_size { // Determine if truncation should happen at the top or the bottom let truncate_top = pos == 0 && num_items > 1; - render_and_truncate(item, area, buf, scroll_direction, truncate_top); + render_and_truncate(item, area, buf, scroll_direction, truncate_top, base_style); } else { item.render(area, buf); } @@ -215,6 +216,7 @@ fn render_and_truncate( buf: &mut Buffer, scroll_direction: &ScrollAxis, truncate_top: bool, + base_style: Style, ) { let item_size = item.size(scroll_direction) as u16; // Create an intermediate buffer for rendering the truncated element @@ -228,6 +230,7 @@ fn render_and_truncate( width, height, }); + hidden_buffer.set_style(hidden_buffer.area, base_style); item.render(hidden_buffer.area, &mut hidden_buffer); // Copy the visible part from the intermediate buffer to the main buffer