Debian Codegraph @

src/canvas/components/data_table/state.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::NonZeroU16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU16#;
2
3 use ratatuirust-analyzer cargo ratatui 0.30.2 crate/::{layoutrust-analyzer cargo ratatui-core 0.1.2 layout/::Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#, widgetsrust-analyzer cargo ratatui 0.30.2 widgets/::TableStaterust-analyzer cargo ratatui-widgets 0.3.2 table/state/TableState#};
4
5 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
6 pub enum ScrollDirectionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection# {
7 // UP means scrolling up --- this usually DECREMENTS
8 Uprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Up#,
9
10 // DOWN means scrolling down --- this usually INCREMENTS
11 #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:]
12 Downrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Down#,
13 }
14
15 /// Internal state representation of a [`DataTable`](super::DataTable).
16 pub struct DataTableStaterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState# {
17 /// The index from where to start displaying the rows.
18 pub display_start_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#display_start_index.: usize,
19
20 /// The current scroll position.
21 pub current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index.: usize,
22
23 /// The direction of the last attempted scroll.
24 pub scroll_directionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#scroll_direction.: ScrollDirectionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#,
25
26 /// ratatui's internal table state.
27 pub table_staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#table_state.: TableStaterust-analyzer cargo ratatui-widgets 0.3.2 table/state/TableState#,
28
29 /// The calculated widths.
30 pub calculated_widthsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#calculated_widths.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<NonZeroU16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU16#>,
31
32 /// The current inner [`Rect`].
33 pub inner_rectrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#inner_rect.: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#,
34 }
35
36 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for DataTableStaterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState# {
37 fn defaultrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/impl#[DataTableState][Default]default().() -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/impl#[DataTableState][Default] {
38 Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/impl#[DataTableState][Default] {
39 display_start_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#display_start_index.: 0,
40 current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index.: 0,
41 scroll_directionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#scroll_direction.: ScrollDirectionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#::Downrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Down#,
42 calculated_widthsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#calculated_widths.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![],
43 table_staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#table_state.: TableStaterust-analyzer cargo ratatui-widgets 0.3.2 table/state/TableState#::defaultrust-analyzer cargo ratatui-widgets 0.3.2 table/state/impl#[TableState][Default]default().(),
44 inner_rectrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#inner_rect.: Rectrust-analyzer cargo ratatui-core 0.1.2 layout/rect/Rect#::defaultrust-analyzer cargo ratatui-core 0.1.2 layout/rect/impl#[Rect][Default]default().(),
45 }
46 }
47 }
48
49 impl DataTableStaterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState# {
50 /// Gets the starting position of a table.
51 pub fn get_start_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/impl#[DataTableState]get_start_position().(&mut self, num_rows: usize, is_force_redraw: bool) {
52 let start_index = if is_force_redraw {
53 0
54 } else {
55 self.display_start_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#display_start_index.
56 };
57 let current_scroll_position = self.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index.;
58 let scroll_direction = self.scroll_directionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#scroll_direction.;
59
60 self.display_start_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#display_start_index. = match scroll_direction {
61 ScrollDirectionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#::Downrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Down# => {
62 if current_scroll_position 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().start_index 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().num_rows {
63 // If, using the current scroll position, we can see the element
64 // (so within that and + num_rows) just reuse the current previously
65 // scrolled position.
66 start_index
67 } else if current_scroll_position rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().num_rows {
68 // If the current position past the last element visible in the list,
69 // then skip until we can see that element.
70 current_scroll_position 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().num_rows 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
71 } else {
72 // Else, if it is not past the last element visible, do not omit anything.
73 0
74 }
75 }
76 ScrollDirectionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#::Uprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Up# => {
77 if current_scroll_position rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().start_index {
78 // If it's past the first element, then show from that element downwards
79 current_scroll_position
80 } else if current_scroll_position rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().start_index 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().num_rows {
81 current_scroll_position 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().num_rows 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
82 } else {
83 start_index
84 }
85 }
86 };
87 }
88 }