mirror of
https://github.com/slint-ui/slint.git
synced 2025-12-23 09:19:32 +00:00
GridLayoutOrganizedData: extract function max_value
This commit is contained in:
parent
a3baa4f6c0
commit
56d35ab144
1 changed files with 12 additions and 7 deletions
|
|
@ -316,11 +316,7 @@ mod grid_internal {
|
|||
) -> Vec<LayoutData> {
|
||||
assert!(organized_data.len() % 4 == 0);
|
||||
assert!(constraints.len() * 4 == organized_data.len());
|
||||
let mut num = 0usize;
|
||||
for idx in 0..organized_data.len() / 4 {
|
||||
let (col_or_row, span) = organized_data.col_or_row_and_span(idx, orientation);
|
||||
num = num.max(col_or_row as usize + span.max(1) as usize);
|
||||
}
|
||||
let num = organized_data.max_value(orientation) as usize;
|
||||
if num < 1 {
|
||||
return Default::default();
|
||||
}
|
||||
|
|
@ -451,17 +447,26 @@ pub struct GridLayoutInputData {
|
|||
pub type GridLayoutOrganizedData = SharedVector<u16>;
|
||||
|
||||
impl GridLayoutOrganizedData {
|
||||
pub fn push_cell(&mut self, col: u16, colspan: u16, row: u16, rowspan: u16) {
|
||||
fn push_cell(&mut self, col: u16, colspan: u16, row: u16, rowspan: u16) {
|
||||
self.push(col);
|
||||
self.push(colspan);
|
||||
self.push(row);
|
||||
self.push(rowspan);
|
||||
}
|
||||
|
||||
pub fn col_or_row_and_span(&self, index: usize, orientation: Orientation) -> (u16, u16) {
|
||||
fn col_or_row_and_span(&self, index: usize, orientation: Orientation) -> (u16, u16) {
|
||||
let offset = if orientation == Orientation::Horizontal { 0 } else { 2 };
|
||||
(self[index * 4 + offset], self[index * 4 + offset + 1])
|
||||
}
|
||||
|
||||
fn max_value(&self, orientation: Orientation) -> u16 {
|
||||
let mut max = 0;
|
||||
for idx in 0..self.len() / 4 {
|
||||
let (col_or_row, span) = self.col_or_row_and_span(idx, orientation);
|
||||
max = max.max(col_or_row + span.max(1));
|
||||
}
|
||||
max
|
||||
}
|
||||
}
|
||||
|
||||
/// Given the cells of a layout of a Dialog, re-order the buttons according to the platform
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue