| 1 | pub mod columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/; |
| 2 | pub mod data_typerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/data_type/; |
| 3 | pub mod drawrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/draw/; |
| 4 | pub mod propsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/; |
| 5 | pub mod sortablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/sortable/; |
| 6 | pub mod staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/; |
| 7 | pub mod stylingrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/styling/; |
| 8 | |
| 9 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#, markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#}; |
| 10 | |
| 11 | pub use columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/::*; |
| 12 | pub use data_typerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/data_type/::*; |
| 13 | pub use drawrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/draw/::*; |
| 14 | pub use propsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/::DataTablePropsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#; |
| 15 | pub use sortablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/sortable/::*; |
| 16 | pub use staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/::{DataTableStaterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#, ScrollDirectionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#}; |
| 17 | pub use stylingrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/styling/::*; |
| 18 | |
| 19 | use craterust-analyzer cargo bottom 0.14.9 crate/::utilsrust-analyzer cargo bottom 0.14.9 utils/::generalrust-analyzer cargo bottom 0.14.9 utils/general/::ClampExtrust-analyzer cargo bottom 0.14.9 utils/general/ClampExt#; |
| 20 | |
| 21 | /// A [`DataTable`] is a component that displays data in a tabular form. |
| 22 | /// |
| 23 | /// Note that [`DataTable`] takes a generic type `S`, bounded by [`SortType`]. |
| 24 | /// This controls whether this table expects sorted data or not, with two |
| 25 | /// expected types: |
| 26 | /// |
| 27 | /// - [`Unsortable`]: The default if otherwise not specified. This table does |
| 28 | /// not expect sorted data. |
| 29 | /// - [`Sortable`]: This table expects sorted data, and there are helper |
| 30 | /// functions to facilitate things like sorting based on a selected column, |
| 31 | /// shortcut column selection support, mouse column selection support, etc. |
| 32 | /// |
| 33 | /// FIXME: We already do all the text width checks - can we skip the underlying |
| 34 | /// ones? |
| 35 | pub struct DataTablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#<DataType, Header, S = Unsortablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/sortable/Unsortable#, C = Columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#<Header>> { |
| 36 | pub columnsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#columns.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<C>, |
| 37 | pub staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state.: DataTableStaterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#, |
| 38 | pub propsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#props.: DataTablePropsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#, |
| 39 | pub stylingrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#styling.: DataTableStylingrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/styling/DataTableStyling#, |
| 40 | datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#data.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DataType>, |
| 41 | sort_typerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#sort_type.: S, |
| 42 | first_drawrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#first_draw.: bool, |
| 43 | first_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#first_index.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, |
| 44 | _pdrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#_pd.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<(DataType, S, Header)>, |
| 45 | } |
| 46 | |
| 47 | impl<DataType: DataToCellrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/data_type/DataToCell#<H>, H: ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#> DataTablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#<DataType, H, Unsortablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/sortable/Unsortable#, Columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#<H>> { |
| 48 | pub fn newrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H>`]new().<C: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#<H>>>>( |
| 49 | columns: C, props: DataTablePropsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#, styling: DataTableStylingrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/styling/DataTableStyling#, |
| 50 | ) -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H>`] { |
| 51 | Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H>`] { |
| 52 | columnsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#columns.: columns.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), |
| 53 | staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state.: DataTableStaterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#::defaultrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/impl#[DataTableState][Default]default().(), |
| 54 | propsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#props., |
| 55 | stylingrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#styling., |
| 56 | datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#data.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 57 | sort_typerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#sort_type.: Unsortablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/sortable/Unsortable#, |
| 58 | first_drawrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#first_draw.: true, |
| 59 | first_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#first_index.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 60 | _pdrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#_pd.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | impl<DataType: DataToCellrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/data_type/DataToCell#<H>, H: ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#, S: SortTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/sortable/SortType#, C: DataTableColumnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#<H>> |
| 66 | DataTablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#<DataType, H, S, C> |
| 67 | { |
| 68 | /// Sets the default value selected on first initialization, if possible. |
| 69 | pub fn first_draw_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]first_draw_index().(mut self, first_index: usize) -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`] { |
| 70 | self.first_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#first_index. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(first_index); |
| 71 | self |
| 72 | } |
| 73 | |
| 74 | /// Sets the scroll position to the first value. |
| 75 | pub fn scroll_to_firstrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]scroll_to_first().(&mut self) { |
| 76 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index. = 0; |
| 77 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#::Uprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Up#; |
| 78 | } |
| 79 | |
| 80 | /// Sets the scroll position to the last value. |
| 81 | pub fn scroll_to_lastrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]scroll_to_last().(&mut self) { |
| 82 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index. = self.datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().().saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1); |
| 83 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#; |
| 84 | } |
| 85 | |
| 86 | /// Updates the scroll position to be valid for the number of entries. |
| 87 | pub fn set_datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_data().(&mut self, data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DataType>) { |
| 88 | self.datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#data. = data; |
| 89 | let max_pos = self.datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().().saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1); |
| 90 | if self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index. 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().max_pos { |
| 91 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index. = max_pos; |
| 92 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..display_start_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#display_start_index. = 0; |
| 93 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /// Increments the scroll position if possible by a positive/negative |
| 98 | /// offset. If there is a valid change, this function will also return |
| 99 | /// the new position wrapped in an [`Option`]. |
| 100 | /// |
| 101 | /// Note that despite the name, this handles both incrementing (positive |
| 102 | /// change) and decrementing (negative change). |
| 103 | pub fn increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]increment_position().(&mut self, change: i64) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 104 | let num_entries = self.datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 105 | |
| 106 | if num_entries rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 107 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 108 | } |
| 109 | |
| 110 | let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(current_index): Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i64, _> = self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().() else { |
| 111 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 112 | }; |
| 113 | |
| 114 | // We do this to clamp the proposed index to 0 if the change is greater |
| 115 | // than the number of entries left from the current index. This gives |
| 116 | // a more intuitive behaviour when using things like page up/down. |
| 117 | let proposed = current_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().change; |
| 118 | |
| 119 | // We check num_entries > 0 above. |
| 120 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index. = proposed.clamprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][Ord]clamp().(0, (num_entries 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().1) as i64) as usize; |
| 121 | |
| 122 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..scroll_directionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#scroll_direction. = if change rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt().0 { |
| 123 | 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# |
| 124 | } else { |
| 125 | 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# |
| 126 | }; |
| 127 | |
| 128 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index.) |
| 129 | } |
| 130 | |
| 131 | /// Updates the scroll position to a selected index. |
| 132 | pub fn set_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_position().(&mut self, new_index: usize) { |
| 133 | let new_index = new_index.clamp_upperrust-analyzer cargo bottom 0.14.9 utils/general/impl#[usize][ClampExt]clamp_upper().(self.datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().().saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1)); |
| 134 | if self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index. 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().new_index { |
| 135 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#; |
| 136 | } else if self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index. 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().new_index { |
| 137 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#::Uprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Up#; |
| 138 | } |
| 139 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index. = new_index; |
| 140 | } |
| 141 | |
| 142 | /// Returns the current scroll index. |
| 143 | pub fn current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(&self) -> usize { |
| 144 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index. |
| 145 | } |
| 146 | |
| 147 | /// Optionally returns the currently selected item, if there is one. |
| 148 | pub fn current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&DataType> { |
| 149 | self.datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#current_index.) |
| 150 | } |
| 151 | |
| 152 | /// Returns ratatui's internal selection. |
| 153 | pub fn ratatui_selectedrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]ratatui_selected().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 154 | self.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..table_staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/DataTableState#table_state..selectedrust-analyzer cargo ratatui-widgets 0.3.2 table/state/impl#[TableState]selected().() |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | #[cfg(test)] |
| 159 | mod testrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/ { |
| 160 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#, 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#}; |
| 161 | |
| 162 | use superrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/::*; |
| 163 | use craterust-analyzer cargo bottom 0.14.9 crate/::optionsrust-analyzer cargo bottom 0.14.9 options/::configrust-analyzer cargo bottom 0.14.9 options/config/::flagsrust-analyzer cargo bottom 0.14.9 options/config/flags/::TableGaprust-analyzer cargo bottom 0.14.9 options/config/flags/TableGap#; |
| 164 | |
| 165 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 166 | struct TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { |
| 167 | indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: usize, |
| 168 | } |
| 169 | |
| 170 | impl DataToCellrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/data_type/DataToCell#<&'static str> for TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { |
| 171 | fn to_cell_textrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/impl#[TestType][`DataToCell<&'static str>`]to_cell_text().( |
| 172 | &self, _column: &&'static str, _calculated_width: NonZeroU16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU16#, |
| 173 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>> { |
| 174 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 175 | } |
| 176 | |
| 177 | fn column_widthsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/impl#[TestType][`DataToCell<&'static str>`]column_widths().<C: DataTableColumnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#<&'static str>>( |
| 178 | _data: &[Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/impl#[TestType][`DataToCell<&'static str>`]], _columns: &[C], |
| 179 | ) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u16> |
| 180 | where |
| 181 | Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/impl#[TestType][`DataToCell<&'static str>`]: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 182 | { |
| 183 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![] |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | fn create_test_tablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/create_test_table().() -> DataTablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#<TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#, &'static str> { |
| 188 | let columns = [Columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#::hardrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`]hard().("a", 10), Columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#::hardrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`]hard().("b", 10)]; |
| 189 | let props = DataTablePropsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps# { |
| 190 | titlerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#title.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), |
| 191 | table_gaprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#table_gap.: TableGaprust-analyzer cargo bottom 0.14.9 options/config/flags/TableGap#::Spacerust-analyzer cargo bottom 0.14.9 options/config/flags/TableGap#Space#, |
| 192 | left_to_rightrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#left_to_right.: false, |
| 193 | is_basicrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#is_basic.: false, |
| 194 | show_table_scroll_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#show_table_scroll_position.: true, |
| 195 | show_table_scroll_barrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#show_table_scroll_bar.: false, |
| 196 | show_current_entry_when_unfocusedrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/props/DataTableProps#show_current_entry_when_unfocused.: false, |
| 197 | }; |
| 198 | let styling = DataTableStylingrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/styling/DataTableStyling#::defaultrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/styling/impl#[DataTableStyling][Default]default().(); |
| 199 | |
| 200 | DataTablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#::newrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H>`]new().(columns, props, styling) |
| 201 | } |
| 202 | |
| 203 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 204 | fn test_scrollingrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/test_scrolling().() { |
| 205 | let mut table = create_test_tablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/create_test_table().(); |
| 206 | table.set_datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_data().((0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#4).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|index| TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index. }).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()); |
| 207 | |
| 208 | table.scroll_to_lastrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]scroll_to_last().(); |
| 209 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 4); |
| 210 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 211 | |
| 212 | table.scroll_to_firstrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]scroll_to_first().(); |
| 213 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 0); |
| 214 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#::Uprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Up#); |
| 215 | } |
| 216 | |
| 217 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 218 | fn test_set_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/test_set_position().() { |
| 219 | let mut table = create_test_tablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/create_test_table().(); |
| 220 | table.set_datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_data().((0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#4).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|index| TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index. }).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()); |
| 221 | |
| 222 | table.set_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_position().(4); |
| 223 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 4); |
| 224 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 225 | |
| 226 | table.set_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_position().(100); |
| 227 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 4); |
| 228 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 229 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 4 })); |
| 230 | } |
| 231 | |
| 232 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 233 | fn test_increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/test_increment_position().() { |
| 234 | let mut table = create_test_tablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/create_test_table().(); |
| 235 | table.set_datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_data().((0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#4).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|index| TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index. }).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()); |
| 236 | |
| 237 | table.set_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_position().(4); |
| 238 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 4); |
| 239 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 240 | |
| 241 | table.increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]increment_position().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1); |
| 242 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 3); |
| 243 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#::Uprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Up#); |
| 244 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 3 })); |
| 245 | |
| 246 | table.increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]increment_position().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().3); |
| 247 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 0); |
| 248 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#::Uprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Up#); |
| 249 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 0 })); |
| 250 | |
| 251 | table.increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]increment_position().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().3); |
| 252 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 0); |
| 253 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#::Uprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Up#); |
| 254 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 0 })); |
| 255 | |
| 256 | table.increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]increment_position().(1); |
| 257 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 1); |
| 258 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 259 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 1 })); |
| 260 | |
| 261 | table.increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]increment_position().(3); |
| 262 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 4); |
| 263 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 264 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 4 })); |
| 265 | |
| 266 | table.increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]increment_position().(10); |
| 267 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 4); |
| 268 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 269 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 4 })); |
| 270 | |
| 271 | // Make sure that overscrolling up causes clamping. |
| 272 | table.increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]increment_position().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().10); |
| 273 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 0); |
| 274 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#::Uprust-analyzer cargo bottom 0.14.9 canvas/components/data_table/state/ScrollDirection#Up#); |
| 275 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 0 })); |
| 276 | |
| 277 | // Make sure that overscrolling down causes clamping. |
| 278 | table.increment_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]increment_position().(100); |
| 279 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 4); |
| 280 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 281 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 4 })); |
| 282 | } |
| 283 | |
| 284 | /// A test to ensure that scroll offsets are correctly handled when we |
| 285 | /// "lose" rows. |
| 286 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 287 | fn test_lose_datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/test_lose_data().() { |
| 288 | let mut table = create_test_tablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/create_test_table().(); |
| 289 | table.set_datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_data().((0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#4).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|index| TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index. }).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()); |
| 290 | |
| 291 | table.set_positionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_position().(4); |
| 292 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 4); |
| 293 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 294 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 4 })); |
| 295 | |
| 296 | table.set_datarust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]set_data().((0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#2).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|index| TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index. }).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()); |
| 297 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_index().(), 2); |
| 298 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.staterust-analyzer cargo bottom 0.14.9 canvas/components/data_table/DataTable#state..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#); |
| 299 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.current_itemrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/impl#[`DataTable<DataType, H, S, C>`]current_item().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&TestTyperust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType# { indexrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/test/TestType#index.: 2 })); |
| 300 | } |
| 301 | } |