layout: adaptive grid and vertical flex; enforce the mechanical style rules
grid_min_cell( width ) adds the adaptive mode WrapGrid was missing: instead of a fixed column count, the count is derived at layout time from the available width so every cell is at least `width` wide (any Length, so a fluid threshold works; never fewer than one column), re-derived on every resize. Cells then share the width equally, and WrapGrid::max_columns( n ) caps the derived count so cells grow instead of multiplying on very wide surfaces — the cap only applies to the adaptive mode, grid( n ) keeps the fixed behaviour untouched. Four new layout tests cover width derivation, spacing accounting, the one-column floor and the cap; the row-wrap assertions check X positions rather than Y because zero-height spacer children produce zero-height rows. flex( child ) now distributes leftover height inside a Column, mirroring its leftover-width behaviour in a Row: flex children join the weight pool alongside weight-only spacers and y-scrolls, draw their child inside the allocated share at full inner width, and contribute zero to the column's natural height exactly like a row counts flex width. This closes the documented "vertical flex is not yet implemented" gap; the Flex rustdoc and the widgets.md entry now describe both axes. Add scripts/style-check.sh and a make stylecheck target, wired into CI: mechanical verification of the grep-checkable subset of code_style_guide.md — tab indentation and spaces inside attribute brackets — with comment lines skipped so prose may cite raw attribute syntax. To turn the check on green, the 82 unspaced attribute sites across 24 files (#[test], #[derive(...)], #[cfg(...)], #[allow(...)]) were normalized to the spaced form. CONTRIBUTING and the style guide reference the new target; brace placement and paren spacing remain review concerns.
This commit is contained in:
@@ -26,7 +26,7 @@ use crate::render::Canvas;
|
||||
use crate::types::{ Rect, WidgetId };
|
||||
use crate::widget::Element;
|
||||
|
||||
#[cfg(test)]
|
||||
#[ cfg( test ) ]
|
||||
mod tests;
|
||||
|
||||
pub struct Carousel<Msg: Clone>
|
||||
|
||||
@@ -17,7 +17,7 @@ fn three_spacer_carousel() -> Carousel<()>
|
||||
.push( spacer() )
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ test ]
|
||||
fn empty_layout_is_empty()
|
||||
{
|
||||
let c: Carousel<()> = carousel();
|
||||
@@ -25,7 +25,7 @@ fn empty_layout_is_empty()
|
||||
assert!( c.layout( rect, &canvas() ).is_empty() );
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ test ]
|
||||
fn first_child_centred_at_offset_zero()
|
||||
{
|
||||
let c = three_spacer_carousel();
|
||||
@@ -36,7 +36,7 @@ fn first_child_centred_at_offset_zero()
|
||||
assert!( ( rects[0].0.width - 80.0 ).abs() < 0.01 );
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ test ]
|
||||
fn children_strided_by_child_width_plus_gap()
|
||||
{
|
||||
let c = carousel::<()>()
|
||||
@@ -50,7 +50,7 @@ fn children_strided_by_child_width_plus_gap()
|
||||
assert!( ( rects[1].0.x - ( rects[0].0.x + 108.0 ) ).abs() < 0.01 );
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ test ]
|
||||
fn snap_offset_centres_target_index()
|
||||
{
|
||||
let c = three_spacer_carousel();
|
||||
@@ -58,7 +58,7 @@ fn snap_offset_centres_target_index()
|
||||
assert!( ( c.snap_offset( 100.0, 2 ) - ( -160.0 ) ).abs() < 0.01 );
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ test ]
|
||||
fn focused_index_rounds_to_nearest_tile()
|
||||
{
|
||||
let mut c = three_spacer_carousel();
|
||||
@@ -68,7 +68,7 @@ fn focused_index_rounds_to_nearest_tile()
|
||||
assert_eq!( c.focused_index( 100.0 ), 1 );
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ test ]
|
||||
fn focused_index_clamps_to_valid_range()
|
||||
{
|
||||
let mut c = three_spacer_carousel();
|
||||
@@ -78,7 +78,7 @@ fn focused_index_clamps_to_valid_range()
|
||||
assert_eq!( c.focused_index( 100.0 ), 2 );
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ test ]
|
||||
fn offset_shifts_all_children_horizontally()
|
||||
{
|
||||
let c = three_spacer_carousel().offset( -25.0 );
|
||||
@@ -90,7 +90,7 @@ fn offset_shifts_all_children_horizontally()
|
||||
assert!( ( rects[1].0.x - rects[0].0.x - 80.0 ).abs() < 0.01 );
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ test ]
|
||||
fn focused_width_frac_is_clamped_to_unit_range()
|
||||
{
|
||||
let c: Carousel<()> = carousel().focused_width_frac( 5.0 ).push( spacer() );
|
||||
@@ -99,7 +99,7 @@ fn focused_width_frac_is_clamped_to_unit_range()
|
||||
assert!( c2.focused_width_frac > 0.0 );
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ test ]
|
||||
fn children_use_full_rect_height()
|
||||
{
|
||||
let c = three_spacer_carousel();
|
||||
|
||||
Reference in New Issue
Block a user