File: scroll_padding.rs

package info (click to toggle)
rust-tui-widget-list 0.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,776 kB
  • sloc: makefile: 2
file content (27 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::common::{item_container::ListItemContainer, Colors};
use ratatui::{layout::Alignment, style::Stylize, text::Line, widgets::Padding};
use tui_widget_list::{ListBuilder, ListView};

pub(crate) struct ScrollPaddingListView;

impl ScrollPaddingListView {
    pub(crate) fn new<'a>() -> ListView<'a, ListItemContainer<'a, Line<'a>>> {
        let builder = ListBuilder::new(|context| {
            let mut line = ListItemContainer::new(
                Line::from(format!("Item {0}", context.index)).alignment(Alignment::Center),
                Padding::vertical(1),
            );
            line = match context.is_selected {
                true => line.bg(Colors::ORANGE).fg(Colors::CHARCOAL),
                false if context.index % 2 == 0 => line.bg(Colors::CHARCOAL),
                false => line.bg(Colors::BLACK),
            };

            return (line, 3);
        });

        return ListView::new(builder, 30)
            .infinite_scrolling(false)
            .scroll_padding(5);
    }
}