# bevy_ui Node reorganization ## Current Node structure: (comments removed) ```rust pub struct Node { pub display: Display, pub position_type: PositionType, pub overflow: Overflow, pub overflow_clip_margin: OverflowClipMargin, pub left: Val, pub right: Val, pub top: Val, pub bottom: Val, pub width: Val, pub height: Val, pub min_width: Val, pub min_height: Val, pub max_width: Val, pub max_height: Val, pub aspect_ratio: Option<f32>, pub align_items: AlignItems, pub justify_items: JustifyItems, pub align_self: AlignSelf, pub justify_self: JustifySelf, pub align_content: AlignContent, pub justify_content: JustifyContent, pub margin: UiRect, pub padding: UiRect, pub border: UiRect, pub flex_direction: FlexDirection, pub flex_wrap: FlexWrap, pub flex_grow: f32, pub flex_shrink: f32, pub flex_basis: Val, pub row_gap: Val, pub column_gap: Val, pub grid_auto_flow: GridAutoFlow, pub grid_template_rows: Vec<RepeatedGridTrack>, pub grid_template_columns: Vec<RepeatedGridTrack>, pub grid_auto_rows: Vec<GridTrack>, pub grid_auto_columns: Vec<GridTrack>, pub grid_row: GridPlacement, pub grid_column: GridPlacement, } ``` ## Proposal 1: ```rust pub struct Node { pub display: Display, pub position_type: PositionType, } pub struct NodeSize { pub width: Val, pub height: Val, pub min_width: Val, pub min_height: Val, pub max_width: Val, pub max_height: Val, } pub struct NodeOffset { pub left: Val, pub right: Val, pub top: Val, pub bottom: Val, } pub struct AspectRatio(f32); // Existing Overflow becomes a component. pub struct Overflow { pub x: OverflowAxis, pub y: OverflowAxis, pub clip_margin: OverflowClipMargin, } // The existing enums are simply made into components. // The reason for not grouping these in a struct is that // some are used for parents while others are used for children. pub enum AlignItems { ... }; pub enum AlignSelf { ... }; pub enum AlignContent { ... }; pub enum JustifyItems { ... }; pub enum JustifySelf { ... }; pub enum JustifyContent { ... }; pub struct Margin(UiRect); pub struct Padding(UiRect); pub struct BorderSize(UiRect); // Not simply `Border` because that's ambiguous // Gap between child nodes (Flex and Grid only) pub struct Gap { pub row_gap: Val, pub column_gap: Val, } // For nodes with Display::Flex pub struct FlexLayout { pub flex_direction: FlexDirection, pub flex_wrap: FlexWrap, } // For children of flex nodes pub struct FlexItem { pub flex_grow: f32, pub flex_shrink: f32, pub flex_basis: Val, } // For nodes with Display::Grid pub struct GridLayout { pub grid_auto_flow: GridAutoFlow, pub grid_template_rows: Vec<RepeatedGridTrack>, pub grid_template_columns: Vec<RepeatedGridTrack>, pub grid_auto_rows: Vec<GridTrack>, pub grid_auto_columns: Vec<GridTrack>, } // For children of grid nodes pub struct GridItem { pub grid_row: GridPlacement, pub grid_column: GridPlacement, } ``` Notes: * Any component not present will act as if it's default value were present.