Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
chore: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
fdehau committed Oct 17, 2021
1 parent 4845c03 commit 8c1f580
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog

## To be released

### Features
* Add option to `widgets::List` to repeat the hightlight symbol for each line of multi-line items.

* Add option to `widgets::List` to repeat the hightlight symbol for each line of multi-line items (#533).

## v0.16.0 - 2021-08-01

Expand Down
12 changes: 9 additions & 3 deletions src/widgets/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a> List<'a> {
self.highlight_style = style;
self
}

pub fn repeat_highlight_symbol(mut self, repeat: bool) -> List<'a> {
self.repeat_highlight_symbol = repeat;
self
Expand Down Expand Up @@ -239,13 +239,19 @@ impl<'a> StatefulWidget for List<'a> {
// if the item is selected, we need to display the hightlight symbol:
// - either for the first line of the item only,
// - or for each line of the item if the appropriate option is set
let symbol = if is_selected && (j == 0 || self.repeat_highlight_symbol){
let symbol = if is_selected && (j == 0 || self.repeat_highlight_symbol) {
highlight_symbol
} else {
&blank_symbol
};
let (elem_x, max_element_width) = if has_selection {
let (elem_x, _) = buf.set_stringn(x, y + j as u16, symbol, list_area.width as usize, item_style);
let (elem_x, _) = buf.set_stringn(
x,
y + j as u16,
symbol,
list_area.width as usize,
item_style,
);
(elem_x, (list_area.width - (elem_x - x)) as u16)
} else {
(x, list_area.width)
Expand Down
7 changes: 5 additions & 2 deletions tests/widgets_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use tui::{
layout::Rect,
style::{Color, Style},
symbols,
text::Spans,
widgets::{Block, Borders, List, ListItem, ListState},
Terminal,
};
Expand Down Expand Up @@ -153,7 +154,8 @@ fn widgets_list_should_display_multiline_items() {
">> Item 2 ",
" Item 2b",
" Item 3 ",
" Item 3c"]);
" Item 3c",
]);
for x in 0..10 {
expected.get_mut(x, 2).set_bg(Color::Yellow);
expected.get_mut(x, 3).set_bg(Color::Yellow);
Expand Down Expand Up @@ -188,7 +190,8 @@ fn widgets_list_should_repeat_highlight_symbol() {
">> Item 2 ",
">> Item 2b",
" Item 3 ",
" Item 3c"]);
" Item 3c",
]);
for x in 0..10 {
expected.get_mut(x, 2).set_bg(Color::Yellow);
expected.get_mut(x, 3).set_bg(Color::Yellow);
Expand Down

0 comments on commit 8c1f580

Please sign in to comment.