🔧 Enable back clippy rules (#6492)

* 🔧 Fix lint script (rust)

* 🔧 Temporarily add clippy rules to ignore so lint script passes

* 💄 Fix clippy rule crate_in_macro_def

* 💄 Fix clippy rule redundant-static-lifetimes

* 💄 Fix clippy rule unnecessary_cast

* 💄 Fix clippy rule nonminimal_bool

* 💄 Fix clippy rule redundant_pattern_matching

* 💄 Fix clippy rule assign_op_pattern

* 💄 Fix clippy rule needless_lifetimes

* 💄 Fix clippy rule for_kv_map

* 💄 Fix clippy rule ptr_arg

* 💄 Fix clippy rule match_like_matches_macro

* 💄 Fix clippy rule macro_metavars_in_unsafe

* 💄 Fix clippy rule map_clone

* 💄 Fix clippy rule wrong_self_convention

* 💄 Fix clippy rule vec_box

* 💄 Fix clippy rule useless_format

* 💄 Fix clippy rule unwrap_or_default

* 💄 Fix clippy rule unused_unit

* 💄 Fix clippy rule unnecessary_to_owned

* 💄 Fix clippy rule too_many_arguments

* 💄 Fix clippy rule slow_vector_initialization

* 💄 Fix clippy rule single_match

* 💄 Fix clippy rule redundant_field_names

* 💄 Fix clippy rule rendudant_closure

* 💄 Fix clippy rule needless_return

* 💄 Fix clippy rule needless_range_loop

* 💄 Fix clippy rule needless_borrows_for_generic_args

* 💄 Fix clippy rule needless-borrow

* 💄 Fix clippy rule missing_transmute_annotations

* 💄 Fix clippy rule map_entry

* 💄 Fix clippy rule manual_map

* 💄 Fix clippy rule len_zero

* 💄 Fix clippy rule from_over_into

* 💄 Fix clippy rule field_reassign_with_default

* 💄 Fix clippy rule enum_variant_names

* 💄 Fix clippy rule derivable_impls

* 💄 Fix clippy rule clone_on_copy

* 💄 Fix clippy rule box_collection

* 🔧 Make lint script also check test config target

* 🔧 Remove cargo-watch as a lib dependency

* 💄 Fix clippy rule for join_bounds

* 🔧 Fix lint script return code

---------

Co-authored-by: alonso.torres <alonso.torres@kaleidos.net>
This commit is contained in:
Belén Albeza 2025-05-19 11:14:55 +02:00 committed by GitHub
parent 051c2a7e99
commit 8afd217a80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 447 additions and 2338 deletions

View file

@ -10,8 +10,6 @@ pub trait GetBounds {
impl GetBounds for HashMap<Uuid, Bounds> {
fn find(&self, shape: &Shape) -> Bounds {
self.get(&shape.id)
.map(|b| b.clone())
.unwrap_or(shape.bounds())
self.get(&shape.id).copied().unwrap_or(shape.bounds())
}
}

View file

@ -120,16 +120,14 @@ pub fn propagate_shape_constraints(
if let Some((scale_width, scale_height)) = calculate_resize(
constraint_h,
constraint_v,
&parent_bounds_before,
&parent_bounds_after,
&child_bounds_before,
parent_bounds_before,
parent_bounds_after,
child_bounds_before,
&child_bounds_after,
) {
let center = child_bounds_before.center();
let mut parent_transform = parent_bounds_after
.transform_matrix()
.unwrap_or(Matrix::default());
let mut parent_transform = parent_bounds_after.transform_matrix().unwrap_or_default();
parent_transform.post_translate(center);
parent_transform.pre_translate(-center);
@ -140,7 +138,7 @@ pub fn propagate_shape_constraints(
scale.post_translate(origin);
scale.post_concat(&parent_transform);
scale.pre_translate(-origin);
scale.pre_concat(&parent_transform_inv);
scale.pre_concat(parent_transform_inv);
child_bounds_after.transform_mut(&scale);
transform.post_concat(&scale);
@ -150,9 +148,9 @@ pub fn propagate_shape_constraints(
if let Some((delta_x, delta_y)) = calculate_displacement(
constraint_h,
constraint_v,
&parent_bounds_before,
&parent_bounds_after,
&child_bounds_before,
parent_bounds_before,
parent_bounds_after,
child_bounds_before,
&child_bounds_after,
) {
let th = parent_bounds_after.hv(delta_x);

View file

@ -141,7 +141,7 @@ impl ChildAxis {
is_fill_main: child.is_layout_horizontal_fill(),
is_fill_across: child.is_layout_vertical_fill(),
z_index: layout_item.map(|i| i.z_index).unwrap_or(0),
bounds: child_bounds.clone(),
bounds: *child_bounds,
}
} else {
Self {
@ -159,7 +159,7 @@ impl ChildAxis {
is_fill_main: child.is_layout_vertical_fill(),
is_fill_across: child.is_layout_horizontal_fill(),
z_index: layout_item.map(|i| i.z_index).unwrap_or(0),
bounds: child_bounds.clone(),
bounds: *child_bounds,
}
};
@ -267,7 +267,7 @@ fn initialize_tracks(
}
// Resize main axis fill
fn distribute_fill_main_space(layout_axis: &LayoutAxis, tracks: &mut Vec<TrackData>) {
fn distribute_fill_main_space(layout_axis: &LayoutAxis, tracks: &mut [TrackData]) {
for track in tracks.iter_mut() {
let mut left_space = layout_axis.main_space() - track.main_size;
let mut to_resize_children: Vec<&mut ChildAxis> = Vec::new();
@ -284,9 +284,9 @@ fn distribute_fill_main_space(layout_axis: &LayoutAxis, tracks: &mut Vec<TrackDa
let child = &mut to_resize_children[i];
let delta =
f32::min(child.max_main_size, child.main_size + current) - child.main_size;
child.main_size = child.main_size + delta;
left_space = left_space - delta;
track.main_size = track.main_size + delta;
child.main_size += delta;
left_space -= delta;
track.main_size += delta;
if (child.main_size - child.max_main_size).abs() < MIN_SIZE {
to_resize_children.remove(i);
@ -296,7 +296,7 @@ fn distribute_fill_main_space(layout_axis: &LayoutAxis, tracks: &mut Vec<TrackDa
}
}
fn distribute_fill_across_space(layout_axis: &LayoutAxis, tracks: &mut Vec<TrackData>) {
fn distribute_fill_across_space(layout_axis: &LayoutAxis, tracks: &mut [TrackData]) {
let total_across_size = tracks.iter().map(|t| t.across_size).sum::<f32>()
+ (tracks.len() - 1) as f32 * layout_axis.gap_across;
let mut left_space = layout_axis.across_space() - total_across_size;
@ -314,8 +314,8 @@ fn distribute_fill_across_space(layout_axis: &LayoutAxis, tracks: &mut Vec<Track
let track = &mut to_resize_tracks[i];
let delta =
f32::min(track.max_across_size, track.across_size + current) - track.across_size;
track.across_size = track.across_size + delta;
left_space = left_space - delta;
track.across_size += delta;
left_space -= delta;
if (track.across_size - track.max_across_size).abs() < MIN_SIZE {
to_resize_tracks.remove(i);
@ -342,7 +342,7 @@ fn distribute_fill_across_space(layout_axis: &LayoutAxis, tracks: &mut Vec<Track
fn stretch_tracks_sizes(
layout_axis: &LayoutAxis,
tracks: &mut Vec<TrackData>,
tracks: &mut [TrackData],
total_across_size: f32,
) {
let total_across_size = total_across_size + (tracks.len() - 1) as f32 * layout_axis.gap_across;
@ -350,7 +350,7 @@ fn stretch_tracks_sizes(
let delta = left_space / tracks.len() as f32;
for track in tracks.iter_mut() {
track.across_size = track.across_size + delta;
track.across_size += delta;
}
}
@ -358,7 +358,7 @@ fn calculate_track_positions(
layout_data: &LayoutData,
layout_axis: &LayoutAxis,
layout_bounds: &Bounds,
tracks: &mut Vec<TrackData>,
tracks: &mut [TrackData],
total_across_size: f32,
) {
let mut align_content = &layout_data.align_content;
@ -411,7 +411,7 @@ fn calculate_track_positions(
for track in tracks.iter_mut() {
track.anchor = next_anchor;
next_anchor = next_anchor + layout_axis.across_v * real_gap;
next_anchor += layout_axis.across_v * real_gap;
}
}
@ -450,7 +450,7 @@ fn calculate_track_data(
}
calculate_track_positions(
&layout_data,
layout_data,
&layout_axis,
layout_bounds,
&mut tracks,
@ -556,7 +556,7 @@ pub fn reflow_flex_layout(
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) -> VecDeque<Modifier> {
let mut result = VecDeque::new();
let layout_bounds = &bounds.find(&shape);
let layout_bounds = &bounds.find(shape);
let layout_axis = LayoutAxis::new(shape, layout_bounds, layout_data, flex_data);
let tracks = calculate_track_data(
shape,
@ -570,7 +570,7 @@ pub fn reflow_flex_layout(
for track in tracks.iter() {
let total_shapes_size = track.shapes.iter().map(|s| s.main_size).sum::<f32>();
let mut shape_anchor = first_anchor(&layout_data, &layout_axis, track, total_shapes_size);
let mut shape_anchor = first_anchor(layout_data, &layout_axis, track, total_shapes_size);
for child_axis in track.shapes.iter() {
let child_id = child_axis.id;
@ -602,7 +602,7 @@ pub fn reflow_flex_layout(
{
transform.post_concat(&math::resize_matrix(
layout_bounds,
&child_bounds,
child_bounds,
new_width,
new_height,
));
@ -615,10 +615,10 @@ pub fn reflow_flex_layout(
result.push_back(Modifier::transform(child.id, transform));
shape_anchor = next_anchor(
&layout_data,
layout_data,
&layout_axis,
&child_axis,
&track,
child_axis,
track,
shape_anchor,
total_shapes_size,
);
@ -681,9 +681,7 @@ pub fn reflow_flex_layout(
)
};
let parent_transform = layout_bounds
.transform_matrix()
.unwrap_or(Matrix::default());
let parent_transform = layout_bounds.transform_matrix().unwrap_or_default();
let parent_transform_inv = &parent_transform.invert().unwrap();
let origin = parent_transform_inv.map_point(layout_bounds.nw);
@ -692,7 +690,7 @@ pub fn reflow_flex_layout(
scale.post_translate(origin);
scale.post_concat(&parent_transform);
scale.pre_translate(-origin);
scale.pre_concat(&parent_transform_inv);
scale.pre_concat(parent_transform_inv);
let layout_bounds_after = layout_bounds.transform(&scale);
result.push_back(Modifier::parent(shape.id, scale));

View file

@ -33,6 +33,8 @@ struct TrackData {
anchor_end: Point,
}
// FIXME: We might be able to simplify these arguments
#[allow(clippy::too_many_arguments)]
fn calculate_tracks(
is_column: bool,
shape: &Shape,
@ -61,11 +63,12 @@ fn calculate_tracks(
set_flex_multi_span(is_column, &mut tracks, cells, shapes, bounds);
set_fr_value(is_column, shape, layout_data, &mut tracks, layout_size);
stretch_tracks(is_column, shape, layout_data, &mut tracks, layout_size);
assign_anchors(is_column, layout_data, &layout_bounds, &mut tracks);
return tracks;
assign_anchors(is_column, layout_data, layout_bounds, &mut tracks);
tracks
}
fn init_tracks(track: &Vec<GridTrack>, size: f32) -> Vec<TrackData> {
fn init_tracks(track: &[GridTrack], size: f32) -> Vec<TrackData> {
track
.iter()
.map(|t| {
@ -103,7 +106,7 @@ fn min_size(column: bool, shape: &Shape, bounds: &HashMap<Uuid, Bounds>) -> f32
// Go through cells to adjust auto sizes for span=1. Base is the max of its children
fn set_auto_base_size(
column: bool,
tracks: &mut Vec<TrackData>,
tracks: &mut [TrackData],
cells: &Vec<GridCell>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
@ -146,7 +149,7 @@ fn track_index(is_column: bool, c: &GridCell) -> (usize, usize) {
}
}
fn has_flex(is_column: bool, cell: &GridCell, tracks: &mut Vec<TrackData>) -> bool {
fn has_flex(is_column: bool, cell: &GridCell, tracks: &mut [TrackData]) -> bool {
let (start, end) = track_index(is_column, cell);
(start..end).any(|i| tracks[i].track_type == GridTrackType::Flex)
}
@ -154,8 +157,8 @@ fn has_flex(is_column: bool, cell: &GridCell, tracks: &mut Vec<TrackData>) -> bo
// Adjust multi-spaned cells with no flex columns
fn set_auto_multi_span(
column: bool,
tracks: &mut Vec<TrackData>,
cells: &Vec<GridCell>,
tracks: &mut [TrackData],
cells: &[GridCell],
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
) {
@ -193,11 +196,11 @@ fn set_auto_multi_span(
let (start, end) = track_index(column, cell);
// Distribute the size between the tracks that already have a set value
for i in start..end {
dist = dist - tracks[i].size;
for track in tracks[start..end].iter() {
dist -= track.size;
if tracks[i].track_type == GridTrackType::Auto {
num_auto = num_auto + 1;
if track.track_type == GridTrackType::Auto {
num_auto += 1;
}
}
@ -206,19 +209,19 @@ fn set_auto_multi_span(
let rest = dist / num_auto as f32;
// Distribute the space between auto tracks
for i in start..end {
if tracks[i].track_type == GridTrackType::Auto {
for track in tracks[start..end].iter_mut() {
if track.track_type == GridTrackType::Auto {
// dist = dist - track[i].size;
let new_size = if tracks[i].size + rest < tracks[i].max_size {
tracks[i].size + rest
let new_size = if track.size + rest < track.max_size {
track.size + rest
} else {
num_auto = num_auto - 1;
tracks[i].max_size
num_auto -= 1;
track.max_size
};
let aloc = new_size - tracks[i].size;
dist = dist - aloc;
tracks[i].size = tracks[i].size + aloc;
let aloc = new_size - track.size;
dist -= aloc;
track.size += aloc;
}
}
}
@ -228,8 +231,8 @@ fn set_auto_multi_span(
// Adjust multi-spaned cells with flex columns
fn set_flex_multi_span(
column: bool,
tracks: &mut Vec<TrackData>,
cells: &Vec<GridCell>,
tracks: &mut [TrackData],
cells: &[GridCell],
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &HashMap<Uuid, Bounds>,
) {
@ -269,16 +272,16 @@ fn set_flex_multi_span(
let (start, end) = track_index(column, cell);
// Distribute the size between the tracks that already have a set value
for i in start..end {
dist = dist - tracks[i].size;
for track in tracks[start..end].iter() {
dist -= track.size;
match tracks[i].track_type {
match track.track_type {
GridTrackType::Flex => {
num_flex = num_flex + tracks[i].value;
num_auto = num_auto + 1;
num_flex += track.value;
num_auto += 1;
}
GridTrackType::Auto => {
num_auto = num_auto + 1;
num_auto += 1;
}
_ => {}
}
@ -289,15 +292,15 @@ fn set_flex_multi_span(
continue;
}
let rest = dist / num_flex as f32;
let rest = dist / num_flex;
// Distribute the space between flex tracks in proportion to the division
for i in start..end {
if tracks[i].track_type == GridTrackType::Flex {
let new_size = f32::min(tracks[i].size + rest, tracks[i].max_size);
let aloc = new_size - tracks[i].size;
dist = dist - aloc;
tracks[i].size = tracks[i].size + aloc;
for track in tracks[start..end].iter_mut() {
if track.track_type == GridTrackType::Flex {
let new_size = f32::min(track.size + rest, track.max_size);
let aloc = new_size - track.size;
dist -= aloc;
track.size += aloc;
}
}
@ -305,20 +308,20 @@ fn set_flex_multi_span(
while dist > MIN_SIZE && num_auto > 0 {
let rest = dist / num_auto as f32;
for i in start..end {
if tracks[i].track_type == GridTrackType::Auto
|| tracks[i].track_type == GridTrackType::Flex
for track in tracks[start..end].iter_mut() {
if track.track_type == GridTrackType::Auto
|| track.track_type == GridTrackType::Flex
{
let new_size = if tracks[i].size + rest < tracks[i].max_size {
tracks[i].size + rest
let new_size = if track.size + rest < track.max_size {
track.size + rest
} else {
num_auto = num_auto - 1;
tracks[i].max_size
num_auto -= 1;
track.max_size
};
let aloc = new_size - tracks[i].size;
dist = dist - aloc;
tracks[i].size = tracks[i].size + aloc;
let aloc = new_size - track.size;
dist -= aloc;
track.size += aloc;
}
}
}
@ -330,7 +333,7 @@ fn set_fr_value(
column: bool,
shape: &Shape,
layout_data: &LayoutData,
tracks: &mut Vec<TrackData>,
tracks: &mut [TrackData],
layout_size: f32,
) {
let tot_gap: f32 = if column {
@ -380,7 +383,7 @@ fn stretch_tracks(
column: bool,
shape: &Shape,
layout_data: &LayoutData,
tracks: &mut Vec<TrackData>,
tracks: &mut [TrackData],
layout_size: f32,
) {
if (column
@ -481,7 +484,7 @@ fn assign_anchors(
_ => (padding_start + 0.0, gap),
};
cursor = cursor + (v * real_margin);
cursor += v * real_margin;
for track in tracks {
track.anchor_start = cursor;
@ -511,8 +514,8 @@ fn create_cell_data<'a>(
children: &IndexSet<Uuid>,
shapes: &'a HashMap<Uuid, &mut Shape>,
cells: &Vec<GridCell>,
column_tracks: &Vec<TrackData>,
row_tracks: &Vec<TrackData>,
column_tracks: &[TrackData],
row_tracks: &[TrackData],
) -> Vec<CellData<'a>> {
let mut result = Vec::<CellData<'a>>::new();
@ -614,11 +617,11 @@ fn child_position(
cell.anchor + vv * vpos + hv * hpos
}
pub fn reflow_grid_layout<'a>(
pub fn reflow_grid_layout(
shape: &Shape,
layout_data: &LayoutData,
grid_data: &GridData,
shapes: &'a HashMap<Uuid, &mut Shape>,
shapes: &HashMap<Uuid, &mut Shape>,
bounds: &mut HashMap<Uuid, Bounds>,
structure: &HashMap<Uuid, Vec<StructureEntry>>,
) -> VecDeque<Modifier> {
@ -693,9 +696,9 @@ pub fn reflow_grid_layout<'a>(
}
let position = child_position(
&child,
child,
&layout_bounds,
&layout_data,
layout_data,
&child_bounds,
child.layout_item,
cell,
@ -733,9 +736,7 @@ pub fn reflow_grid_layout<'a>(
scale_height = auto_height / height;
}
let parent_transform = layout_bounds
.transform_matrix()
.unwrap_or(Matrix::default());
let parent_transform = layout_bounds.transform_matrix().unwrap_or_default();
let parent_transform_inv = &parent_transform.invert().unwrap();
let origin = parent_transform_inv.map_point(layout_bounds.nw);
@ -744,7 +745,7 @@ pub fn reflow_grid_layout<'a>(
scale.post_translate(origin);
scale.post_concat(&parent_transform);
scale.pre_translate(-origin);
scale.pre_concat(&parent_transform_inv);
scale.pre_concat(parent_transform_inv);
let layout_bounds_after = layout_bounds.transform(&scale);
result.push_back(Modifier::parent(shape.id, scale));