| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 2 | 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#, |
| 3 | cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::{maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max()., minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().}, |
| 4 | 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#, |
| 5 | }; |
| 6 | |
| 7 | /// A bound on the width of a column. |
| 8 | #[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:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 9 | pub enum ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds# { |
| 10 | /// A width of this type is as long as `desired`, but can otherwise shrink |
| 11 | /// and grow up to a point. |
| 12 | Softrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Soft# { |
| 13 | /// The desired, calculated width. Take this if possible as the base |
| 14 | /// starting width. |
| 15 | desiredrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Soft#desired.: u16, |
| 16 | |
| 17 | /// The max width, as a percentage of the total width available. If |
| 18 | /// [`None`], then it can grow as desired. |
| 19 | max_percentagerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Soft#max_percentage.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<f32>, |
| 20 | }, |
| 21 | |
| 22 | /// A width of this type is either as long as specified, or does not appear |
| 23 | /// at all. |
| 24 | Hardrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Hard#(u16), |
| 25 | |
| 26 | /// A width of this type always resizes to the column header's text width. |
| 27 | FollowHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#FollowHeader#, |
| 28 | } |
| 29 | |
| 30 | pub trait ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader# { |
| 31 | /// The "text" version of the column header. |
| 32 | fn textrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#text().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>; |
| 33 | |
| 34 | /// The version displayed when drawing the table. Defaults to |
| 35 | /// [`ColumnHeader::text`]. |
| 36 | #[inline(always)] |
| 37 | fn headerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#header().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str> { |
| 38 | self.textrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#text().() |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | impl ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader# for &'static str { |
| 43 | fn textrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`&'static str`][ColumnHeader]text().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str> { |
| 44 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(self) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | impl ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader# for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 49 | fn textrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[String][ColumnHeader]text().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str> { |
| 50 | Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(self.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | pub trait DataTableColumnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#<H: ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#> { |
| 55 | fn innerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#inner().(&self) -> &H; |
| 56 | |
| 57 | fn inner_mutrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#inner_mut().(&mut self) -> &mut H; |
| 58 | |
| 59 | fn boundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#bounds().(&self) -> ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#; |
| 60 | |
| 61 | fn bounds_mutrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#bounds_mut().(&mut self) -> &mut ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#; |
| 62 | |
| 63 | fn is_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#is_hidden().(&self) -> bool; |
| 64 | |
| 65 | fn set_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#set_hidden().(&mut self, hidden: bool); |
| 66 | |
| 67 | /// The actually displayed "header". |
| 68 | fn headerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#header().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>; |
| 69 | |
| 70 | /// The header length, along with any required additional lengths for things |
| 71 | /// like arrows. Defaults to getting the length of |
| 72 | /// [`DataTableColumn::header`]. |
| 73 | fn header_lenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#header_len().(&self) -> usize { |
| 74 | self.headerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#header().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | #[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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 79 | pub struct Columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#<H> { |
| 80 | /// The inner column header. |
| 81 | innerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#inner.: H, |
| 82 | |
| 83 | /// A restriction on this column's width. |
| 84 | boundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#bounds.: ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#, |
| 85 | |
| 86 | /// Marks that this column is currently "hidden", and should *always* be |
| 87 | /// skipped. |
| 88 | is_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#is_hidden.: bool, |
| 89 | } |
| 90 | |
| 91 | impl<H: ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#> DataTableColumnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#<H> for Columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#<H> { |
| 92 | #[inline] |
| 93 | fn innerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`][`DataTableColumn<H>`]inner().(&self) -> &H { |
| 94 | &self.innerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#inner. |
| 95 | } |
| 96 | |
| 97 | #[inline] |
| 98 | fn inner_mutrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`][`DataTableColumn<H>`]inner_mut().(&mut self) -> &mut H { |
| 99 | &mut self.innerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#inner. |
| 100 | } |
| 101 | |
| 102 | #[inline] |
| 103 | fn boundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`][`DataTableColumn<H>`]bounds().(&self) -> ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds# { |
| 104 | self.boundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#bounds. |
| 105 | } |
| 106 | |
| 107 | #[inline] |
| 108 | fn bounds_mutrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`][`DataTableColumn<H>`]bounds_mut().(&mut self) -> &mut ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds# { |
| 109 | &mut self.boundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#bounds. |
| 110 | } |
| 111 | |
| 112 | #[inline] |
| 113 | fn is_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`][`DataTableColumn<H>`]is_hidden().(&self) -> bool { |
| 114 | self.is_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#is_hidden. |
| 115 | } |
| 116 | |
| 117 | #[inline] |
| 118 | fn set_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`][`DataTableColumn<H>`]set_hidden().(&mut self, hidden: bool) { |
| 119 | self.is_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#is_hidden. = hidden; |
| 120 | } |
| 121 | |
| 122 | fn headerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`][`DataTableColumn<H>`]header().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str> { |
| 123 | self.innerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#inner..headerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#header().() |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | impl<H: ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#> Columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#<H> { |
| 128 | pub const fn newrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`]new().(inner: H) -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`] { |
| 129 | Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`] { |
| 130 | innerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#inner., |
| 131 | boundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#bounds.: ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#::FollowHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#FollowHeader#, |
| 132 | is_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#is_hidden.: false, |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | pub const fn hardrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`]hard().(inner: H, width: u16) -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`] { |
| 137 | Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`] { |
| 138 | innerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#inner., |
| 139 | boundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#bounds.: ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#::Hardrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Hard#(width), |
| 140 | is_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#is_hidden.: false, |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | pub const fn softrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`]soft().(inner: H, max_percentage: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<f32>) -> Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`] { |
| 145 | Selfrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`] { |
| 146 | innerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#inner., |
| 147 | boundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#bounds.: ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#::Softrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Soft# { |
| 148 | desiredrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Soft#desired.: 0, |
| 149 | max_percentagerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Soft#max_percentage., |
| 150 | }, |
| 151 | is_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#is_hidden.: false, |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | pub trait CalculateColumnWidthsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/CalculateColumnWidths#<H> { |
| 157 | /// Calculates widths for the columns of this table, given the current width |
| 158 | /// when called. |
| 159 | /// |
| 160 | /// * `total_width` is the total width on the canvas that the columns can |
| 161 | /// try and work with. |
| 162 | /// * `left_to_right` is whether to size from left-to-right (`true`) or |
| 163 | /// right-to-left (`false`). |
| 164 | fn calculate_column_widthsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/CalculateColumnWidths#calculate_column_widths().(&self, total_width: u16, left_to_right: bool) -> 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#>; |
| 165 | } |
| 166 | |
| 167 | impl<H, C> CalculateColumnWidthsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/CalculateColumnWidths#<H> for [C] |
| 168 | where |
| 169 | H: ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader#, |
| 170 | C: DataTableColumnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#<H>, |
| 171 | { |
| 172 | fn calculate_column_widthsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`[C]`][`CalculateColumnWidths<H>`]calculate_column_widths().(&self, total_width: u16, left_to_right: bool) -> 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#> { |
| 173 | use itertoolsrust-analyzer cargo itertools 0.15.0 crate/::Eitherrust-analyzer cargo either 1.15.0 Either#; |
| 174 | |
| 175 | const COLUMN_SPACINGrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/COLUMN_SPACING.: u16 = 1; |
| 176 | |
| 177 | #[inline] |
| 178 | fn stop_allocating_spacerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/stop_allocating_space().(desired: u16, available: u16) -> bool { |
| 179 | desired rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().available || desired rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().0 |
| 180 | } |
| 181 | |
| 182 | let mut total_width_left = total_width; |
| 183 | let mut calculated_widths = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 184 | let columns = if left_to_right { |
| 185 | Eitherrust-analyzer cargo either 1.15.0 Either#::Leftrust-analyzer cargo either 1.15.0 Either#Left#(self.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) |
| 186 | } else { |
| 187 | Eitherrust-analyzer cargo either 1.15.0 Either#::Rightrust-analyzer cargo either 1.15.0 Either#Right#(self.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().()) |
| 188 | }; |
| 189 | |
| 190 | for column in columns { |
| 191 | if column.is_hiddenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#is_hidden().() { |
| 192 | continue; |
| 193 | } |
| 194 | |
| 195 | let new_width = match &column.boundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#bounds().() { |
| 196 | ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#::Softrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Soft# { |
| 197 | desiredrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Soft#desired., |
| 198 | max_percentagerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Soft#max_percentage., |
| 199 | } => { |
| 200 | let min_width = column.header_lenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#header_len().() as u16; |
| 201 | if min_width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().total_width_left { |
| 202 | break; |
| 203 | } |
| 204 | |
| 205 | let soft_limit = maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().( |
| 206 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(max_percentage) = max_percentage { |
| 207 | ((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().max_percentage rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul().f32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[f32][`From<u16>`]from().(total_width)).ceilrust-analyzer cargo std https://github.com/rust-lang/rust/library/std f32/impl#[f32]ceil().()) as u16 |
| 208 | } else { |
| 209 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().desired |
| 210 | }, |
| 211 | min_width, |
| 212 | ); |
| 213 | |
| 214 | minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(soft_limit, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().desired), total_width_left) |
| 215 | } |
| 216 | ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#::Hardrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#Hard#(width) => *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().width, |
| 217 | ColumnWidthBoundsrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#::FollowHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnWidthBounds#FollowHeader# => column.header_lenrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/DataTableColumn#header_len().() as u16, |
| 218 | }; |
| 219 | |
| 220 | if stop_allocating_spacerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/stop_allocating_space().(new_width, total_width_left) { |
| 221 | break; |
| 222 | } else { |
| 223 | total_width_left = total_width_left.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_sub().(new_width 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().COLUMN_SPACINGrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/COLUMN_SPACING.); |
| 224 | |
| 225 | // SAFETY: This is safe as we call `stop_allocating_space` which checks that |
| 226 | // the value pushed is greater than zero. |
| 227 | unsafe { |
| 228 | calculated_widths.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(NonZeroU16rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU16#::new_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new_unchecked().(new_width)); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().calculated_widths.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 234 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().left_to_right { |
| 235 | calculated_widths.reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]reverse().(); |
| 236 | } |
| 237 | |
| 238 | // Redistribute remaining space. |
| 239 | let mut num_dist = calculated_widths.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as u16; |
| 240 | let amount_per_slot = total_width_left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Div<Self>`]div().num_dist; // Safe from DBZ by above empty check. |
| 241 | total_width_left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`RemAssign<Self>`]rem_assign().num_dist; |
| 242 | |
| 243 | for width in calculated_widths.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() { |
| 244 | if num_dist rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().0 { |
| 245 | break; |
| 246 | } |
| 247 | |
| 248 | if total_width_left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().0 { |
| 249 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().width = width.saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<u16>`]saturating_add().(amount_per_slot 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().1); |
| 250 | total_width_left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`SubAssign<Self>`]sub_assign().1; |
| 251 | } else { |
| 252 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().width = width.saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<u16>`]saturating_add().(amount_per_slot); |
| 253 | } |
| 254 | |
| 255 | num_dist rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`SubAssign<Self>`]sub_assign().1; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | calculated_widths |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | #[cfg(test)] |
| 264 | mod testrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/test/ { |
| 265 | use superrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/::*; |
| 266 | |
| 267 | struct TestInnerColumnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/test/TestInnerColumn#; |
| 268 | |
| 269 | impl ColumnHeaderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/ColumnHeader# for TestInnerColumnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/test/TestInnerColumn# { |
| 270 | fn textrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/test/impl#[TestInnerColumn][ColumnHeader]text().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str> { |
| 271 | "text".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 272 | } |
| 273 | |
| 274 | fn headerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/test/impl#[TestInnerColumn][ColumnHeader]header().(&self) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str> { |
| 275 | "header(h)".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /// Ensure that the [`DataTableColumn`] implementation for [`Column`] calls the right method. |
| 280 | /// Yes, this is a somewhat meaningless test but it may catch a regression if this happens again in the future |
| 281 | /// during a refactor. |
| 282 | /// |
| 283 | /// See <https://github.com/ClementTsang/bottom/issues/2159> for details of the issue. |
| 284 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 285 | fn column_header_impl_uses_right_functionrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/test/column_header_impl_uses_right_function().() { |
| 286 | let column = Columnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/Column#::newrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`]new().(TestInnerColumnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/test/TestInnerColumn#); |
| 287 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(column.headerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/impl#[`Column<H>`][`DataTableColumn<H>`]header().(), TestInnerColumnrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/test/TestInnerColumn#.headerrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/column/test/impl#[TestInnerColumn][ColumnHeader]header().()); |
| 288 | } |
| 289 | } |