| 1 | use tuirust-analyzer cargo ratatui 0.30.0 crate/::{ |
| 2 | bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/::Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer#, |
| 3 | layoutrust-analyzer cargo ratatui-core 0.1.0 layout/::Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#, |
| 4 | textrust-analyzer cargo ratatui-core 0.1.0 text/::{Linerust-analyzer cargo ratatui-core 0.1.0 text/line/Line#, Spanrust-analyzer cargo ratatui-core 0.1.0 text/span/Span#, Textrust-analyzer cargo ratatui-core 0.1.0 text/text/Text#}, |
| 5 | widgetsrust-analyzer cargo ratatui 0.30.0 widgets/::{Blockrust-analyzer cargo ratatui-widgets 0.3.0 block/Block#, Paragraphrust-analyzer cargo ratatui-widgets 0.3.0 paragraph/Paragraph#, Widgetrust-analyzer cargo ratatui-core 0.1.0 widgets/widget/Widget#}, |
| 6 | }; |
| 7 | |
| 8 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 9 | pub struct Listrust-analyzer cargo tui-react 0.24.0 list/List# { |
| 10 | /// The index at which the list last started. Used for scrolling |
| 11 | pub offsetrust-analyzer cargo tui-react 0.24.0 list/List#offset.: usize, |
| 12 | } |
| 13 | |
| 14 | impl Listrust-analyzer cargo tui-react 0.24.0 list/List# { |
| 15 | fn list_offset_forrust-analyzer cargo tui-react 0.24.0 list/impl#[List]list_offset_for().(&self, entry_in_view: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, height: usize) -> usize { |
| 16 | match entry_in_view { |
| 17 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pos) => match height { |
| 18 | h if (self.offsetrust-analyzer cargo tui-react 0.24.0 list/List#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().h).saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().pos => pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().h rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, |
| 19 | _ if self.offsetrust-analyzer cargo tui-react 0.24.0 list/List#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().pos => pos, |
| 20 | _ => self.offsetrust-analyzer cargo tui-react 0.24.0 list/List#offset., |
| 21 | }, |
| 22 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => 0, |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 28 | pub struct ListPropsrust-analyzer cargo tui-react 0.24.0 list/ListProps#<'b> { |
| 29 | pub blockrust-analyzer cargo tui-react 0.24.0 list/ListProps#block.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Blockrust-analyzer cargo ratatui-widgets 0.3.0 block/Block#<'b>>, |
| 30 | pub entry_in_viewrust-analyzer cargo tui-react 0.24.0 list/ListProps#entry_in_view.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, |
| 31 | } |
| 32 | |
| 33 | impl Listrust-analyzer cargo tui-react 0.24.0 list/List# { |
| 34 | pub fn renderrust-analyzer cargo tui-react 0.24.0 list/impl#[List]render().<'a, 't>( |
| 35 | &mut self, |
| 36 | props: ListPropsrust-analyzer cargo tui-react 0.24.0 list/ListProps#<'a>, |
| 37 | items: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Spanrust-analyzer cargo ratatui-core 0.1.0 text/span/Span#<'t>>>, |
| 38 | area: Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#, |
| 39 | buf: &mut Bufferrust-analyzer cargo ratatui-core 0.1.0 buffer/buffer/Buffer#, |
| 40 | ) { |
| 41 | let ListPropsrust-analyzer cargo tui-react 0.24.0 list/ListProps# { |
| 42 | blockrust-analyzer cargo tui-react 0.24.0 list/ListProps#block., |
| 43 | entry_in_viewrust-analyzer cargo tui-react 0.24.0 list/ListProps#entry_in_view., |
| 44 | } = props; |
| 45 | |
| 46 | let list_area = match block { |
| 47 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b) => { |
| 48 | let inner_area = b.innerrust-analyzer cargo ratatui-widgets 0.3.0 block/impl#[`Block<'a>`]inner().(area); |
| 49 | b.renderrust-analyzer cargo ratatui-widgets 0.3.0 block/impl#[`Block<'_>`][Widget]render().(area, buf); |
| 50 | inner_area |
| 51 | } |
| 52 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => area, |
| 53 | }; |
| 54 | self.offsetrust-analyzer cargo tui-react 0.24.0 list/List#offset. = self.list_offset_forrust-analyzer cargo tui-react 0.24.0 list/impl#[List]list_offset_for().(entry_in_view, list_area.heightrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#height. as usize); |
| 55 | |
| 56 | if list_area.widthrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#width. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().1 || list_area.heightrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#height. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().1 { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | for (i, vec_of_spans) in items |
| 61 | .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().() |
| 62 | .skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(self.offsetrust-analyzer cargo tui-react 0.24.0 list/List#offset.) |
| 63 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 64 | .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(list_area.heightrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#height. as usize) |
| 65 | { |
| 66 | let (x, y) = (list_area.leftrust-analyzer cargo ratatui-core 0.1.0 layout/rect/impl#[Rect]left().(), list_area.toprust-analyzer cargo ratatui-core 0.1.0 layout/rect/impl#[Rect]top().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().i as u16); |
| 67 | Paragraphrust-analyzer cargo ratatui-widgets 0.3.0 paragraph/Paragraph#::newrust-analyzer cargo ratatui-widgets 0.3.0 paragraph/impl#[`Paragraph<'a>`]new().(Textrust-analyzer cargo ratatui-core 0.1.0 text/text/Text#::fromrust-analyzer cargo ratatui-core 0.1.0 text/text/impl#[`Text<'a>`][`From<Line<'a>>`]from().(Linerust-analyzer cargo ratatui-core 0.1.0 text/line/Line#::fromrust-analyzer cargo ratatui-core 0.1.0 text/line/impl#[`Line<'a>`][`From<Vec<Span<'a>>>`]from().(vec_of_spans))).renderrust-analyzer cargo ratatui-widgets 0.3.0 paragraph/impl#[`Paragraph<'_>`][Widget]render().( |
| 68 | Rectrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect# { |
| 69 | xrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#x., |
| 70 | yrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#y., |
| 71 | widthrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#width.: list_area.widthrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#width., |
| 72 | heightrust-analyzer cargo ratatui-core 0.1.0 layout/rect/Rect#height.: 1, |
| 73 | }, |
| 74 | buf, |
| 75 | ); |
| 76 | } |
| 77 | } |
| 78 | } |