Struct UiRect

Source
pub struct UiRect {
    pub left: Val,
    pub right: Val,
    pub top: Val,
    pub bottom: Val,
}
Expand description

A type which is commonly used to define margins, paddings and borders.

§Examples

§Margin

A margin is used to create space around UI elements, outside of any defined borders.

let margin = UiRect::all(Val::Auto); // Centers the UI element

§Padding

A padding is used to create space around UI elements, inside of any defined borders.

let padding = UiRect {
    left: Val::Px(10.0),
    right: Val::Px(20.0),
    top: Val::Px(30.0),
    bottom: Val::Px(40.0),
};

§Borders

A border is used to define the width of the border of a UI element.

let border = UiRect {
    left: Val::Px(10.0),
    right: Val::Px(20.0),
    top: Val::Px(30.0),
    bottom: Val::Px(40.0),
};

Fields§

§left: Val

The value corresponding to the left side of the UI rect.

§right: Val

The value corresponding to the right side of the UI rect.

§top: Val

The value corresponding to the top side of the UI rect.

§bottom: Val

The value corresponding to the bottom side of the UI rect.

Implementations§

Source§

impl UiRect

Source

pub const DEFAULT: UiRect

Source

pub const ZERO: UiRect

Source

pub const AUTO: UiRect

Source

pub const fn new(left: Val, right: Val, top: Val, bottom: Val) -> UiRect

Creates a new UiRect from the values specified.

§Example
let ui_rect = UiRect::new(
    Val::Px(10.0),
    Val::Px(20.0),
    Val::Px(30.0),
    Val::Px(40.0),
);

assert_eq!(ui_rect.left, Val::Px(10.0));
assert_eq!(ui_rect.right, Val::Px(20.0));
assert_eq!(ui_rect.top, Val::Px(30.0));
assert_eq!(ui_rect.bottom, Val::Px(40.0));
Source

pub const fn all(value: Val) -> UiRect

Creates a new UiRect where all sides have the same value.

§Example
let ui_rect = UiRect::all(Val::Px(10.0));

assert_eq!(ui_rect.left, Val::Px(10.0));
assert_eq!(ui_rect.right, Val::Px(10.0));
assert_eq!(ui_rect.top, Val::Px(10.0));
assert_eq!(ui_rect.bottom, Val::Px(10.0));
Examples found in repository?
examples/3d/../helpers/widgets.rs (line 28)
28pub const BUTTON_BORDER: UiRect = UiRect::all(Val::Px(1.0));
More examples
Hide additional examples
examples/app/log_layers_ecs.rs (line 133)
125fn setup(mut commands: Commands) {
126    commands.spawn(Camera2d);
127
128    commands.spawn((
129        Node {
130            width: Val::Vw(100.0),
131            height: Val::Vh(100.0),
132            flex_direction: FlexDirection::Column,
133            padding: UiRect::all(Val::Px(12.)),
134            ..default()
135        },
136        LogViewerRoot,
137    ));
138}
examples/ui/ghost_nodes.rs (line 79)
73fn create_button() -> impl Bundle {
74    (
75        Button,
76        Node {
77            width: Val::Px(150.0),
78            height: Val::Px(65.0),
79            border: UiRect::all(Val::Px(5.0)),
80            // horizontally center child text
81            justify_content: JustifyContent::Center,
82            // vertically center child text
83            align_items: AlignItems::Center,
84            ..default()
85        },
86        BorderColor(Color::BLACK),
87        BorderRadius::MAX,
88        BackgroundColor(Color::srgb(0.15, 0.15, 0.15)),
89    )
90}
examples/3d/split_screen.rs (line 118)
108    fn buttons_panel(parent: &mut ChildSpawnerCommands) {
109        parent
110            .spawn(Node {
111                position_type: PositionType::Absolute,
112                width: Val::Percent(100.),
113                height: Val::Percent(100.),
114                display: Display::Flex,
115                flex_direction: FlexDirection::Row,
116                justify_content: JustifyContent::SpaceBetween,
117                align_items: AlignItems::Center,
118                padding: UiRect::all(Val::Px(20.)),
119                ..default()
120            })
121            .with_children(|parent| {
122                rotate_button(parent, "<", Direction::Left);
123                rotate_button(parent, ">", Direction::Right);
124            });
125    }
126
127    fn rotate_button(parent: &mut ChildSpawnerCommands, caption: &str, direction: Direction) {
128        parent
129            .spawn((
130                RotateCamera(direction),
131                Button,
132                Node {
133                    width: Val::Px(40.),
134                    height: Val::Px(40.),
135                    border: UiRect::all(Val::Px(2.)),
136                    justify_content: JustifyContent::Center,
137                    align_items: AlignItems::Center,
138                    ..default()
139                },
140                BorderColor(Color::WHITE),
141                BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
142            ))
143            .with_children(|parent| {
144                parent.spawn(Text::new(caption));
145            });
146    }
examples/window/window_drag_move.rs (line 67)
58fn setup(mut commands: Commands) {
59    // Camera
60    commands.spawn(Camera3d::default());
61
62    // UI
63    commands
64        .spawn((
65            Node {
66                position_type: PositionType::Absolute,
67                padding: UiRect::all(Val::Px(5.0)),
68                ..default()
69            },
70            BackgroundColor(Color::BLACK.with_alpha(0.75)),
71            GlobalZIndex(i32::MAX),
72        ))
73        .with_children(|p| {
74            p.spawn(Text::default()).with_children(|p| {
75                p.spawn(TextSpan::new(
76                    "Demonstrate drag move and drag resize without window decorations.\n\n",
77                ));
78                p.spawn(TextSpan::new("Controls:\n"));
79                p.spawn(TextSpan::new("A - change left click action ["));
80                p.spawn(TextSpan::new("Move"));
81                p.spawn(TextSpan::new("]\n"));
82                p.spawn(TextSpan::new("S / D - change resize direction ["));
83                p.spawn(TextSpan::new("NorthWest"));
84                p.spawn(TextSpan::new("]\n"));
85            });
86        });
87}
examples/3d/tonemapping.rs (line 183)
150fn setup_image_viewer_scene(
151    mut commands: Commands,
152    mut meshes: ResMut<Assets<Mesh>>,
153    mut materials: ResMut<Assets<StandardMaterial>>,
154    camera_transform: Res<CameraTransform>,
155) {
156    let mut transform = camera_transform.0;
157    transform.translation += *transform.forward();
158
159    // exr/hdr viewer (exr requires enabling bevy feature)
160    commands.spawn((
161        Mesh3d(meshes.add(Rectangle::default())),
162        MeshMaterial3d(materials.add(StandardMaterial {
163            base_color_texture: None,
164            unlit: true,
165            ..default()
166        })),
167        transform,
168        Visibility::Hidden,
169        SceneNumber(3),
170        HDRViewer,
171    ));
172
173    commands.spawn((
174        Text::new("Drag and drop an HDR or EXR file"),
175        TextFont {
176            font_size: 36.0,
177            ..default()
178        },
179        TextColor(Color::BLACK),
180        TextLayout::new_with_justify(JustifyText::Center),
181        Node {
182            align_self: AlignSelf::Center,
183            margin: UiRect::all(Val::Auto),
184            ..default()
185        },
186        SceneNumber(3),
187        Visibility::Hidden,
188    ));
189}
Source

pub const fn px(left: f32, right: f32, top: f32, bottom: f32) -> UiRect

Creates a new UiRect from the values specified in logical pixels.

This is a shortcut for UiRect::new(), applying Val::Px to all arguments.

§Example
let ui_rect = UiRect::px(10., 20., 30., 40.);
assert_eq!(ui_rect.left, Val::Px(10.));
assert_eq!(ui_rect.right, Val::Px(20.));
assert_eq!(ui_rect.top, Val::Px(30.));
assert_eq!(ui_rect.bottom, Val::Px(40.));
Source

pub const fn percent(left: f32, right: f32, top: f32, bottom: f32) -> UiRect

Creates a new UiRect from the values specified in percentages.

This is a shortcut for UiRect::new(), applying Val::Percent to all arguments.

§Example
let ui_rect = UiRect::percent(5., 10., 2., 1.);
assert_eq!(ui_rect.left, Val::Percent(5.));
assert_eq!(ui_rect.right, Val::Percent(10.));
assert_eq!(ui_rect.top, Val::Percent(2.));
assert_eq!(ui_rect.bottom, Val::Percent(1.));
Source

pub const fn horizontal(value: Val) -> UiRect

Creates a new UiRect where left and right take the given value, and top and bottom set to zero Val::ZERO.

§Example
let ui_rect = UiRect::horizontal(Val::Px(10.0));

assert_eq!(ui_rect.left, Val::Px(10.0));
assert_eq!(ui_rect.right, Val::Px(10.0));
assert_eq!(ui_rect.top, Val::ZERO);
assert_eq!(ui_rect.bottom, Val::ZERO);
Examples found in repository?
examples/ui/size_constraints.rs (line 221)
206fn spawn_button(
207    parent: &mut ChildSpawnerCommands,
208    constraint: Constraint,
209    action: ButtonValue,
210    label: String,
211    text_style: (TextFont, TextColor),
212    active: bool,
213) {
214    parent
215        .spawn((
216            Button,
217            Node {
218                align_items: AlignItems::Center,
219                justify_content: JustifyContent::Center,
220                border: UiRect::all(Val::Px(2.)),
221                margin: UiRect::horizontal(Val::Px(2.)),
222                ..Default::default()
223            },
224            BorderColor(if active {
225                ACTIVE_BORDER_COLOR
226            } else {
227                INACTIVE_BORDER_COLOR
228            }),
229            constraint,
230            action,
231        ))
232        .with_children(|parent| {
233            parent
234                .spawn((
235                    Node {
236                        width: Val::Px(100.),
237                        justify_content: JustifyContent::Center,
238                        ..default()
239                    },
240                    BackgroundColor(if active {
241                        ACTIVE_INNER_COLOR
242                    } else {
243                        INACTIVE_INNER_COLOR
244                    }),
245                ))
246                .with_child((
247                    Text::new(label),
248                    text_style.0,
249                    TextColor(if active {
250                        ACTIVE_TEXT_COLOR
251                    } else {
252                        UNHOVERED_TEXT_COLOR
253                    }),
254                    TextLayout::new_with_justify(JustifyText::Center),
255                ));
256        });
257}
More examples
Hide additional examples
examples/ui/overflow.rs (line 44)
15fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
16    commands.spawn(Camera2d);
17
18    let text_style = TextFont::default();
19
20    let image = asset_server.load("branding/icon.png");
21
22    commands
23        .spawn((
24            Node {
25                width: Val::Percent(100.),
26                height: Val::Percent(100.),
27                align_items: AlignItems::Center,
28                justify_content: JustifyContent::Center,
29                ..Default::default()
30            },
31            BackgroundColor(ANTIQUE_WHITE.into()),
32        ))
33        .with_children(|parent| {
34            for overflow in [
35                Overflow::visible(),
36                Overflow::clip_x(),
37                Overflow::clip_y(),
38                Overflow::clip(),
39            ] {
40                parent
41                    .spawn(Node {
42                        flex_direction: FlexDirection::Column,
43                        align_items: AlignItems::Center,
44                        margin: UiRect::horizontal(Val::Px(25.)),
45                        ..Default::default()
46                    })
47                    .with_children(|parent| {
48                        let label = format!("{overflow:#?}");
49                        parent
50                            .spawn((
51                                Node {
52                                    padding: UiRect::all(Val::Px(10.)),
53                                    margin: UiRect::bottom(Val::Px(25.)),
54                                    ..Default::default()
55                                },
56                                BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
57                            ))
58                            .with_children(|parent| {
59                                parent.spawn((Text::new(label), text_style.clone()));
60                            });
61                        parent
62                            .spawn((
63                                Node {
64                                    width: Val::Px(100.),
65                                    height: Val::Px(100.),
66                                    padding: UiRect {
67                                        left: Val::Px(25.),
68                                        top: Val::Px(25.),
69                                        ..Default::default()
70                                    },
71                                    border: UiRect::all(Val::Px(5.)),
72                                    overflow,
73                                    ..default()
74                                },
75                                BorderColor(Color::BLACK),
76                                BackgroundColor(GRAY.into()),
77                            ))
78                            .with_children(|parent| {
79                                parent.spawn((
80                                    ImageNode::new(image.clone()),
81                                    Node {
82                                        min_width: Val::Px(100.),
83                                        min_height: Val::Px(100.),
84                                        ..default()
85                                    },
86                                    Interaction::default(),
87                                    Outline {
88                                        width: Val::Px(2.),
89                                        offset: Val::Px(2.),
90                                        color: Color::NONE,
91                                    },
92                                ));
93                            });
94                    });
95            }
96        });
97}
examples/ui/borders.rs (line 75)
12fn setup(mut commands: Commands) {
13    commands.spawn(Camera2d);
14    let root = commands
15        .spawn((
16            Node {
17                margin: UiRect::all(Val::Px(25.0)),
18                align_self: AlignSelf::Stretch,
19                justify_self: JustifySelf::Stretch,
20                flex_wrap: FlexWrap::Wrap,
21                justify_content: JustifyContent::FlexStart,
22                align_items: AlignItems::FlexStart,
23                align_content: AlignContent::FlexStart,
24                ..default()
25            },
26            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
27        ))
28        .id();
29
30    let root_rounded = commands
31        .spawn((
32            Node {
33                margin: UiRect::all(Val::Px(25.0)),
34                align_self: AlignSelf::Stretch,
35                justify_self: JustifySelf::Stretch,
36                flex_wrap: FlexWrap::Wrap,
37                justify_content: JustifyContent::FlexStart,
38                align_items: AlignItems::FlexStart,
39                align_content: AlignContent::FlexStart,
40                ..default()
41            },
42            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
43        ))
44        .id();
45
46    // labels for the different border edges
47    let border_labels = [
48        "None",
49        "All",
50        "Left",
51        "Right",
52        "Top",
53        "Bottom",
54        "Horizontal",
55        "Vertical",
56        "Top Left",
57        "Bottom Left",
58        "Top Right",
59        "Bottom Right",
60        "Top Bottom Right",
61        "Top Bottom Left",
62        "Top Left Right",
63        "Bottom Left Right",
64    ];
65
66    // all the different combinations of border edges
67    // these correspond to the labels above
68    let borders = [
69        UiRect::default(),
70        UiRect::all(Val::Px(10.)),
71        UiRect::left(Val::Px(10.)),
72        UiRect::right(Val::Px(10.)),
73        UiRect::top(Val::Px(10.)),
74        UiRect::bottom(Val::Px(10.)),
75        UiRect::horizontal(Val::Px(10.)),
76        UiRect::vertical(Val::Px(10.)),
77        UiRect {
78            left: Val::Px(20.),
79            top: Val::Px(10.),
80            ..Default::default()
81        },
82        UiRect {
83            left: Val::Px(10.),
84            bottom: Val::Px(20.),
85            ..Default::default()
86        },
87        UiRect {
88            right: Val::Px(20.),
89            top: Val::Px(10.),
90            ..Default::default()
91        },
92        UiRect {
93            right: Val::Px(10.),
94            bottom: Val::Px(10.),
95            ..Default::default()
96        },
97        UiRect {
98            right: Val::Px(10.),
99            top: Val::Px(20.),
100            bottom: Val::Px(10.),
101            ..Default::default()
102        },
103        UiRect {
104            left: Val::Px(10.),
105            top: Val::Px(10.),
106            bottom: Val::Px(10.),
107            ..Default::default()
108        },
109        UiRect {
110            left: Val::Px(20.),
111            right: Val::Px(10.),
112            top: Val::Px(10.),
113            ..Default::default()
114        },
115        UiRect {
116            left: Val::Px(10.),
117            right: Val::Px(10.),
118            bottom: Val::Px(20.),
119            ..Default::default()
120        },
121    ];
122
123    for (label, border) in border_labels.into_iter().zip(borders) {
124        let inner_spot = commands
125            .spawn((
126                Node {
127                    width: Val::Px(10.),
128                    height: Val::Px(10.),
129                    ..default()
130                },
131                BackgroundColor(YELLOW.into()),
132            ))
133            .id();
134        let border_node = commands
135            .spawn((
136                Node {
137                    width: Val::Px(50.),
138                    height: Val::Px(50.),
139                    border,
140                    margin: UiRect::all(Val::Px(20.)),
141                    align_items: AlignItems::Center,
142                    justify_content: JustifyContent::Center,
143                    ..default()
144                },
145                BackgroundColor(MAROON.into()),
146                BorderColor(RED.into()),
147                Outline {
148                    width: Val::Px(6.),
149                    offset: Val::Px(6.),
150                    color: Color::WHITE,
151                },
152            ))
153            .add_child(inner_spot)
154            .id();
155        let label_node = commands
156            .spawn((
157                Text::new(label),
158                TextFont {
159                    font_size: 9.0,
160                    ..Default::default()
161                },
162            ))
163            .id();
164        let container = commands
165            .spawn(Node {
166                flex_direction: FlexDirection::Column,
167                align_items: AlignItems::Center,
168                ..default()
169            })
170            .add_children(&[border_node, label_node])
171            .id();
172        commands.entity(root).add_child(container);
173    }
174
175    for (label, border) in border_labels.into_iter().zip(borders) {
176        let inner_spot = commands
177            .spawn((
178                Node {
179                    width: Val::Px(10.),
180                    height: Val::Px(10.),
181                    ..default()
182                },
183                BorderRadius::MAX,
184                BackgroundColor(YELLOW.into()),
185            ))
186            .id();
187        let non_zero = |x, y| x != Val::Px(0.) && y != Val::Px(0.);
188        let border_size = |x, y| if non_zero(x, y) { f32::MAX } else { 0. };
189        let border_radius = BorderRadius::px(
190            border_size(border.left, border.top),
191            border_size(border.right, border.top),
192            border_size(border.right, border.bottom),
193            border_size(border.left, border.bottom),
194        );
195        let border_node = commands
196            .spawn((
197                Node {
198                    width: Val::Px(50.),
199                    height: Val::Px(50.),
200                    border,
201                    margin: UiRect::all(Val::Px(20.)),
202                    align_items: AlignItems::Center,
203                    justify_content: JustifyContent::Center,
204                    ..default()
205                },
206                BackgroundColor(MAROON.into()),
207                BorderColor(RED.into()),
208                border_radius,
209                Outline {
210                    width: Val::Px(6.),
211                    offset: Val::Px(6.),
212                    color: Color::WHITE,
213                },
214            ))
215            .add_child(inner_spot)
216            .id();
217        let label_node = commands
218            .spawn((
219                Text::new(label),
220                TextFont {
221                    font_size: 9.0,
222                    ..Default::default()
223                },
224            ))
225            .id();
226        let container = commands
227            .spawn(Node {
228                flex_direction: FlexDirection::Column,
229                align_items: AlignItems::Center,
230                ..default()
231            })
232            .add_children(&[border_node, label_node])
233            .id();
234        commands.entity(root_rounded).add_child(container);
235    }
236
237    let border_label = commands
238        .spawn((
239            Node {
240                margin: UiRect {
241                    left: Val::Px(25.0),
242                    right: Val::Px(25.0),
243                    top: Val::Px(25.0),
244                    bottom: Val::Px(0.0),
245                },
246                ..default()
247            },
248            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
249        ))
250        .with_children(|builder| {
251            builder.spawn((
252                Text::new("Borders"),
253                TextFont {
254                    font_size: 20.0,
255                    ..Default::default()
256                },
257            ));
258        })
259        .id();
260
261    let border_rounded_label = commands
262        .spawn((
263            Node {
264                margin: UiRect {
265                    left: Val::Px(25.0),
266                    right: Val::Px(25.0),
267                    top: Val::Px(25.0),
268                    bottom: Val::Px(0.0),
269                },
270                ..default()
271            },
272            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
273        ))
274        .with_children(|builder| {
275            builder.spawn((
276                Text::new("Borders Rounded"),
277                TextFont {
278                    font_size: 20.0,
279                    ..Default::default()
280                },
281            ));
282        })
283        .id();
284
285    commands
286        .spawn((
287            Node {
288                margin: UiRect::all(Val::Px(25.0)),
289                flex_direction: FlexDirection::Column,
290                align_self: AlignSelf::Stretch,
291                justify_self: JustifySelf::Stretch,
292                flex_wrap: FlexWrap::Wrap,
293                justify_content: JustifyContent::FlexStart,
294                align_items: AlignItems::FlexStart,
295                align_content: AlignContent::FlexStart,
296                ..default()
297            },
298            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
299        ))
300        .add_child(border_label)
301        .add_child(root)
302        .add_child(border_rounded_label)
303        .add_child(root_rounded);
304}
Source

pub const fn vertical(value: Val) -> UiRect

Creates a new UiRect where top and bottom take the given value, and left and right are set to Val::ZERO.

§Example
let ui_rect = UiRect::vertical(Val::Px(10.0));

assert_eq!(ui_rect.left, Val::ZERO);
assert_eq!(ui_rect.right, Val::ZERO);
assert_eq!(ui_rect.top, Val::Px(10.0));
assert_eq!(ui_rect.bottom, Val::Px(10.0));
Examples found in repository?
examples/testbed/ui.rs (line 186)
169    pub fn setup(mut commands: Commands) {
170        commands.spawn((Camera2d, StateScoped(super::Scene::Borders)));
171        let root = commands
172            .spawn((
173                Node {
174                    flex_wrap: FlexWrap::Wrap,
175                    ..default()
176                },
177                StateScoped(super::Scene::Borders),
178            ))
179            .id();
180
181        // all the different combinations of border edges
182        let borders = [
183            UiRect::default(),
184            UiRect::all(Val::Px(20.)),
185            UiRect::left(Val::Px(20.)),
186            UiRect::vertical(Val::Px(20.)),
187            UiRect {
188                left: Val::Px(40.),
189                top: Val::Px(20.),
190                ..Default::default()
191            },
192            UiRect {
193                right: Val::Px(20.),
194                bottom: Val::Px(30.),
195                ..Default::default()
196            },
197            UiRect {
198                right: Val::Px(20.),
199                top: Val::Px(40.),
200                bottom: Val::Px(20.),
201                ..Default::default()
202            },
203            UiRect {
204                left: Val::Px(20.),
205                top: Val::Px(20.),
206                bottom: Val::Px(20.),
207                ..Default::default()
208            },
209            UiRect {
210                left: Val::Px(20.),
211                right: Val::Px(20.),
212                bottom: Val::Px(40.),
213                ..Default::default()
214            },
215        ];
216
217        let non_zero = |x, y| x != Val::Px(0.) && y != Val::Px(0.);
218        let border_size = |x, y| if non_zero(x, y) { f32::MAX } else { 0. };
219
220        for border in borders {
221            for rounded in [true, false] {
222                let border_node = commands
223                    .spawn((
224                        Node {
225                            width: Val::Px(100.),
226                            height: Val::Px(100.),
227                            border,
228                            margin: UiRect::all(Val::Px(30.)),
229                            align_items: AlignItems::Center,
230                            justify_content: JustifyContent::Center,
231                            ..default()
232                        },
233                        BackgroundColor(MAROON.into()),
234                        BorderColor(RED.into()),
235                        Outline {
236                            width: Val::Px(10.),
237                            offset: Val::Px(10.),
238                            color: Color::WHITE,
239                        },
240                    ))
241                    .id();
242
243                if rounded {
244                    let border_radius = BorderRadius::px(
245                        border_size(border.left, border.top),
246                        border_size(border.right, border.top),
247                        border_size(border.right, border.bottom),
248                        border_size(border.left, border.bottom),
249                    );
250                    commands.entity(border_node).insert(border_radius);
251                }
252
253                commands.entity(root).add_child(border_node);
254            }
255        }
256    }
More examples
Hide additional examples
examples/animation/animation_masks.rs (line 280)
227fn add_mask_group_control(
228    parent: &mut ChildSpawnerCommands,
229    label: &str,
230    width: Val,
231    mask_group_id: u32,
232) {
233    let button_text_style = (
234        TextFont {
235            font_size: 14.0,
236            ..default()
237        },
238        TextColor::WHITE,
239    );
240    let selected_button_text_style = (button_text_style.0.clone(), TextColor::BLACK);
241    let label_text_style = (
242        button_text_style.0.clone(),
243        TextColor(Color::Srgba(LIGHT_GRAY)),
244    );
245
246    parent
247        .spawn((
248            Node {
249                border: UiRect::all(Val::Px(1.0)),
250                width,
251                flex_direction: FlexDirection::Column,
252                justify_content: JustifyContent::Center,
253                align_items: AlignItems::Center,
254                padding: UiRect::ZERO,
255                margin: UiRect::ZERO,
256                ..default()
257            },
258            BorderColor(Color::WHITE),
259            BorderRadius::all(Val::Px(3.0)),
260            BackgroundColor(Color::BLACK),
261        ))
262        .with_children(|builder| {
263            builder
264                .spawn((
265                    Node {
266                        border: UiRect::ZERO,
267                        width: Val::Percent(100.0),
268                        justify_content: JustifyContent::Center,
269                        align_items: AlignItems::Center,
270                        padding: UiRect::ZERO,
271                        margin: UiRect::ZERO,
272                        ..default()
273                    },
274                    BackgroundColor(Color::BLACK),
275                ))
276                .with_child((
277                    Text::new(label),
278                    label_text_style.clone(),
279                    Node {
280                        margin: UiRect::vertical(Val::Px(3.0)),
281                        ..default()
282                    },
283                ));
284
285            builder
286                .spawn((
287                    Node {
288                        width: Val::Percent(100.0),
289                        flex_direction: FlexDirection::Row,
290                        justify_content: JustifyContent::Center,
291                        align_items: AlignItems::Center,
292                        border: UiRect::top(Val::Px(1.0)),
293                        ..default()
294                    },
295                    BorderColor(Color::WHITE),
296                ))
297                .with_children(|builder| {
298                    for (index, label) in [
299                        AnimationLabel::Run,
300                        AnimationLabel::Walk,
301                        AnimationLabel::Idle,
302                        AnimationLabel::Off,
303                    ]
304                    .iter()
305                    .enumerate()
306                    {
307                        builder
308                            .spawn((
309                                Button,
310                                BackgroundColor(if index > 0 {
311                                    Color::BLACK
312                                } else {
313                                    Color::WHITE
314                                }),
315                                Node {
316                                    flex_grow: 1.0,
317                                    border: if index > 0 {
318                                        UiRect::left(Val::Px(1.0))
319                                    } else {
320                                        UiRect::ZERO
321                                    },
322                                    ..default()
323                                },
324                                BorderColor(Color::WHITE),
325                                AnimationControl {
326                                    group_id: mask_group_id,
327                                    label: *label,
328                                },
329                            ))
330                            .with_child((
331                                Text(format!("{:?}", label)),
332                                if index > 0 {
333                                    button_text_style.clone()
334                                } else {
335                                    selected_button_text_style.clone()
336                                },
337                                TextLayout::new_with_justify(JustifyText::Center),
338                                Node {
339                                    flex_grow: 1.0,
340                                    margin: UiRect::vertical(Val::Px(3.0)),
341                                    ..default()
342                                },
343                            ));
344                    }
345                });
346        });
347}
examples/ui/borders.rs (line 76)
12fn setup(mut commands: Commands) {
13    commands.spawn(Camera2d);
14    let root = commands
15        .spawn((
16            Node {
17                margin: UiRect::all(Val::Px(25.0)),
18                align_self: AlignSelf::Stretch,
19                justify_self: JustifySelf::Stretch,
20                flex_wrap: FlexWrap::Wrap,
21                justify_content: JustifyContent::FlexStart,
22                align_items: AlignItems::FlexStart,
23                align_content: AlignContent::FlexStart,
24                ..default()
25            },
26            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
27        ))
28        .id();
29
30    let root_rounded = commands
31        .spawn((
32            Node {
33                margin: UiRect::all(Val::Px(25.0)),
34                align_self: AlignSelf::Stretch,
35                justify_self: JustifySelf::Stretch,
36                flex_wrap: FlexWrap::Wrap,
37                justify_content: JustifyContent::FlexStart,
38                align_items: AlignItems::FlexStart,
39                align_content: AlignContent::FlexStart,
40                ..default()
41            },
42            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
43        ))
44        .id();
45
46    // labels for the different border edges
47    let border_labels = [
48        "None",
49        "All",
50        "Left",
51        "Right",
52        "Top",
53        "Bottom",
54        "Horizontal",
55        "Vertical",
56        "Top Left",
57        "Bottom Left",
58        "Top Right",
59        "Bottom Right",
60        "Top Bottom Right",
61        "Top Bottom Left",
62        "Top Left Right",
63        "Bottom Left Right",
64    ];
65
66    // all the different combinations of border edges
67    // these correspond to the labels above
68    let borders = [
69        UiRect::default(),
70        UiRect::all(Val::Px(10.)),
71        UiRect::left(Val::Px(10.)),
72        UiRect::right(Val::Px(10.)),
73        UiRect::top(Val::Px(10.)),
74        UiRect::bottom(Val::Px(10.)),
75        UiRect::horizontal(Val::Px(10.)),
76        UiRect::vertical(Val::Px(10.)),
77        UiRect {
78            left: Val::Px(20.),
79            top: Val::Px(10.),
80            ..Default::default()
81        },
82        UiRect {
83            left: Val::Px(10.),
84            bottom: Val::Px(20.),
85            ..Default::default()
86        },
87        UiRect {
88            right: Val::Px(20.),
89            top: Val::Px(10.),
90            ..Default::default()
91        },
92        UiRect {
93            right: Val::Px(10.),
94            bottom: Val::Px(10.),
95            ..Default::default()
96        },
97        UiRect {
98            right: Val::Px(10.),
99            top: Val::Px(20.),
100            bottom: Val::Px(10.),
101            ..Default::default()
102        },
103        UiRect {
104            left: Val::Px(10.),
105            top: Val::Px(10.),
106            bottom: Val::Px(10.),
107            ..Default::default()
108        },
109        UiRect {
110            left: Val::Px(20.),
111            right: Val::Px(10.),
112            top: Val::Px(10.),
113            ..Default::default()
114        },
115        UiRect {
116            left: Val::Px(10.),
117            right: Val::Px(10.),
118            bottom: Val::Px(20.),
119            ..Default::default()
120        },
121    ];
122
123    for (label, border) in border_labels.into_iter().zip(borders) {
124        let inner_spot = commands
125            .spawn((
126                Node {
127                    width: Val::Px(10.),
128                    height: Val::Px(10.),
129                    ..default()
130                },
131                BackgroundColor(YELLOW.into()),
132            ))
133            .id();
134        let border_node = commands
135            .spawn((
136                Node {
137                    width: Val::Px(50.),
138                    height: Val::Px(50.),
139                    border,
140                    margin: UiRect::all(Val::Px(20.)),
141                    align_items: AlignItems::Center,
142                    justify_content: JustifyContent::Center,
143                    ..default()
144                },
145                BackgroundColor(MAROON.into()),
146                BorderColor(RED.into()),
147                Outline {
148                    width: Val::Px(6.),
149                    offset: Val::Px(6.),
150                    color: Color::WHITE,
151                },
152            ))
153            .add_child(inner_spot)
154            .id();
155        let label_node = commands
156            .spawn((
157                Text::new(label),
158                TextFont {
159                    font_size: 9.0,
160                    ..Default::default()
161                },
162            ))
163            .id();
164        let container = commands
165            .spawn(Node {
166                flex_direction: FlexDirection::Column,
167                align_items: AlignItems::Center,
168                ..default()
169            })
170            .add_children(&[border_node, label_node])
171            .id();
172        commands.entity(root).add_child(container);
173    }
174
175    for (label, border) in border_labels.into_iter().zip(borders) {
176        let inner_spot = commands
177            .spawn((
178                Node {
179                    width: Val::Px(10.),
180                    height: Val::Px(10.),
181                    ..default()
182                },
183                BorderRadius::MAX,
184                BackgroundColor(YELLOW.into()),
185            ))
186            .id();
187        let non_zero = |x, y| x != Val::Px(0.) && y != Val::Px(0.);
188        let border_size = |x, y| if non_zero(x, y) { f32::MAX } else { 0. };
189        let border_radius = BorderRadius::px(
190            border_size(border.left, border.top),
191            border_size(border.right, border.top),
192            border_size(border.right, border.bottom),
193            border_size(border.left, border.bottom),
194        );
195        let border_node = commands
196            .spawn((
197                Node {
198                    width: Val::Px(50.),
199                    height: Val::Px(50.),
200                    border,
201                    margin: UiRect::all(Val::Px(20.)),
202                    align_items: AlignItems::Center,
203                    justify_content: JustifyContent::Center,
204                    ..default()
205                },
206                BackgroundColor(MAROON.into()),
207                BorderColor(RED.into()),
208                border_radius,
209                Outline {
210                    width: Val::Px(6.),
211                    offset: Val::Px(6.),
212                    color: Color::WHITE,
213                },
214            ))
215            .add_child(inner_spot)
216            .id();
217        let label_node = commands
218            .spawn((
219                Text::new(label),
220                TextFont {
221                    font_size: 9.0,
222                    ..Default::default()
223                },
224            ))
225            .id();
226        let container = commands
227            .spawn(Node {
228                flex_direction: FlexDirection::Column,
229                align_items: AlignItems::Center,
230                ..default()
231            })
232            .add_children(&[border_node, label_node])
233            .id();
234        commands.entity(root_rounded).add_child(container);
235    }
236
237    let border_label = commands
238        .spawn((
239            Node {
240                margin: UiRect {
241                    left: Val::Px(25.0),
242                    right: Val::Px(25.0),
243                    top: Val::Px(25.0),
244                    bottom: Val::Px(0.0),
245                },
246                ..default()
247            },
248            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
249        ))
250        .with_children(|builder| {
251            builder.spawn((
252                Text::new("Borders"),
253                TextFont {
254                    font_size: 20.0,
255                    ..Default::default()
256                },
257            ));
258        })
259        .id();
260
261    let border_rounded_label = commands
262        .spawn((
263            Node {
264                margin: UiRect {
265                    left: Val::Px(25.0),
266                    right: Val::Px(25.0),
267                    top: Val::Px(25.0),
268                    bottom: Val::Px(0.0),
269                },
270                ..default()
271            },
272            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
273        ))
274        .with_children(|builder| {
275            builder.spawn((
276                Text::new("Borders Rounded"),
277                TextFont {
278                    font_size: 20.0,
279                    ..Default::default()
280                },
281            ));
282        })
283        .id();
284
285    commands
286        .spawn((
287            Node {
288                margin: UiRect::all(Val::Px(25.0)),
289                flex_direction: FlexDirection::Column,
290                align_self: AlignSelf::Stretch,
291                justify_self: JustifySelf::Stretch,
292                flex_wrap: FlexWrap::Wrap,
293                justify_content: JustifyContent::FlexStart,
294                align_items: AlignItems::FlexStart,
295                align_content: AlignContent::FlexStart,
296                ..default()
297            },
298            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
299        ))
300        .add_child(border_label)
301        .add_child(root)
302        .add_child(border_rounded_label)
303        .add_child(root_rounded);
304}
Source

pub const fn axes(horizontal: Val, vertical: Val) -> UiRect

Creates a new UiRect where both left and right take the value of horizontal, and both top and bottom take the value of vertical.

§Example
let ui_rect = UiRect::axes(Val::Px(10.0), Val::Percent(15.0));

assert_eq!(ui_rect.left, Val::Px(10.0));
assert_eq!(ui_rect.right, Val::Px(10.0));
assert_eq!(ui_rect.top, Val::Percent(15.0));
assert_eq!(ui_rect.bottom, Val::Percent(15.0));
Examples found in repository?
examples/3d/../helpers/widgets.rs (line 37)
37pub const BUTTON_PADDING: UiRect = UiRect::axes(Val::Px(12.0), Val::Px(6.0));
More examples
Hide additional examples
examples/ui/flex_layout.rs (line 158)
147fn spawn_nested_text_bundle(
148    builder: &mut ChildSpawnerCommands,
149    font: Handle<Font>,
150    background_color: Color,
151    margin: UiRect,
152    text: &str,
153) {
154    builder
155        .spawn((
156            Node {
157                margin,
158                padding: UiRect::axes(Val::Px(5.), Val::Px(1.)),
159                ..default()
160            },
161            BackgroundColor(background_color),
162        ))
163        .with_children(|builder| {
164            builder.spawn((
165                Text::new(text),
166                TextFont { font, ..default() },
167                TextColor::BLACK,
168            ));
169        });
170}
examples/ui/display_and_visibility.rs (line 389)
379fn spawn_button<T>(parent: &mut ChildSpawnerCommands, text_font: TextFont, target: Entity)
380where
381    T: Default + std::fmt::Debug + Send + Sync + 'static,
382    Target<T>: TargetUpdate,
383{
384    parent
385        .spawn((
386            Button,
387            Node {
388                align_self: AlignSelf::FlexStart,
389                padding: UiRect::axes(Val::Px(5.), Val::Px(1.)),
390                ..default()
391            },
392            BackgroundColor(Color::BLACK.with_alpha(0.5)),
393            Target::<T>::new(target),
394        ))
395        .with_children(|builder| {
396            builder.spawn((
397                Text(format!("{}::{:?}", Target::<T>::NAME, T::default())),
398                text_font,
399                TextLayout::new_with_justify(JustifyText::Center),
400            ));
401        });
402}
examples/stress_tests/many_buttons.rs (line 275)
262fn spawn_button(
263    commands: &mut ChildSpawnerCommands,
264    background_color: Color,
265    buttons: f32,
266    column: usize,
267    row: usize,
268    spawn_text: bool,
269    border: UiRect,
270    border_color: BorderColor,
271    image: Option<Handle<Image>>,
272) {
273    let width = Val::Vw(90.0 / buttons);
274    let height = Val::Vh(90.0 / buttons);
275    let margin = UiRect::axes(width * 0.05, height * 0.05);
276    let mut builder = commands.spawn((
277        Button,
278        Node {
279            width,
280            height,
281            margin,
282            align_items: AlignItems::Center,
283            justify_content: JustifyContent::Center,
284            border,
285            ..default()
286        },
287        BackgroundColor(background_color),
288        border_color,
289        IdleColor(background_color),
290    ));
291
292    if let Some(image) = image {
293        builder.insert(ImageNode::new(image));
294    }
295
296    if spawn_text {
297        builder.with_children(|parent| {
298            // These labels are split to stress test multi-span text
299            parent
300                .spawn((
301                    Text(format!("{column}, ")),
302                    TextFont {
303                        font_size: FONT_SIZE,
304                        ..default()
305                    },
306                    TextColor(Color::srgb(0.5, 0.2, 0.2)),
307                ))
308                .with_child((
309                    TextSpan(format!("{row}")),
310                    TextFont {
311                        font_size: FONT_SIZE,
312                        ..default()
313                    },
314                    TextColor(Color::srgb(0.2, 0.2, 0.5)),
315                ));
316        });
317    }
318}
examples/3d/color_grading.rs (line 251)
236fn add_button_for_value(
237    parent: &mut ChildSpawnerCommands,
238    option: SelectedColorGradingOption,
239    color_grading: &ColorGrading,
240    font: &Handle<Font>,
241) {
242    // Add the button node.
243    parent
244        .spawn((
245            Button,
246            Node {
247                border: UiRect::all(Val::Px(1.0)),
248                width: Val::Px(200.0),
249                justify_content: JustifyContent::Center,
250                align_items: AlignItems::Center,
251                padding: UiRect::axes(Val::Px(12.0), Val::Px(6.0)),
252                margin: UiRect::right(Val::Px(12.0)),
253                ..default()
254            },
255            BorderColor(Color::WHITE),
256            BorderRadius::MAX,
257            BackgroundColor(Color::BLACK),
258        ))
259        .insert(ColorGradingOptionWidget {
260            widget_type: ColorGradingOptionWidgetType::Button,
261            option,
262        })
263        .with_children(|parent| {
264            // Add the button label.
265            let label = match option {
266                SelectedColorGradingOption::Global(option) => option.to_string(),
267                SelectedColorGradingOption::Section(_, option) => option.to_string(),
268            };
269            add_text(parent, &label, font, Color::WHITE).insert(ColorGradingOptionWidget {
270                widget_type: ColorGradingOptionWidgetType::Label,
271                option,
272            });
273
274            // Add a spacer.
275            parent.spawn(Node {
276                flex_grow: 1.0,
277                ..default()
278            });
279
280            // Add the value text.
281            add_text(
282                parent,
283                &format!("{:.3}", option.get(color_grading)),
284                font,
285                Color::WHITE,
286            )
287            .insert(ColorGradingOptionWidget {
288                widget_type: ColorGradingOptionWidgetType::Value,
289                option,
290            });
291        });
292}
examples/ui/viewport_debug.rs (line 74)
68fn spawn_with_viewport_coords(commands: &mut Commands) {
69    commands
70        .spawn((
71            Node {
72                width: Val::Vw(100.),
73                height: Val::Vh(100.),
74                border: UiRect::axes(Val::Vw(5.), Val::Vh(5.)),
75                flex_wrap: FlexWrap::Wrap,
76                ..default()
77            },
78            BorderColor(PALETTE[0].into()),
79            Coords::Viewport,
80        ))
81        .with_children(|builder| {
82            builder.spawn((
83                Node {
84                    width: Val::Vw(30.),
85                    height: Val::Vh(30.),
86                    border: UiRect::all(Val::VMin(5.)),
87                    ..default()
88                },
89                BackgroundColor(PALETTE[2].into()),
90                BorderColor(PALETTE[9].into()),
91            ));
92
93            builder.spawn((
94                Node {
95                    width: Val::Vw(60.),
96                    height: Val::Vh(30.),
97                    ..default()
98                },
99                BackgroundColor(PALETTE[3].into()),
100            ));
101
102            builder.spawn((
103                Node {
104                    width: Val::Vw(45.),
105                    height: Val::Vh(30.),
106                    border: UiRect::left(Val::VMax(45. / 2.)),
107                    ..default()
108                },
109                BackgroundColor(PALETTE[4].into()),
110                BorderColor(PALETTE[8].into()),
111            ));
112
113            builder.spawn((
114                Node {
115                    width: Val::Vw(45.),
116                    height: Val::Vh(30.),
117                    border: UiRect::right(Val::VMax(45. / 2.)),
118                    ..default()
119                },
120                BackgroundColor(PALETTE[5].into()),
121                BorderColor(PALETTE[8].into()),
122            ));
123
124            builder.spawn((
125                Node {
126                    width: Val::Vw(60.),
127                    height: Val::Vh(30.),
128                    ..default()
129                },
130                BackgroundColor(PALETTE[6].into()),
131            ));
132
133            builder.spawn((
134                Node {
135                    width: Val::Vw(30.),
136                    height: Val::Vh(30.),
137                    border: UiRect::all(Val::VMin(5.)),
138                    ..default()
139                },
140                BackgroundColor(PALETTE[7].into()),
141                BorderColor(PALETTE[9].into()),
142            ));
143        });
144}
145
146fn spawn_with_pixel_coords(commands: &mut Commands) {
147    commands
148        .spawn((
149            Node {
150                width: Val::Px(640.),
151                height: Val::Px(360.),
152                border: UiRect::axes(Val::Px(32.), Val::Px(18.)),
153                flex_wrap: FlexWrap::Wrap,
154                ..default()
155            },
156            BorderColor(PALETTE[1].into()),
157            Coords::Pixel,
158        ))
159        .with_children(|builder| {
160            builder.spawn((
161                Node {
162                    width: Val::Px(192.),
163                    height: Val::Px(108.),
164                    border: UiRect::axes(Val::Px(18.), Val::Px(18.)),
165                    ..default()
166                },
167                BackgroundColor(PALETTE[2].into()),
168                BorderColor(PALETTE[9].into()),
169            ));
170
171            builder.spawn((
172                Node {
173                    width: Val::Px(384.),
174                    height: Val::Px(108.),
175                    ..default()
176                },
177                BackgroundColor(PALETTE[3].into()),
178            ));
179
180            builder.spawn((
181                Node {
182                    width: Val::Px(288.),
183                    height: Val::Px(108.),
184                    border: UiRect::left(Val::Px(144.)),
185                    ..default()
186                },
187                BackgroundColor(PALETTE[4].into()),
188                BorderColor(PALETTE[8].into()),
189            ));
190
191            builder.spawn((
192                Node {
193                    width: Val::Px(288.),
194                    height: Val::Px(108.),
195                    border: UiRect::right(Val::Px(144.)),
196                    ..default()
197                },
198                BackgroundColor(PALETTE[5].into()),
199                BorderColor(PALETTE[8].into()),
200            ));
201
202            builder.spawn((
203                Node {
204                    width: Val::Px(384.),
205                    height: Val::Px(108.),
206                    ..default()
207                },
208                BackgroundColor(PALETTE[6].into()),
209            ));
210
211            builder.spawn((
212                Node {
213                    width: Val::Px(192.),
214                    height: Val::Px(108.),
215                    border: UiRect::axes(Val::Px(18.), Val::Px(18.)),
216                    ..default()
217                },
218                BackgroundColor(PALETTE[7].into()),
219                BorderColor(PALETTE[9].into()),
220            ));
221        });
222}
Source

pub const fn left(left: Val) -> UiRect

Creates a new UiRect where left takes the given value, and the other fields are set to Val::ZERO.

§Example
let ui_rect = UiRect::left(Val::Px(10.0));

assert_eq!(ui_rect.left, Val::Px(10.0));
assert_eq!(ui_rect.right, Val::ZERO);
assert_eq!(ui_rect.top, Val::ZERO);
assert_eq!(ui_rect.bottom, Val::ZERO);
Examples found in repository?
examples/animation/animation_graph.rs (line 364)
340fn setup_node_lines(commands: &mut Commands) {
341    for line in &HORIZONTAL_LINES {
342        commands.spawn((
343            Node {
344                position_type: PositionType::Absolute,
345                bottom: Val::Px(line.bottom),
346                left: Val::Px(line.left),
347                height: Val::Px(0.0),
348                width: Val::Px(line.length),
349                border: UiRect::bottom(Val::Px(1.0)),
350                ..default()
351            },
352            BorderColor(WHITE.into()),
353        ));
354    }
355
356    for line in &VERTICAL_LINES {
357        commands.spawn((
358            Node {
359                position_type: PositionType::Absolute,
360                bottom: Val::Px(line.bottom),
361                left: Val::Px(line.left),
362                height: Val::Px(line.length),
363                width: Val::Px(0.0),
364                border: UiRect::left(Val::Px(1.0)),
365                ..default()
366            },
367            BorderColor(WHITE.into()),
368        ));
369    }
370}
More examples
Hide additional examples
examples/ui/viewport_debug.rs (line 106)
68fn spawn_with_viewport_coords(commands: &mut Commands) {
69    commands
70        .spawn((
71            Node {
72                width: Val::Vw(100.),
73                height: Val::Vh(100.),
74                border: UiRect::axes(Val::Vw(5.), Val::Vh(5.)),
75                flex_wrap: FlexWrap::Wrap,
76                ..default()
77            },
78            BorderColor(PALETTE[0].into()),
79            Coords::Viewport,
80        ))
81        .with_children(|builder| {
82            builder.spawn((
83                Node {
84                    width: Val::Vw(30.),
85                    height: Val::Vh(30.),
86                    border: UiRect::all(Val::VMin(5.)),
87                    ..default()
88                },
89                BackgroundColor(PALETTE[2].into()),
90                BorderColor(PALETTE[9].into()),
91            ));
92
93            builder.spawn((
94                Node {
95                    width: Val::Vw(60.),
96                    height: Val::Vh(30.),
97                    ..default()
98                },
99                BackgroundColor(PALETTE[3].into()),
100            ));
101
102            builder.spawn((
103                Node {
104                    width: Val::Vw(45.),
105                    height: Val::Vh(30.),
106                    border: UiRect::left(Val::VMax(45. / 2.)),
107                    ..default()
108                },
109                BackgroundColor(PALETTE[4].into()),
110                BorderColor(PALETTE[8].into()),
111            ));
112
113            builder.spawn((
114                Node {
115                    width: Val::Vw(45.),
116                    height: Val::Vh(30.),
117                    border: UiRect::right(Val::VMax(45. / 2.)),
118                    ..default()
119                },
120                BackgroundColor(PALETTE[5].into()),
121                BorderColor(PALETTE[8].into()),
122            ));
123
124            builder.spawn((
125                Node {
126                    width: Val::Vw(60.),
127                    height: Val::Vh(30.),
128                    ..default()
129                },
130                BackgroundColor(PALETTE[6].into()),
131            ));
132
133            builder.spawn((
134                Node {
135                    width: Val::Vw(30.),
136                    height: Val::Vh(30.),
137                    border: UiRect::all(Val::VMin(5.)),
138                    ..default()
139                },
140                BackgroundColor(PALETTE[7].into()),
141                BorderColor(PALETTE[9].into()),
142            ));
143        });
144}
145
146fn spawn_with_pixel_coords(commands: &mut Commands) {
147    commands
148        .spawn((
149            Node {
150                width: Val::Px(640.),
151                height: Val::Px(360.),
152                border: UiRect::axes(Val::Px(32.), Val::Px(18.)),
153                flex_wrap: FlexWrap::Wrap,
154                ..default()
155            },
156            BorderColor(PALETTE[1].into()),
157            Coords::Pixel,
158        ))
159        .with_children(|builder| {
160            builder.spawn((
161                Node {
162                    width: Val::Px(192.),
163                    height: Val::Px(108.),
164                    border: UiRect::axes(Val::Px(18.), Val::Px(18.)),
165                    ..default()
166                },
167                BackgroundColor(PALETTE[2].into()),
168                BorderColor(PALETTE[9].into()),
169            ));
170
171            builder.spawn((
172                Node {
173                    width: Val::Px(384.),
174                    height: Val::Px(108.),
175                    ..default()
176                },
177                BackgroundColor(PALETTE[3].into()),
178            ));
179
180            builder.spawn((
181                Node {
182                    width: Val::Px(288.),
183                    height: Val::Px(108.),
184                    border: UiRect::left(Val::Px(144.)),
185                    ..default()
186                },
187                BackgroundColor(PALETTE[4].into()),
188                BorderColor(PALETTE[8].into()),
189            ));
190
191            builder.spawn((
192                Node {
193                    width: Val::Px(288.),
194                    height: Val::Px(108.),
195                    border: UiRect::right(Val::Px(144.)),
196                    ..default()
197                },
198                BackgroundColor(PALETTE[5].into()),
199                BorderColor(PALETTE[8].into()),
200            ));
201
202            builder.spawn((
203                Node {
204                    width: Val::Px(384.),
205                    height: Val::Px(108.),
206                    ..default()
207                },
208                BackgroundColor(PALETTE[6].into()),
209            ));
210
211            builder.spawn((
212                Node {
213                    width: Val::Px(192.),
214                    height: Val::Px(108.),
215                    border: UiRect::axes(Val::Px(18.), Val::Px(18.)),
216                    ..default()
217                },
218                BackgroundColor(PALETTE[7].into()),
219                BorderColor(PALETTE[9].into()),
220            ));
221        });
222}
examples/testbed/ui.rs (line 185)
169    pub fn setup(mut commands: Commands) {
170        commands.spawn((Camera2d, StateScoped(super::Scene::Borders)));
171        let root = commands
172            .spawn((
173                Node {
174                    flex_wrap: FlexWrap::Wrap,
175                    ..default()
176                },
177                StateScoped(super::Scene::Borders),
178            ))
179            .id();
180
181        // all the different combinations of border edges
182        let borders = [
183            UiRect::default(),
184            UiRect::all(Val::Px(20.)),
185            UiRect::left(Val::Px(20.)),
186            UiRect::vertical(Val::Px(20.)),
187            UiRect {
188                left: Val::Px(40.),
189                top: Val::Px(20.),
190                ..Default::default()
191            },
192            UiRect {
193                right: Val::Px(20.),
194                bottom: Val::Px(30.),
195                ..Default::default()
196            },
197            UiRect {
198                right: Val::Px(20.),
199                top: Val::Px(40.),
200                bottom: Val::Px(20.),
201                ..Default::default()
202            },
203            UiRect {
204                left: Val::Px(20.),
205                top: Val::Px(20.),
206                bottom: Val::Px(20.),
207                ..Default::default()
208            },
209            UiRect {
210                left: Val::Px(20.),
211                right: Val::Px(20.),
212                bottom: Val::Px(40.),
213                ..Default::default()
214            },
215        ];
216
217        let non_zero = |x, y| x != Val::Px(0.) && y != Val::Px(0.);
218        let border_size = |x, y| if non_zero(x, y) { f32::MAX } else { 0. };
219
220        for border in borders {
221            for rounded in [true, false] {
222                let border_node = commands
223                    .spawn((
224                        Node {
225                            width: Val::Px(100.),
226                            height: Val::Px(100.),
227                            border,
228                            margin: UiRect::all(Val::Px(30.)),
229                            align_items: AlignItems::Center,
230                            justify_content: JustifyContent::Center,
231                            ..default()
232                        },
233                        BackgroundColor(MAROON.into()),
234                        BorderColor(RED.into()),
235                        Outline {
236                            width: Val::Px(10.),
237                            offset: Val::Px(10.),
238                            color: Color::WHITE,
239                        },
240                    ))
241                    .id();
242
243                if rounded {
244                    let border_radius = BorderRadius::px(
245                        border_size(border.left, border.top),
246                        border_size(border.right, border.top),
247                        border_size(border.right, border.bottom),
248                        border_size(border.left, border.bottom),
249                    );
250                    commands.entity(border_node).insert(border_radius);
251                }
252
253                commands.entity(root).add_child(border_node);
254            }
255        }
256    }
examples/animation/animation_masks.rs (line 318)
227fn add_mask_group_control(
228    parent: &mut ChildSpawnerCommands,
229    label: &str,
230    width: Val,
231    mask_group_id: u32,
232) {
233    let button_text_style = (
234        TextFont {
235            font_size: 14.0,
236            ..default()
237        },
238        TextColor::WHITE,
239    );
240    let selected_button_text_style = (button_text_style.0.clone(), TextColor::BLACK);
241    let label_text_style = (
242        button_text_style.0.clone(),
243        TextColor(Color::Srgba(LIGHT_GRAY)),
244    );
245
246    parent
247        .spawn((
248            Node {
249                border: UiRect::all(Val::Px(1.0)),
250                width,
251                flex_direction: FlexDirection::Column,
252                justify_content: JustifyContent::Center,
253                align_items: AlignItems::Center,
254                padding: UiRect::ZERO,
255                margin: UiRect::ZERO,
256                ..default()
257            },
258            BorderColor(Color::WHITE),
259            BorderRadius::all(Val::Px(3.0)),
260            BackgroundColor(Color::BLACK),
261        ))
262        .with_children(|builder| {
263            builder
264                .spawn((
265                    Node {
266                        border: UiRect::ZERO,
267                        width: Val::Percent(100.0),
268                        justify_content: JustifyContent::Center,
269                        align_items: AlignItems::Center,
270                        padding: UiRect::ZERO,
271                        margin: UiRect::ZERO,
272                        ..default()
273                    },
274                    BackgroundColor(Color::BLACK),
275                ))
276                .with_child((
277                    Text::new(label),
278                    label_text_style.clone(),
279                    Node {
280                        margin: UiRect::vertical(Val::Px(3.0)),
281                        ..default()
282                    },
283                ));
284
285            builder
286                .spawn((
287                    Node {
288                        width: Val::Percent(100.0),
289                        flex_direction: FlexDirection::Row,
290                        justify_content: JustifyContent::Center,
291                        align_items: AlignItems::Center,
292                        border: UiRect::top(Val::Px(1.0)),
293                        ..default()
294                    },
295                    BorderColor(Color::WHITE),
296                ))
297                .with_children(|builder| {
298                    for (index, label) in [
299                        AnimationLabel::Run,
300                        AnimationLabel::Walk,
301                        AnimationLabel::Idle,
302                        AnimationLabel::Off,
303                    ]
304                    .iter()
305                    .enumerate()
306                    {
307                        builder
308                            .spawn((
309                                Button,
310                                BackgroundColor(if index > 0 {
311                                    Color::BLACK
312                                } else {
313                                    Color::WHITE
314                                }),
315                                Node {
316                                    flex_grow: 1.0,
317                                    border: if index > 0 {
318                                        UiRect::left(Val::Px(1.0))
319                                    } else {
320                                        UiRect::ZERO
321                                    },
322                                    ..default()
323                                },
324                                BorderColor(Color::WHITE),
325                                AnimationControl {
326                                    group_id: mask_group_id,
327                                    label: *label,
328                                },
329                            ))
330                            .with_child((
331                                Text(format!("{:?}", label)),
332                                if index > 0 {
333                                    button_text_style.clone()
334                                } else {
335                                    selected_button_text_style.clone()
336                                },
337                                TextLayout::new_with_justify(JustifyText::Center),
338                                Node {
339                                    flex_grow: 1.0,
340                                    margin: UiRect::vertical(Val::Px(3.0)),
341                                    ..default()
342                                },
343                            ));
344                    }
345                });
346        });
347}
examples/ui/borders.rs (line 71)
12fn setup(mut commands: Commands) {
13    commands.spawn(Camera2d);
14    let root = commands
15        .spawn((
16            Node {
17                margin: UiRect::all(Val::Px(25.0)),
18                align_self: AlignSelf::Stretch,
19                justify_self: JustifySelf::Stretch,
20                flex_wrap: FlexWrap::Wrap,
21                justify_content: JustifyContent::FlexStart,
22                align_items: AlignItems::FlexStart,
23                align_content: AlignContent::FlexStart,
24                ..default()
25            },
26            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
27        ))
28        .id();
29
30    let root_rounded = commands
31        .spawn((
32            Node {
33                margin: UiRect::all(Val::Px(25.0)),
34                align_self: AlignSelf::Stretch,
35                justify_self: JustifySelf::Stretch,
36                flex_wrap: FlexWrap::Wrap,
37                justify_content: JustifyContent::FlexStart,
38                align_items: AlignItems::FlexStart,
39                align_content: AlignContent::FlexStart,
40                ..default()
41            },
42            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
43        ))
44        .id();
45
46    // labels for the different border edges
47    let border_labels = [
48        "None",
49        "All",
50        "Left",
51        "Right",
52        "Top",
53        "Bottom",
54        "Horizontal",
55        "Vertical",
56        "Top Left",
57        "Bottom Left",
58        "Top Right",
59        "Bottom Right",
60        "Top Bottom Right",
61        "Top Bottom Left",
62        "Top Left Right",
63        "Bottom Left Right",
64    ];
65
66    // all the different combinations of border edges
67    // these correspond to the labels above
68    let borders = [
69        UiRect::default(),
70        UiRect::all(Val::Px(10.)),
71        UiRect::left(Val::Px(10.)),
72        UiRect::right(Val::Px(10.)),
73        UiRect::top(Val::Px(10.)),
74        UiRect::bottom(Val::Px(10.)),
75        UiRect::horizontal(Val::Px(10.)),
76        UiRect::vertical(Val::Px(10.)),
77        UiRect {
78            left: Val::Px(20.),
79            top: Val::Px(10.),
80            ..Default::default()
81        },
82        UiRect {
83            left: Val::Px(10.),
84            bottom: Val::Px(20.),
85            ..Default::default()
86        },
87        UiRect {
88            right: Val::Px(20.),
89            top: Val::Px(10.),
90            ..Default::default()
91        },
92        UiRect {
93            right: Val::Px(10.),
94            bottom: Val::Px(10.),
95            ..Default::default()
96        },
97        UiRect {
98            right: Val::Px(10.),
99            top: Val::Px(20.),
100            bottom: Val::Px(10.),
101            ..Default::default()
102        },
103        UiRect {
104            left: Val::Px(10.),
105            top: Val::Px(10.),
106            bottom: Val::Px(10.),
107            ..Default::default()
108        },
109        UiRect {
110            left: Val::Px(20.),
111            right: Val::Px(10.),
112            top: Val::Px(10.),
113            ..Default::default()
114        },
115        UiRect {
116            left: Val::Px(10.),
117            right: Val::Px(10.),
118            bottom: Val::Px(20.),
119            ..Default::default()
120        },
121    ];
122
123    for (label, border) in border_labels.into_iter().zip(borders) {
124        let inner_spot = commands
125            .spawn((
126                Node {
127                    width: Val::Px(10.),
128                    height: Val::Px(10.),
129                    ..default()
130                },
131                BackgroundColor(YELLOW.into()),
132            ))
133            .id();
134        let border_node = commands
135            .spawn((
136                Node {
137                    width: Val::Px(50.),
138                    height: Val::Px(50.),
139                    border,
140                    margin: UiRect::all(Val::Px(20.)),
141                    align_items: AlignItems::Center,
142                    justify_content: JustifyContent::Center,
143                    ..default()
144                },
145                BackgroundColor(MAROON.into()),
146                BorderColor(RED.into()),
147                Outline {
148                    width: Val::Px(6.),
149                    offset: Val::Px(6.),
150                    color: Color::WHITE,
151                },
152            ))
153            .add_child(inner_spot)
154            .id();
155        let label_node = commands
156            .spawn((
157                Text::new(label),
158                TextFont {
159                    font_size: 9.0,
160                    ..Default::default()
161                },
162            ))
163            .id();
164        let container = commands
165            .spawn(Node {
166                flex_direction: FlexDirection::Column,
167                align_items: AlignItems::Center,
168                ..default()
169            })
170            .add_children(&[border_node, label_node])
171            .id();
172        commands.entity(root).add_child(container);
173    }
174
175    for (label, border) in border_labels.into_iter().zip(borders) {
176        let inner_spot = commands
177            .spawn((
178                Node {
179                    width: Val::Px(10.),
180                    height: Val::Px(10.),
181                    ..default()
182                },
183                BorderRadius::MAX,
184                BackgroundColor(YELLOW.into()),
185            ))
186            .id();
187        let non_zero = |x, y| x != Val::Px(0.) && y != Val::Px(0.);
188        let border_size = |x, y| if non_zero(x, y) { f32::MAX } else { 0. };
189        let border_radius = BorderRadius::px(
190            border_size(border.left, border.top),
191            border_size(border.right, border.top),
192            border_size(border.right, border.bottom),
193            border_size(border.left, border.bottom),
194        );
195        let border_node = commands
196            .spawn((
197                Node {
198                    width: Val::Px(50.),
199                    height: Val::Px(50.),
200                    border,
201                    margin: UiRect::all(Val::Px(20.)),
202                    align_items: AlignItems::Center,
203                    justify_content: JustifyContent::Center,
204                    ..default()
205                },
206                BackgroundColor(MAROON.into()),
207                BorderColor(RED.into()),
208                border_radius,
209                Outline {
210                    width: Val::Px(6.),
211                    offset: Val::Px(6.),
212                    color: Color::WHITE,
213                },
214            ))
215            .add_child(inner_spot)
216            .id();
217        let label_node = commands
218            .spawn((
219                Text::new(label),
220                TextFont {
221                    font_size: 9.0,
222                    ..Default::default()
223                },
224            ))
225            .id();
226        let container = commands
227            .spawn(Node {
228                flex_direction: FlexDirection::Column,
229                align_items: AlignItems::Center,
230                ..default()
231            })
232            .add_children(&[border_node, label_node])
233            .id();
234        commands.entity(root_rounded).add_child(container);
235    }
236
237    let border_label = commands
238        .spawn((
239            Node {
240                margin: UiRect {
241                    left: Val::Px(25.0),
242                    right: Val::Px(25.0),
243                    top: Val::Px(25.0),
244                    bottom: Val::Px(0.0),
245                },
246                ..default()
247            },
248            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
249        ))
250        .with_children(|builder| {
251            builder.spawn((
252                Text::new("Borders"),
253                TextFont {
254                    font_size: 20.0,
255                    ..Default::default()
256                },
257            ));
258        })
259        .id();
260
261    let border_rounded_label = commands
262        .spawn((
263            Node {
264                margin: UiRect {
265                    left: Val::Px(25.0),
266                    right: Val::Px(25.0),
267                    top: Val::Px(25.0),
268                    bottom: Val::Px(0.0),
269                },
270                ..default()
271            },
272            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
273        ))
274        .with_children(|builder| {
275            builder.spawn((
276                Text::new("Borders Rounded"),
277                TextFont {
278                    font_size: 20.0,
279                    ..Default::default()
280                },
281            ));
282        })
283        .id();
284
285    commands
286        .spawn((
287            Node {
288                margin: UiRect::all(Val::Px(25.0)),
289                flex_direction: FlexDirection::Column,
290                align_self: AlignSelf::Stretch,
291                justify_self: JustifySelf::Stretch,
292                flex_wrap: FlexWrap::Wrap,
293                justify_content: JustifyContent::FlexStart,
294                align_items: AlignItems::FlexStart,
295                align_content: AlignContent::FlexStart,
296                ..default()
297            },
298            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
299        ))
300        .add_child(border_label)
301        .add_child(root)
302        .add_child(border_rounded_label)
303        .add_child(root_rounded);
304}
Source

pub const fn right(right: Val) -> UiRect

Creates a new UiRect where right takes the given value, and the other fields are set to Val::ZERO.

§Example
let ui_rect = UiRect::right(Val::Px(10.0));

assert_eq!(ui_rect.left, Val::ZERO);
assert_eq!(ui_rect.right, Val::Px(10.0));
assert_eq!(ui_rect.top, Val::ZERO);
assert_eq!(ui_rect.bottom, Val::ZERO);
Examples found in repository?
examples/3d/color_grading.rs (line 252)
236fn add_button_for_value(
237    parent: &mut ChildSpawnerCommands,
238    option: SelectedColorGradingOption,
239    color_grading: &ColorGrading,
240    font: &Handle<Font>,
241) {
242    // Add the button node.
243    parent
244        .spawn((
245            Button,
246            Node {
247                border: UiRect::all(Val::Px(1.0)),
248                width: Val::Px(200.0),
249                justify_content: JustifyContent::Center,
250                align_items: AlignItems::Center,
251                padding: UiRect::axes(Val::Px(12.0), Val::Px(6.0)),
252                margin: UiRect::right(Val::Px(12.0)),
253                ..default()
254            },
255            BorderColor(Color::WHITE),
256            BorderRadius::MAX,
257            BackgroundColor(Color::BLACK),
258        ))
259        .insert(ColorGradingOptionWidget {
260            widget_type: ColorGradingOptionWidgetType::Button,
261            option,
262        })
263        .with_children(|parent| {
264            // Add the button label.
265            let label = match option {
266                SelectedColorGradingOption::Global(option) => option.to_string(),
267                SelectedColorGradingOption::Section(_, option) => option.to_string(),
268            };
269            add_text(parent, &label, font, Color::WHITE).insert(ColorGradingOptionWidget {
270                widget_type: ColorGradingOptionWidgetType::Label,
271                option,
272            });
273
274            // Add a spacer.
275            parent.spawn(Node {
276                flex_grow: 1.0,
277                ..default()
278            });
279
280            // Add the value text.
281            add_text(
282                parent,
283                &format!("{:.3}", option.get(color_grading)),
284                font,
285                Color::WHITE,
286            )
287            .insert(ColorGradingOptionWidget {
288                widget_type: ColorGradingOptionWidgetType::Value,
289                option,
290            });
291        });
292}
More examples
Hide additional examples
examples/ui/viewport_debug.rs (line 117)
68fn spawn_with_viewport_coords(commands: &mut Commands) {
69    commands
70        .spawn((
71            Node {
72                width: Val::Vw(100.),
73                height: Val::Vh(100.),
74                border: UiRect::axes(Val::Vw(5.), Val::Vh(5.)),
75                flex_wrap: FlexWrap::Wrap,
76                ..default()
77            },
78            BorderColor(PALETTE[0].into()),
79            Coords::Viewport,
80        ))
81        .with_children(|builder| {
82            builder.spawn((
83                Node {
84                    width: Val::Vw(30.),
85                    height: Val::Vh(30.),
86                    border: UiRect::all(Val::VMin(5.)),
87                    ..default()
88                },
89                BackgroundColor(PALETTE[2].into()),
90                BorderColor(PALETTE[9].into()),
91            ));
92
93            builder.spawn((
94                Node {
95                    width: Val::Vw(60.),
96                    height: Val::Vh(30.),
97                    ..default()
98                },
99                BackgroundColor(PALETTE[3].into()),
100            ));
101
102            builder.spawn((
103                Node {
104                    width: Val::Vw(45.),
105                    height: Val::Vh(30.),
106                    border: UiRect::left(Val::VMax(45. / 2.)),
107                    ..default()
108                },
109                BackgroundColor(PALETTE[4].into()),
110                BorderColor(PALETTE[8].into()),
111            ));
112
113            builder.spawn((
114                Node {
115                    width: Val::Vw(45.),
116                    height: Val::Vh(30.),
117                    border: UiRect::right(Val::VMax(45. / 2.)),
118                    ..default()
119                },
120                BackgroundColor(PALETTE[5].into()),
121                BorderColor(PALETTE[8].into()),
122            ));
123
124            builder.spawn((
125                Node {
126                    width: Val::Vw(60.),
127                    height: Val::Vh(30.),
128                    ..default()
129                },
130                BackgroundColor(PALETTE[6].into()),
131            ));
132
133            builder.spawn((
134                Node {
135                    width: Val::Vw(30.),
136                    height: Val::Vh(30.),
137                    border: UiRect::all(Val::VMin(5.)),
138                    ..default()
139                },
140                BackgroundColor(PALETTE[7].into()),
141                BorderColor(PALETTE[9].into()),
142            ));
143        });
144}
145
146fn spawn_with_pixel_coords(commands: &mut Commands) {
147    commands
148        .spawn((
149            Node {
150                width: Val::Px(640.),
151                height: Val::Px(360.),
152                border: UiRect::axes(Val::Px(32.), Val::Px(18.)),
153                flex_wrap: FlexWrap::Wrap,
154                ..default()
155            },
156            BorderColor(PALETTE[1].into()),
157            Coords::Pixel,
158        ))
159        .with_children(|builder| {
160            builder.spawn((
161                Node {
162                    width: Val::Px(192.),
163                    height: Val::Px(108.),
164                    border: UiRect::axes(Val::Px(18.), Val::Px(18.)),
165                    ..default()
166                },
167                BackgroundColor(PALETTE[2].into()),
168                BorderColor(PALETTE[9].into()),
169            ));
170
171            builder.spawn((
172                Node {
173                    width: Val::Px(384.),
174                    height: Val::Px(108.),
175                    ..default()
176                },
177                BackgroundColor(PALETTE[3].into()),
178            ));
179
180            builder.spawn((
181                Node {
182                    width: Val::Px(288.),
183                    height: Val::Px(108.),
184                    border: UiRect::left(Val::Px(144.)),
185                    ..default()
186                },
187                BackgroundColor(PALETTE[4].into()),
188                BorderColor(PALETTE[8].into()),
189            ));
190
191            builder.spawn((
192                Node {
193                    width: Val::Px(288.),
194                    height: Val::Px(108.),
195                    border: UiRect::right(Val::Px(144.)),
196                    ..default()
197                },
198                BackgroundColor(PALETTE[5].into()),
199                BorderColor(PALETTE[8].into()),
200            ));
201
202            builder.spawn((
203                Node {
204                    width: Val::Px(384.),
205                    height: Val::Px(108.),
206                    ..default()
207                },
208                BackgroundColor(PALETTE[6].into()),
209            ));
210
211            builder.spawn((
212                Node {
213                    width: Val::Px(192.),
214                    height: Val::Px(108.),
215                    border: UiRect::axes(Val::Px(18.), Val::Px(18.)),
216                    ..default()
217                },
218                BackgroundColor(PALETTE[7].into()),
219                BorderColor(PALETTE[9].into()),
220            ));
221        });
222}
examples/ui/flex_layout.rs (line 50)
21fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
22    let font = asset_server.load("fonts/FiraSans-Bold.ttf");
23    commands.spawn(Camera2d);
24    commands
25        .spawn((
26            Node {
27                // fill the entire window
28                width: Val::Percent(100.),
29                height: Val::Percent(100.),
30                flex_direction: FlexDirection::Column,
31                align_items: AlignItems::Center,
32                padding: UiRect::all(MARGIN),
33                row_gap: MARGIN,
34                ..Default::default()
35            },
36            BackgroundColor(Color::BLACK),
37        ))
38        .with_children(|builder| {
39            // spawn the key
40            builder
41                .spawn(Node {
42                    flex_direction: FlexDirection::Row,
43                    ..default()
44                })
45                .with_children(|builder| {
46                    spawn_nested_text_bundle(
47                        builder,
48                        font.clone(),
49                        ALIGN_ITEMS_COLOR,
50                        UiRect::right(MARGIN),
51                        "AlignItems",
52                    );
53                    spawn_nested_text_bundle(
54                        builder,
55                        font.clone(),
56                        JUSTIFY_CONTENT_COLOR,
57                        UiRect::default(),
58                        "JustifyContent",
59                    );
60                });
61
62            builder
63                .spawn(Node {
64                    width: Val::Percent(100.),
65                    height: Val::Percent(100.),
66                    flex_direction: FlexDirection::Column,
67                    row_gap: MARGIN,
68                    ..default()
69                })
70                .with_children(|builder| {
71                    // spawn one child node for each combination of `AlignItems` and `JustifyContent`
72                    let justifications = [
73                        JustifyContent::FlexStart,
74                        JustifyContent::Center,
75                        JustifyContent::FlexEnd,
76                        JustifyContent::SpaceEvenly,
77                        JustifyContent::SpaceAround,
78                        JustifyContent::SpaceBetween,
79                    ];
80                    let alignments = [
81                        AlignItems::Baseline,
82                        AlignItems::FlexStart,
83                        AlignItems::Center,
84                        AlignItems::FlexEnd,
85                        AlignItems::Stretch,
86                    ];
87                    for align_items in alignments {
88                        builder
89                            .spawn(Node {
90                                width: Val::Percent(100.),
91                                height: Val::Percent(100.),
92                                flex_direction: FlexDirection::Row,
93                                column_gap: MARGIN,
94                                ..Default::default()
95                            })
96                            .with_children(|builder| {
97                                for justify_content in justifications {
98                                    spawn_child_node(
99                                        builder,
100                                        font.clone(),
101                                        align_items,
102                                        justify_content,
103                                    );
104                                }
105                            });
106                    }
107                });
108        });
109}
examples/ui/borders.rs (line 72)
12fn setup(mut commands: Commands) {
13    commands.spawn(Camera2d);
14    let root = commands
15        .spawn((
16            Node {
17                margin: UiRect::all(Val::Px(25.0)),
18                align_self: AlignSelf::Stretch,
19                justify_self: JustifySelf::Stretch,
20                flex_wrap: FlexWrap::Wrap,
21                justify_content: JustifyContent::FlexStart,
22                align_items: AlignItems::FlexStart,
23                align_content: AlignContent::FlexStart,
24                ..default()
25            },
26            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
27        ))
28        .id();
29
30    let root_rounded = commands
31        .spawn((
32            Node {
33                margin: UiRect::all(Val::Px(25.0)),
34                align_self: AlignSelf::Stretch,
35                justify_self: JustifySelf::Stretch,
36                flex_wrap: FlexWrap::Wrap,
37                justify_content: JustifyContent::FlexStart,
38                align_items: AlignItems::FlexStart,
39                align_content: AlignContent::FlexStart,
40                ..default()
41            },
42            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
43        ))
44        .id();
45
46    // labels for the different border edges
47    let border_labels = [
48        "None",
49        "All",
50        "Left",
51        "Right",
52        "Top",
53        "Bottom",
54        "Horizontal",
55        "Vertical",
56        "Top Left",
57        "Bottom Left",
58        "Top Right",
59        "Bottom Right",
60        "Top Bottom Right",
61        "Top Bottom Left",
62        "Top Left Right",
63        "Bottom Left Right",
64    ];
65
66    // all the different combinations of border edges
67    // these correspond to the labels above
68    let borders = [
69        UiRect::default(),
70        UiRect::all(Val::Px(10.)),
71        UiRect::left(Val::Px(10.)),
72        UiRect::right(Val::Px(10.)),
73        UiRect::top(Val::Px(10.)),
74        UiRect::bottom(Val::Px(10.)),
75        UiRect::horizontal(Val::Px(10.)),
76        UiRect::vertical(Val::Px(10.)),
77        UiRect {
78            left: Val::Px(20.),
79            top: Val::Px(10.),
80            ..Default::default()
81        },
82        UiRect {
83            left: Val::Px(10.),
84            bottom: Val::Px(20.),
85            ..Default::default()
86        },
87        UiRect {
88            right: Val::Px(20.),
89            top: Val::Px(10.),
90            ..Default::default()
91        },
92        UiRect {
93            right: Val::Px(10.),
94            bottom: Val::Px(10.),
95            ..Default::default()
96        },
97        UiRect {
98            right: Val::Px(10.),
99            top: Val::Px(20.),
100            bottom: Val::Px(10.),
101            ..Default::default()
102        },
103        UiRect {
104            left: Val::Px(10.),
105            top: Val::Px(10.),
106            bottom: Val::Px(10.),
107            ..Default::default()
108        },
109        UiRect {
110            left: Val::Px(20.),
111            right: Val::Px(10.),
112            top: Val::Px(10.),
113            ..Default::default()
114        },
115        UiRect {
116            left: Val::Px(10.),
117            right: Val::Px(10.),
118            bottom: Val::Px(20.),
119            ..Default::default()
120        },
121    ];
122
123    for (label, border) in border_labels.into_iter().zip(borders) {
124        let inner_spot = commands
125            .spawn((
126                Node {
127                    width: Val::Px(10.),
128                    height: Val::Px(10.),
129                    ..default()
130                },
131                BackgroundColor(YELLOW.into()),
132            ))
133            .id();
134        let border_node = commands
135            .spawn((
136                Node {
137                    width: Val::Px(50.),
138                    height: Val::Px(50.),
139                    border,
140                    margin: UiRect::all(Val::Px(20.)),
141                    align_items: AlignItems::Center,
142                    justify_content: JustifyContent::Center,
143                    ..default()
144                },
145                BackgroundColor(MAROON.into()),
146                BorderColor(RED.into()),
147                Outline {
148                    width: Val::Px(6.),
149                    offset: Val::Px(6.),
150                    color: Color::WHITE,
151                },
152            ))
153            .add_child(inner_spot)
154            .id();
155        let label_node = commands
156            .spawn((
157                Text::new(label),
158                TextFont {
159                    font_size: 9.0,
160                    ..Default::default()
161                },
162            ))
163            .id();
164        let container = commands
165            .spawn(Node {
166                flex_direction: FlexDirection::Column,
167                align_items: AlignItems::Center,
168                ..default()
169            })
170            .add_children(&[border_node, label_node])
171            .id();
172        commands.entity(root).add_child(container);
173    }
174
175    for (label, border) in border_labels.into_iter().zip(borders) {
176        let inner_spot = commands
177            .spawn((
178                Node {
179                    width: Val::Px(10.),
180                    height: Val::Px(10.),
181                    ..default()
182                },
183                BorderRadius::MAX,
184                BackgroundColor(YELLOW.into()),
185            ))
186            .id();
187        let non_zero = |x, y| x != Val::Px(0.) && y != Val::Px(0.);
188        let border_size = |x, y| if non_zero(x, y) { f32::MAX } else { 0. };
189        let border_radius = BorderRadius::px(
190            border_size(border.left, border.top),
191            border_size(border.right, border.top),
192            border_size(border.right, border.bottom),
193            border_size(border.left, border.bottom),
194        );
195        let border_node = commands
196            .spawn((
197                Node {
198                    width: Val::Px(50.),
199                    height: Val::Px(50.),
200                    border,
201                    margin: UiRect::all(Val::Px(20.)),
202                    align_items: AlignItems::Center,
203                    justify_content: JustifyContent::Center,
204                    ..default()
205                },
206                BackgroundColor(MAROON.into()),
207                BorderColor(RED.into()),
208                border_radius,
209                Outline {
210                    width: Val::Px(6.),
211                    offset: Val::Px(6.),
212                    color: Color::WHITE,
213                },
214            ))
215            .add_child(inner_spot)
216            .id();
217        let label_node = commands
218            .spawn((
219                Text::new(label),
220                TextFont {
221                    font_size: 9.0,
222                    ..Default::default()
223                },
224            ))
225            .id();
226        let container = commands
227            .spawn(Node {
228                flex_direction: FlexDirection::Column,
229                align_items: AlignItems::Center,
230                ..default()
231            })
232            .add_children(&[border_node, label_node])
233            .id();
234        commands.entity(root_rounded).add_child(container);
235    }
236
237    let border_label = commands
238        .spawn((
239            Node {
240                margin: UiRect {
241                    left: Val::Px(25.0),
242                    right: Val::Px(25.0),
243                    top: Val::Px(25.0),
244                    bottom: Val::Px(0.0),
245                },
246                ..default()
247            },
248            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
249        ))
250        .with_children(|builder| {
251            builder.spawn((
252                Text::new("Borders"),
253                TextFont {
254                    font_size: 20.0,
255                    ..Default::default()
256                },
257            ));
258        })
259        .id();
260
261    let border_rounded_label = commands
262        .spawn((
263            Node {
264                margin: UiRect {
265                    left: Val::Px(25.0),
266                    right: Val::Px(25.0),
267                    top: Val::Px(25.0),
268                    bottom: Val::Px(0.0),
269                },
270                ..default()
271            },
272            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
273        ))
274        .with_children(|builder| {
275            builder.spawn((
276                Text::new("Borders Rounded"),
277                TextFont {
278                    font_size: 20.0,
279                    ..Default::default()
280                },
281            ));
282        })
283        .id();
284
285    commands
286        .spawn((
287            Node {
288                margin: UiRect::all(Val::Px(25.0)),
289                flex_direction: FlexDirection::Column,
290                align_self: AlignSelf::Stretch,
291                justify_self: JustifySelf::Stretch,
292                flex_wrap: FlexWrap::Wrap,
293                justify_content: JustifyContent::FlexStart,
294                align_items: AlignItems::FlexStart,
295                align_content: AlignContent::FlexStart,
296                ..default()
297            },
298            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
299        ))
300        .add_child(border_label)
301        .add_child(root)
302        .add_child(border_rounded_label)
303        .add_child(root_rounded);
304}
Source

pub const fn top(top: Val) -> UiRect

Creates a new UiRect where top takes the given value, and the other fields are set to Val::ZERO.

§Example
let ui_rect = UiRect::top(Val::Px(10.0));

assert_eq!(ui_rect.left, Val::ZERO);
assert_eq!(ui_rect.right, Val::ZERO);
assert_eq!(ui_rect.top, Val::Px(10.0));
assert_eq!(ui_rect.bottom, Val::ZERO);
Examples found in repository?
examples/ui/flex_layout.rs (line 140)
111fn spawn_child_node(
112    builder: &mut ChildSpawnerCommands,
113    font: Handle<Font>,
114    align_items: AlignItems,
115    justify_content: JustifyContent,
116) {
117    builder
118        .spawn((
119            Node {
120                flex_direction: FlexDirection::Column,
121                align_items,
122                justify_content,
123                width: Val::Percent(100.),
124                height: Val::Percent(100.),
125                ..default()
126            },
127            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
128        ))
129        .with_children(|builder| {
130            let labels = [
131                (format!("{align_items:?}"), ALIGN_ITEMS_COLOR, 0.),
132                (format!("{justify_content:?}"), JUSTIFY_CONTENT_COLOR, 3.),
133            ];
134            for (text, color, top_margin) in labels {
135                // We nest the text within a parent node because margins and padding can't be directly applied to text nodes currently.
136                spawn_nested_text_bundle(
137                    builder,
138                    font.clone(),
139                    color,
140                    UiRect::top(Val::Px(top_margin)),
141                    &text,
142                );
143            }
144        });
145}
More examples
Hide additional examples
examples/ui/size_constraints.rs (line 91)
41fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
42    // ui camera
43    commands.spawn(Camera2d);
44
45    let text_font = (
46        TextFont {
47            font: asset_server.load("fonts/FiraSans-Bold.ttf"),
48            font_size: 33.0,
49            ..Default::default()
50        },
51        TextColor(Color::srgb(0.9, 0.9, 0.9)),
52    );
53
54    commands
55        .spawn((
56            Node {
57                width: Val::Percent(100.0),
58                height: Val::Percent(100.0),
59                justify_content: JustifyContent::Center,
60                align_items: AlignItems::Center,
61                ..default()
62            },
63            BackgroundColor(Color::BLACK),
64        ))
65        .with_children(|parent| {
66            parent
67                .spawn(Node {
68                    flex_direction: FlexDirection::Column,
69                    align_items: AlignItems::Center,
70                    justify_content: JustifyContent::Center,
71                    ..default()
72                })
73                .with_children(|parent| {
74                    parent.spawn((
75                        Text::new("Size Constraints Example"),
76                        text_font.clone(),
77                        Node {
78                            margin: UiRect::bottom(Val::Px(25.)),
79                            ..Default::default()
80                        },
81                    ));
82
83                    spawn_bar(parent);
84
85                    parent
86                        .spawn((
87                            Node {
88                                flex_direction: FlexDirection::Column,
89                                align_items: AlignItems::Stretch,
90                                padding: UiRect::all(Val::Px(10.)),
91                                margin: UiRect::top(Val::Px(50.)),
92                                ..default()
93                            },
94                            BackgroundColor(YELLOW.into()),
95                        ))
96                        .with_children(|parent| {
97                            for constraint in [
98                                Constraint::MinWidth,
99                                Constraint::FlexBasis,
100                                Constraint::Width,
101                                Constraint::MaxWidth,
102                            ] {
103                                spawn_button_row(parent, constraint, text_font.clone());
104                            }
105                        });
106                });
107        });
108}
examples/ui/overflow_clip_margin.rs (line 60)
14fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
15    commands.spawn(Camera2d);
16
17    let image = asset_server.load("branding/icon.png");
18
19    commands
20        .spawn((
21            Node {
22                width: Val::Percent(100.),
23                height: Val::Percent(100.),
24                align_items: AlignItems::Center,
25                justify_content: JustifyContent::Center,
26                row_gap: Val::Px(40.),
27                flex_direction: FlexDirection::Column,
28                ..default()
29            },
30            BackgroundColor(ANTIQUE_WHITE.into()),
31        ))
32        .with_children(|parent| {
33            for overflow_clip_margin in [
34                OverflowClipMargin::border_box().with_margin(25.),
35                OverflowClipMargin::border_box(),
36                OverflowClipMargin::padding_box(),
37                OverflowClipMargin::content_box(),
38            ] {
39                parent
40                    .spawn(Node {
41                        flex_direction: FlexDirection::Row,
42                        column_gap: Val::Px(20.),
43                        ..default()
44                    })
45                    .with_children(|parent| {
46                        parent
47                            .spawn((
48                                Node {
49                                    padding: UiRect::all(Val::Px(10.)),
50                                    margin: UiRect::bottom(Val::Px(25.)),
51                                    ..default()
52                                },
53                                BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
54                            ))
55                            .with_child(Text(format!("{overflow_clip_margin:#?}")));
56
57                        parent
58                            .spawn((
59                                Node {
60                                    margin: UiRect::top(Val::Px(10.)),
61                                    width: Val::Px(100.),
62                                    height: Val::Px(100.),
63                                    padding: UiRect::all(Val::Px(20.)),
64                                    border: UiRect::all(Val::Px(5.)),
65                                    overflow: Overflow::clip(),
66                                    overflow_clip_margin,
67                                    ..default()
68                                },
69                                BackgroundColor(GRAY.into()),
70                                BorderColor(Color::BLACK),
71                            ))
72                            .with_children(|parent| {
73                                parent
74                                    .spawn((
75                                        Node {
76                                            min_width: Val::Px(50.),
77                                            min_height: Val::Px(50.),
78                                            ..default()
79                                        },
80                                        BackgroundColor(LIGHT_CYAN.into()),
81                                    ))
82                                    .with_child((
83                                        ImageNode::new(image.clone()),
84                                        Node {
85                                            min_width: Val::Px(100.),
86                                            min_height: Val::Px(100.),
87                                            ..default()
88                                        },
89                                    ));
90                            });
91                    });
92            }
93        });
94}
examples/animation/animation_masks.rs (line 292)
227fn add_mask_group_control(
228    parent: &mut ChildSpawnerCommands,
229    label: &str,
230    width: Val,
231    mask_group_id: u32,
232) {
233    let button_text_style = (
234        TextFont {
235            font_size: 14.0,
236            ..default()
237        },
238        TextColor::WHITE,
239    );
240    let selected_button_text_style = (button_text_style.0.clone(), TextColor::BLACK);
241    let label_text_style = (
242        button_text_style.0.clone(),
243        TextColor(Color::Srgba(LIGHT_GRAY)),
244    );
245
246    parent
247        .spawn((
248            Node {
249                border: UiRect::all(Val::Px(1.0)),
250                width,
251                flex_direction: FlexDirection::Column,
252                justify_content: JustifyContent::Center,
253                align_items: AlignItems::Center,
254                padding: UiRect::ZERO,
255                margin: UiRect::ZERO,
256                ..default()
257            },
258            BorderColor(Color::WHITE),
259            BorderRadius::all(Val::Px(3.0)),
260            BackgroundColor(Color::BLACK),
261        ))
262        .with_children(|builder| {
263            builder
264                .spawn((
265                    Node {
266                        border: UiRect::ZERO,
267                        width: Val::Percent(100.0),
268                        justify_content: JustifyContent::Center,
269                        align_items: AlignItems::Center,
270                        padding: UiRect::ZERO,
271                        margin: UiRect::ZERO,
272                        ..default()
273                    },
274                    BackgroundColor(Color::BLACK),
275                ))
276                .with_child((
277                    Text::new(label),
278                    label_text_style.clone(),
279                    Node {
280                        margin: UiRect::vertical(Val::Px(3.0)),
281                        ..default()
282                    },
283                ));
284
285            builder
286                .spawn((
287                    Node {
288                        width: Val::Percent(100.0),
289                        flex_direction: FlexDirection::Row,
290                        justify_content: JustifyContent::Center,
291                        align_items: AlignItems::Center,
292                        border: UiRect::top(Val::Px(1.0)),
293                        ..default()
294                    },
295                    BorderColor(Color::WHITE),
296                ))
297                .with_children(|builder| {
298                    for (index, label) in [
299                        AnimationLabel::Run,
300                        AnimationLabel::Walk,
301                        AnimationLabel::Idle,
302                        AnimationLabel::Off,
303                    ]
304                    .iter()
305                    .enumerate()
306                    {
307                        builder
308                            .spawn((
309                                Button,
310                                BackgroundColor(if index > 0 {
311                                    Color::BLACK
312                                } else {
313                                    Color::WHITE
314                                }),
315                                Node {
316                                    flex_grow: 1.0,
317                                    border: if index > 0 {
318                                        UiRect::left(Val::Px(1.0))
319                                    } else {
320                                        UiRect::ZERO
321                                    },
322                                    ..default()
323                                },
324                                BorderColor(Color::WHITE),
325                                AnimationControl {
326                                    group_id: mask_group_id,
327                                    label: *label,
328                                },
329                            ))
330                            .with_child((
331                                Text(format!("{:?}", label)),
332                                if index > 0 {
333                                    button_text_style.clone()
334                                } else {
335                                    selected_button_text_style.clone()
336                                },
337                                TextLayout::new_with_justify(JustifyText::Center),
338                                Node {
339                                    flex_grow: 1.0,
340                                    margin: UiRect::vertical(Val::Px(3.0)),
341                                    ..default()
342                                },
343                            ));
344                    }
345                });
346        });
347}
examples/ui/borders.rs (line 73)
12fn setup(mut commands: Commands) {
13    commands.spawn(Camera2d);
14    let root = commands
15        .spawn((
16            Node {
17                margin: UiRect::all(Val::Px(25.0)),
18                align_self: AlignSelf::Stretch,
19                justify_self: JustifySelf::Stretch,
20                flex_wrap: FlexWrap::Wrap,
21                justify_content: JustifyContent::FlexStart,
22                align_items: AlignItems::FlexStart,
23                align_content: AlignContent::FlexStart,
24                ..default()
25            },
26            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
27        ))
28        .id();
29
30    let root_rounded = commands
31        .spawn((
32            Node {
33                margin: UiRect::all(Val::Px(25.0)),
34                align_self: AlignSelf::Stretch,
35                justify_self: JustifySelf::Stretch,
36                flex_wrap: FlexWrap::Wrap,
37                justify_content: JustifyContent::FlexStart,
38                align_items: AlignItems::FlexStart,
39                align_content: AlignContent::FlexStart,
40                ..default()
41            },
42            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
43        ))
44        .id();
45
46    // labels for the different border edges
47    let border_labels = [
48        "None",
49        "All",
50        "Left",
51        "Right",
52        "Top",
53        "Bottom",
54        "Horizontal",
55        "Vertical",
56        "Top Left",
57        "Bottom Left",
58        "Top Right",
59        "Bottom Right",
60        "Top Bottom Right",
61        "Top Bottom Left",
62        "Top Left Right",
63        "Bottom Left Right",
64    ];
65
66    // all the different combinations of border edges
67    // these correspond to the labels above
68    let borders = [
69        UiRect::default(),
70        UiRect::all(Val::Px(10.)),
71        UiRect::left(Val::Px(10.)),
72        UiRect::right(Val::Px(10.)),
73        UiRect::top(Val::Px(10.)),
74        UiRect::bottom(Val::Px(10.)),
75        UiRect::horizontal(Val::Px(10.)),
76        UiRect::vertical(Val::Px(10.)),
77        UiRect {
78            left: Val::Px(20.),
79            top: Val::Px(10.),
80            ..Default::default()
81        },
82        UiRect {
83            left: Val::Px(10.),
84            bottom: Val::Px(20.),
85            ..Default::default()
86        },
87        UiRect {
88            right: Val::Px(20.),
89            top: Val::Px(10.),
90            ..Default::default()
91        },
92        UiRect {
93            right: Val::Px(10.),
94            bottom: Val::Px(10.),
95            ..Default::default()
96        },
97        UiRect {
98            right: Val::Px(10.),
99            top: Val::Px(20.),
100            bottom: Val::Px(10.),
101            ..Default::default()
102        },
103        UiRect {
104            left: Val::Px(10.),
105            top: Val::Px(10.),
106            bottom: Val::Px(10.),
107            ..Default::default()
108        },
109        UiRect {
110            left: Val::Px(20.),
111            right: Val::Px(10.),
112            top: Val::Px(10.),
113            ..Default::default()
114        },
115        UiRect {
116            left: Val::Px(10.),
117            right: Val::Px(10.),
118            bottom: Val::Px(20.),
119            ..Default::default()
120        },
121    ];
122
123    for (label, border) in border_labels.into_iter().zip(borders) {
124        let inner_spot = commands
125            .spawn((
126                Node {
127                    width: Val::Px(10.),
128                    height: Val::Px(10.),
129                    ..default()
130                },
131                BackgroundColor(YELLOW.into()),
132            ))
133            .id();
134        let border_node = commands
135            .spawn((
136                Node {
137                    width: Val::Px(50.),
138                    height: Val::Px(50.),
139                    border,
140                    margin: UiRect::all(Val::Px(20.)),
141                    align_items: AlignItems::Center,
142                    justify_content: JustifyContent::Center,
143                    ..default()
144                },
145                BackgroundColor(MAROON.into()),
146                BorderColor(RED.into()),
147                Outline {
148                    width: Val::Px(6.),
149                    offset: Val::Px(6.),
150                    color: Color::WHITE,
151                },
152            ))
153            .add_child(inner_spot)
154            .id();
155        let label_node = commands
156            .spawn((
157                Text::new(label),
158                TextFont {
159                    font_size: 9.0,
160                    ..Default::default()
161                },
162            ))
163            .id();
164        let container = commands
165            .spawn(Node {
166                flex_direction: FlexDirection::Column,
167                align_items: AlignItems::Center,
168                ..default()
169            })
170            .add_children(&[border_node, label_node])
171            .id();
172        commands.entity(root).add_child(container);
173    }
174
175    for (label, border) in border_labels.into_iter().zip(borders) {
176        let inner_spot = commands
177            .spawn((
178                Node {
179                    width: Val::Px(10.),
180                    height: Val::Px(10.),
181                    ..default()
182                },
183                BorderRadius::MAX,
184                BackgroundColor(YELLOW.into()),
185            ))
186            .id();
187        let non_zero = |x, y| x != Val::Px(0.) && y != Val::Px(0.);
188        let border_size = |x, y| if non_zero(x, y) { f32::MAX } else { 0. };
189        let border_radius = BorderRadius::px(
190            border_size(border.left, border.top),
191            border_size(border.right, border.top),
192            border_size(border.right, border.bottom),
193            border_size(border.left, border.bottom),
194        );
195        let border_node = commands
196            .spawn((
197                Node {
198                    width: Val::Px(50.),
199                    height: Val::Px(50.),
200                    border,
201                    margin: UiRect::all(Val::Px(20.)),
202                    align_items: AlignItems::Center,
203                    justify_content: JustifyContent::Center,
204                    ..default()
205                },
206                BackgroundColor(MAROON.into()),
207                BorderColor(RED.into()),
208                border_radius,
209                Outline {
210                    width: Val::Px(6.),
211                    offset: Val::Px(6.),
212                    color: Color::WHITE,
213                },
214            ))
215            .add_child(inner_spot)
216            .id();
217        let label_node = commands
218            .spawn((
219                Text::new(label),
220                TextFont {
221                    font_size: 9.0,
222                    ..Default::default()
223                },
224            ))
225            .id();
226        let container = commands
227            .spawn(Node {
228                flex_direction: FlexDirection::Column,
229                align_items: AlignItems::Center,
230                ..default()
231            })
232            .add_children(&[border_node, label_node])
233            .id();
234        commands.entity(root_rounded).add_child(container);
235    }
236
237    let border_label = commands
238        .spawn((
239            Node {
240                margin: UiRect {
241                    left: Val::Px(25.0),
242                    right: Val::Px(25.0),
243                    top: Val::Px(25.0),
244                    bottom: Val::Px(0.0),
245                },
246                ..default()
247            },
248            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
249        ))
250        .with_children(|builder| {
251            builder.spawn((
252                Text::new("Borders"),
253                TextFont {
254                    font_size: 20.0,
255                    ..Default::default()
256                },
257            ));
258        })
259        .id();
260
261    let border_rounded_label = commands
262        .spawn((
263            Node {
264                margin: UiRect {
265                    left: Val::Px(25.0),
266                    right: Val::Px(25.0),
267                    top: Val::Px(25.0),
268                    bottom: Val::Px(0.0),
269                },
270                ..default()
271            },
272            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
273        ))
274        .with_children(|builder| {
275            builder.spawn((
276                Text::new("Borders Rounded"),
277                TextFont {
278                    font_size: 20.0,
279                    ..Default::default()
280                },
281            ));
282        })
283        .id();
284
285    commands
286        .spawn((
287            Node {
288                margin: UiRect::all(Val::Px(25.0)),
289                flex_direction: FlexDirection::Column,
290                align_self: AlignSelf::Stretch,
291                justify_self: JustifySelf::Stretch,
292                flex_wrap: FlexWrap::Wrap,
293                justify_content: JustifyContent::FlexStart,
294                align_items: AlignItems::FlexStart,
295                align_content: AlignContent::FlexStart,
296                ..default()
297            },
298            BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
299        ))
300        .add_child(border_label)
301        .add_child(root)
302        .add_child(border_rounded_label)
303        .add_child(root_rounded);
304}
examples/testbed/full_ui.rs (line 325)
27fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
28    // Camera
29    commands.spawn((Camera2d, IsDefaultUiCamera, BoxShadowSamples(6)));
30
31    // root node
32    commands
33        .spawn(Node {
34            width: Val::Percent(100.0),
35            height: Val::Percent(100.0),
36            justify_content: JustifyContent::SpaceBetween,
37            ..default()
38        })
39        .insert(Pickable::IGNORE)
40        .with_children(|parent| {
41            // left vertical fill (border)
42            parent
43                .spawn((
44                    Node {
45                        width: Val::Px(200.),
46                        border: UiRect::all(Val::Px(2.)),
47                        ..default()
48                    },
49                    BackgroundColor(Color::srgb(0.65, 0.65, 0.65)),
50                ))
51                .with_children(|parent| {
52                    // left vertical fill (content)
53                    parent
54                        .spawn((
55                            Node {
56                                width: Val::Percent(100.),
57                                flex_direction: FlexDirection::Column,
58                                padding: UiRect::all(Val::Px(5.)),
59                                row_gap: Val::Px(5.),
60                                ..default()
61                            },
62                            BackgroundColor(Color::srgb(0.15, 0.15, 0.15)),
63                            Visibility::Visible,
64                        ))
65                        .with_children(|parent| {
66                            // text
67                            parent.spawn((
68                                Text::new("Text Example"),
69                                TextFont {
70                                    font: asset_server.load("fonts/FiraSans-Bold.ttf"),
71                                    font_size: 25.0,
72                                    ..default()
73                                },
74                                // Because this is a distinct label widget and
75                                // not button/list item text, this is necessary
76                                // for accessibility to treat the text accordingly.
77                                Label,
78                            ));
79
80                            #[cfg(feature = "bevy_ui_debug")]
81                            {
82                                // Debug overlay text
83                                parent.spawn((
84                                    Text::new("Press Space to toggle debug outlines."),
85                                    TextFont {
86                                        font: asset_server.load("fonts/FiraSans-Bold.ttf"),
87                                        ..default()
88                                    },
89                                    Label,
90                                ));
91
92                                parent.spawn((
93                                    Text::new("V: toggle UI root's visibility"),
94                                    TextFont {
95                                        font: asset_server.load("fonts/FiraSans-Bold.ttf"),
96                                        font_size: 12.,
97                                        ..default()
98                                    },
99                                    Label,
100                                ));
101
102                                parent.spawn((
103                                    Text::new("S: toggle outlines for hidden nodes"),
104                                    TextFont {
105                                        font: asset_server.load("fonts/FiraSans-Bold.ttf"),
106                                        font_size: 12.,
107                                        ..default()
108                                    },
109                                    Label,
110                                ));
111                                parent.spawn((
112                                    Text::new("C: toggle outlines for clipped nodes"),
113                                    TextFont {
114                                        font: asset_server.load("fonts/FiraSans-Bold.ttf"),
115                                        font_size: 12.,
116                                        ..default()
117                                    },
118                                    Label,
119                                ));
120                            }
121                            #[cfg(not(feature = "bevy_ui_debug"))]
122                            parent.spawn((
123                                Text::new("Try enabling feature \"bevy_ui_debug\"."),
124                                TextFont {
125                                    font: asset_server.load("fonts/FiraSans-Bold.ttf"),
126                                    ..default()
127                                },
128                                Label,
129                            ));
130                        });
131                });
132            // right vertical fill
133            parent
134                .spawn(Node {
135                    flex_direction: FlexDirection::Column,
136                    justify_content: JustifyContent::Center,
137                    align_items: AlignItems::Center,
138                    width: Val::Px(200.),
139                    ..default()
140                })
141                .with_children(|parent| {
142                    // Title
143                    parent.spawn((
144                        Text::new("Scrolling list"),
145                        TextFont {
146                            font: asset_server.load("fonts/FiraSans-Bold.ttf"),
147                            font_size: 21.,
148                            ..default()
149                        },
150                        Label,
151                    ));
152                    // Scrolling list
153                    parent
154                        .spawn((
155                            Node {
156                                flex_direction: FlexDirection::Column,
157                                align_self: AlignSelf::Stretch,
158                                height: Val::Percent(50.),
159                                overflow: Overflow::scroll_y(),
160                                ..default()
161                            },
162                            BackgroundColor(Color::srgb(0.10, 0.10, 0.10)),
163                        ))
164                        .with_children(|parent| {
165                            // List items
166                            for i in 0..25 {
167                                parent
168                                    .spawn((
169                                        Text(format!("Item {i}")),
170                                        TextFont {
171                                            font: asset_server.load("fonts/FiraSans-Bold.ttf"),
172                                            ..default()
173                                        },
174                                        Label,
175                                        AccessibilityNode(Accessible::new(Role::ListItem)),
176                                    ))
177                                    .insert(Pickable {
178                                        should_block_lower: false,
179                                        ..default()
180                                    });
181                            }
182                        });
183                });
184
185            parent
186                .spawn(Node {
187                    left: Val::Px(210.),
188                    bottom: Val::Px(10.),
189                    position_type: PositionType::Absolute,
190                    ..default()
191                })
192                .with_children(|parent| {
193                    parent
194                        .spawn((
195                            Node {
196                                width: Val::Px(200.0),
197                                height: Val::Px(200.0),
198                                border: UiRect::all(Val::Px(20.)),
199                                flex_direction: FlexDirection::Column,
200                                justify_content: JustifyContent::Center,
201                                ..default()
202                            },
203                            BorderColor(LIME.into()),
204                            BackgroundColor(Color::srgb(0.8, 0.8, 1.)),
205                        ))
206                        .with_children(|parent| {
207                            parent.spawn((
208                                ImageNode::new(asset_server.load("branding/bevy_logo_light.png")),
209                                // Uses the transform to rotate the logo image by 45 degrees
210                                Transform::from_rotation(Quat::from_rotation_z(0.25 * PI)),
211                                BorderRadius::all(Val::Px(10.)),
212                                Outline {
213                                    width: Val::Px(2.),
214                                    offset: Val::Px(4.),
215                                    color: DARK_GRAY.into(),
216                                },
217                            ));
218                        });
219                });
220
221            let shadow_style = ShadowStyle {
222                color: Color::BLACK.with_alpha(0.5),
223                blur_radius: Val::Px(2.),
224                x_offset: Val::Px(10.),
225                y_offset: Val::Px(10.),
226                ..default()
227            };
228
229            // render order test: reddest in the back, whitest in the front (flex center)
230            parent
231                .spawn(Node {
232                    width: Val::Percent(100.0),
233                    height: Val::Percent(100.0),
234                    position_type: PositionType::Absolute,
235                    align_items: AlignItems::Center,
236                    justify_content: JustifyContent::Center,
237                    ..default()
238                })
239                .insert(Pickable::IGNORE)
240                .with_children(|parent| {
241                    parent
242                        .spawn((
243                            Node {
244                                width: Val::Px(100.0),
245                                height: Val::Px(100.0),
246                                ..default()
247                            },
248                            BackgroundColor(Color::srgb(1.0, 0.0, 0.)),
249                            BoxShadow::from(shadow_style),
250                        ))
251                        .with_children(|parent| {
252                            parent.spawn((
253                                Node {
254                                    // Take the size of the parent node.
255                                    width: Val::Percent(100.0),
256                                    height: Val::Percent(100.0),
257                                    position_type: PositionType::Absolute,
258                                    left: Val::Px(20.),
259                                    bottom: Val::Px(20.),
260                                    ..default()
261                                },
262                                BackgroundColor(Color::srgb(1.0, 0.3, 0.3)),
263                                BoxShadow::from(shadow_style),
264                            ));
265                            parent.spawn((
266                                Node {
267                                    width: Val::Percent(100.0),
268                                    height: Val::Percent(100.0),
269                                    position_type: PositionType::Absolute,
270                                    left: Val::Px(40.),
271                                    bottom: Val::Px(40.),
272                                    ..default()
273                                },
274                                BackgroundColor(Color::srgb(1.0, 0.5, 0.5)),
275                                BoxShadow::from(shadow_style),
276                            ));
277                            parent.spawn((
278                                Node {
279                                    width: Val::Percent(100.0),
280                                    height: Val::Percent(100.0),
281                                    position_type: PositionType::Absolute,
282                                    left: Val::Px(60.),
283                                    bottom: Val::Px(60.),
284                                    ..default()
285                                },
286                                BackgroundColor(Color::srgb(0.0, 0.7, 0.7)),
287                                BoxShadow::from(shadow_style),
288                            ));
289                            // alpha test
290                            parent.spawn((
291                                Node {
292                                    width: Val::Percent(100.0),
293                                    height: Val::Percent(100.0),
294                                    position_type: PositionType::Absolute,
295                                    left: Val::Px(80.),
296                                    bottom: Val::Px(80.),
297                                    ..default()
298                                },
299                                BackgroundColor(Color::srgba(1.0, 0.9, 0.9, 0.4)),
300                                BoxShadow::from(ShadowStyle {
301                                    color: Color::BLACK.with_alpha(0.3),
302                                    ..shadow_style
303                                }),
304                            ));
305                        });
306                });
307            // bevy logo (flex center)
308            parent
309                .spawn(Node {
310                    width: Val::Percent(100.0),
311                    position_type: PositionType::Absolute,
312                    justify_content: JustifyContent::Center,
313                    align_items: AlignItems::FlexStart,
314                    ..default()
315                })
316                .with_children(|parent| {
317                    // bevy logo (image)
318                    parent
319                        .spawn((
320                            ImageNode::new(asset_server.load("branding/bevy_logo_dark_big.png"))
321                                .with_mode(NodeImageMode::Stretch),
322                            Node {
323                                width: Val::Px(500.0),
324                                height: Val::Px(125.0),
325                                margin: UiRect::top(Val::VMin(5.)),
326                                ..default()
327                            },
328                        ))
329                        .with_children(|parent| {
330                            // alt text
331                            // This UI node takes up no space in the layout and the `Text` component is used by the accessibility module
332                            // and is not rendered.
333                            parent.spawn((
334                                Node {
335                                    display: Display::None,
336                                    ..default()
337                                },
338                                Text::new("Bevy logo"),
339                            ));
340                        });
341                });
342
343            // four bevy icons demonstrating image flipping
344            parent
345                .spawn(Node {
346                    width: Val::Percent(100.0),
347                    height: Val::Percent(100.0),
348                    position_type: PositionType::Absolute,
349                    justify_content: JustifyContent::Center,
350                    align_items: AlignItems::FlexEnd,
351                    column_gap: Val::Px(10.),
352                    padding: UiRect::all(Val::Px(10.)),
353                    ..default()
354                })
355                .insert(Pickable::IGNORE)
356                .with_children(|parent| {
357                    for (flip_x, flip_y) in
358                        [(false, false), (false, true), (true, true), (true, false)]
359                    {
360                        parent.spawn((
361                            ImageNode {
362                                image: asset_server.load("branding/icon.png"),
363                                flip_x,
364                                flip_y,
365                                ..default()
366                            },
367                            Node {
368                                // The height will be chosen automatically to preserve the image's aspect ratio
369                                width: Val::Px(75.),
370                                ..default()
371                            },
372                        ));
373                    }
374                });
375        });
376}
Source

pub const fn bottom(bottom: Val) -> UiRect

Creates a new UiRect where bottom takes the given value, and the other fields are set to Val::ZERO.

§Example
let ui_rect = UiRect::bottom(Val::Px(10.0));

assert_eq!(ui_rect.left, Val::ZERO);
assert_eq!(ui_rect.right, Val::ZERO);
assert_eq!(ui_rect.top, Val::ZERO);
assert_eq!(ui_rect.bottom, Val::Px(10.0));
Examples found in repository?
examples/animation/animation_graph.rs (line 349)
340fn setup_node_lines(commands: &mut Commands) {
341    for line in &HORIZONTAL_LINES {
342        commands.spawn((
343            Node {
344                position_type: PositionType::Absolute,
345                bottom: Val::Px(line.bottom),
346                left: Val::Px(line.left),
347                height: Val::Px(0.0),
348                width: Val::Px(line.length),
349                border: UiRect::bottom(Val::Px(1.0)),
350                ..default()
351            },
352            BorderColor(WHITE.into()),
353        ));
354    }
355
356    for line in &VERTICAL_LINES {
357        commands.spawn((
358            Node {
359                position_type: PositionType::Absolute,
360                bottom: Val::Px(line.bottom),
361                left: Val::Px(line.left),
362                height: Val::Px(line.length),
363                width: Val::Px(0.0),
364                border: UiRect::left(Val::Px(1.0)),
365                ..default()
366            },
367            BorderColor(WHITE.into()),
368        ));
369    }
370}
More examples
Hide additional examples
examples/ui/relative_cursor_position.rs (line 46)
17fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
18    commands.spawn((
19        Camera2d,
20        Camera {
21            // Cursor position will take the viewport offset into account
22            viewport: Some(Viewport {
23                physical_position: [200, 100].into(),
24                physical_size: [600, 600].into(),
25                ..default()
26            }),
27            ..default()
28        },
29    ));
30
31    commands
32        .spawn(Node {
33            width: Val::Percent(100.),
34            height: Val::Percent(100.0),
35            align_items: AlignItems::Center,
36            justify_content: JustifyContent::Center,
37            flex_direction: FlexDirection::Column,
38            ..default()
39        })
40        .with_children(|parent| {
41            parent
42                .spawn((
43                    Node {
44                        width: Val::Px(250.),
45                        height: Val::Px(250.),
46                        margin: UiRect::bottom(Val::Px(15.)),
47                        ..default()
48                    },
49                    BackgroundColor(Color::srgb(235., 35., 12.)),
50                ))
51                .insert(RelativeCursorPosition::default());
52
53            parent.spawn((
54                Text::new("(0.0, 0.0)"),
55                TextFont {
56                    font: asset_server.load("fonts/FiraSans-Bold.ttf"),
57                    font_size: 33.0,
58                    ..default()
59                },
60                TextColor(Color::srgb(0.9, 0.9, 0.9)),
61            ));
62        });
63}
examples/ui/size_constraints.rs (line 78)
41fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
42    // ui camera
43    commands.spawn(Camera2d);
44
45    let text_font = (
46        TextFont {
47            font: asset_server.load("fonts/FiraSans-Bold.ttf"),
48            font_size: 33.0,
49            ..Default::default()
50        },
51        TextColor(Color::srgb(0.9, 0.9, 0.9)),
52    );
53
54    commands
55        .spawn((
56            Node {
57                width: Val::Percent(100.0),
58                height: Val::Percent(100.0),
59                justify_content: JustifyContent::Center,
60                align_items: AlignItems::Center,
61                ..default()
62            },
63            BackgroundColor(Color::BLACK),
64        ))
65        .with_children(|parent| {
66            parent
67                .spawn(Node {
68                    flex_direction: FlexDirection::Column,
69                    align_items: AlignItems::Center,
70                    justify_content: JustifyContent::Center,
71                    ..default()
72                })
73                .with_children(|parent| {
74                    parent.spawn((
75                        Text::new("Size Constraints Example"),
76                        text_font.clone(),
77                        Node {
78                            margin: UiRect::bottom(Val::Px(25.)),
79                            ..Default::default()
80                        },
81                    ));
82
83                    spawn_bar(parent);
84
85                    parent
86                        .spawn((
87                            Node {
88                                flex_direction: FlexDirection::Column,
89                                align_items: AlignItems::Stretch,
90                                padding: UiRect::all(Val::Px(10.)),
91                                margin: UiRect::top(Val::Px(50.)),
92                                ..default()
93                            },
94                            BackgroundColor(YELLOW.into()),
95                        ))
96                        .with_children(|parent| {
97                            for constraint in [
98                                Constraint::MinWidth,
99                                Constraint::FlexBasis,
100                                Constraint::Width,
101                                Constraint::MaxWidth,
102                            ] {
103                                spawn_button_row(parent, constraint, text_font.clone());
104                            }
105                        });
106                });
107        });
108}
examples/ui/overflow.rs (line 53)
15fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
16    commands.spawn(Camera2d);
17
18    let text_style = TextFont::default();
19
20    let image = asset_server.load("branding/icon.png");
21
22    commands
23        .spawn((
24            Node {
25                width: Val::Percent(100.),
26                height: Val::Percent(100.),
27                align_items: AlignItems::Center,
28                justify_content: JustifyContent::Center,
29                ..Default::default()
30            },
31            BackgroundColor(ANTIQUE_WHITE.into()),
32        ))
33        .with_children(|parent| {
34            for overflow in [
35                Overflow::visible(),
36                Overflow::clip_x(),
37                Overflow::clip_y(),
38                Overflow::clip(),
39            ] {
40                parent
41                    .spawn(Node {
42                        flex_direction: FlexDirection::Column,
43                        align_items: AlignItems::Center,
44                        margin: UiRect::horizontal(Val::Px(25.)),
45                        ..Default::default()
46                    })
47                    .with_children(|parent| {
48                        let label = format!("{overflow:#?}");
49                        parent
50                            .spawn((
51                                Node {
52                                    padding: UiRect::all(Val::Px(10.)),
53                                    margin: UiRect::bottom(Val::Px(25.)),
54                                    ..Default::default()
55                                },
56                                BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
57                            ))
58                            .with_children(|parent| {
59                                parent.spawn((Text::new(label), text_style.clone()));
60                            });
61                        parent
62                            .spawn((
63                                Node {
64                                    width: Val::Px(100.),
65                                    height: Val::Px(100.),
66                                    padding: UiRect {
67                                        left: Val::Px(25.),
68                                        top: Val::Px(25.),
69                                        ..Default::default()
70                                    },
71                                    border: UiRect::all(Val::Px(5.)),
72                                    overflow,
73                                    ..default()
74                                },
75                                BorderColor(Color::BLACK),
76                                BackgroundColor(GRAY.into()),
77                            ))
78                            .with_children(|parent| {
79                                parent.spawn((
80                                    ImageNode::new(image.clone()),
81                                    Node {
82                                        min_width: Val::Px(100.),
83                                        min_height: Val::Px(100.),
84                                        ..default()
85                                    },
86                                    Interaction::default(),
87                                    Outline {
88                                        width: Val::Px(2.),
89                                        offset: Val::Px(2.),
90                                        color: Color::NONE,
91                                    },
92                                ));
93                            });
94                    });
95            }
96        });
97}
examples/ui/overflow_clip_margin.rs (line 50)
14fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
15    commands.spawn(Camera2d);
16
17    let image = asset_server.load("branding/icon.png");
18
19    commands
20        .spawn((
21            Node {
22                width: Val::Percent(100.),
23                height: Val::Percent(100.),
24                align_items: AlignItems::Center,
25                justify_content: JustifyContent::Center,
26                row_gap: Val::Px(40.),
27                flex_direction: FlexDirection::Column,
28                ..default()
29            },
30            BackgroundColor(ANTIQUE_WHITE.into()),
31        ))
32        .with_children(|parent| {
33            for overflow_clip_margin in [
34                OverflowClipMargin::border_box().with_margin(25.),
35                OverflowClipMargin::border_box(),
36                OverflowClipMargin::padding_box(),
37                OverflowClipMargin::content_box(),
38            ] {
39                parent
40                    .spawn(Node {
41                        flex_direction: FlexDirection::Row,
42                        column_gap: Val::Px(20.),
43                        ..default()
44                    })
45                    .with_children(|parent| {
46                        parent
47                            .spawn((
48                                Node {
49                                    padding: UiRect::all(Val::Px(10.)),
50                                    margin: UiRect::bottom(Val::Px(25.)),
51                                    ..default()
52                                },
53                                BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
54                            ))
55                            .with_child(Text(format!("{overflow_clip_margin:#?}")));
56
57                        parent
58                            .spawn((
59                                Node {
60                                    margin: UiRect::top(Val::Px(10.)),
61                                    width: Val::Px(100.),
62                                    height: Val::Px(100.),
63                                    padding: UiRect::all(Val::Px(20.)),
64                                    border: UiRect::all(Val::Px(5.)),
65                                    overflow: Overflow::clip(),
66                                    overflow_clip_margin,
67                                    ..default()
68                                },
69                                BackgroundColor(GRAY.into()),
70                                BorderColor(Color::BLACK),
71                            ))
72                            .with_children(|parent| {
73                                parent
74                                    .spawn((
75                                        Node {
76                                            min_width: Val::Px(50.),
77                                            min_height: Val::Px(50.),
78                                            ..default()
79                                        },
80                                        BackgroundColor(LIGHT_CYAN.into()),
81                                    ))
82                                    .with_child((
83                                        ImageNode::new(image.clone()),
84                                        Node {
85                                            min_width: Val::Px(100.),
86                                            min_height: Val::Px(100.),
87                                            ..default()
88                                        },
89                                    ));
90                            });
91                    });
92            }
93        });
94}
examples/ui/display_and_visibility.rs (line 104)
77fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
78    let palette: [Color; 4] = PALETTE.map(|hex| Srgba::hex(hex).unwrap().into());
79
80    let text_font = TextFont {
81        font: asset_server.load("fonts/FiraSans-Bold.ttf"),
82        ..default()
83    };
84
85    commands.spawn(Camera2d);
86    commands
87        .spawn((
88            Node {
89                width: Val::Percent(100.),
90                height: Val::Percent(100.),
91                flex_direction: FlexDirection::Column,
92                align_items: AlignItems::Center,
93                justify_content: JustifyContent::SpaceEvenly,
94                ..Default::default()
95            },
96            BackgroundColor(Color::BLACK),
97        ))
98        .with_children(|parent| {
99            parent.spawn((
100                Text::new("Use the panel on the right to change the Display and Visibility properties for the respective nodes of the panel on the left"),
101                text_font.clone(),
102                TextLayout::new_with_justify(JustifyText::Center),
103                Node {
104                    margin: UiRect::bottom(Val::Px(10.)),
105                    ..Default::default()
106                },
107            ));
108
109            parent
110                .spawn(Node {
111                    width: Val::Percent(100.),
112                    ..default()
113                })
114                .with_children(|parent| {
115                    let mut target_ids = vec![];
116                    parent
117                        .spawn(Node {
118                            width: Val::Percent(50.),
119                            height: Val::Px(520.),
120                            justify_content: JustifyContent::Center,
121                            ..default()
122                        })
123                        .with_children(|parent| {
124                            target_ids = spawn_left_panel(parent, &palette);
125                        });
126
127                    parent
128                        .spawn(Node {
129                            width: Val::Percent(50.),
130                            justify_content: JustifyContent::Center,
131                            ..default()
132                        })
133                        .with_children(|parent| {
134                            spawn_right_panel(parent, text_font, &palette, target_ids);
135                        });
136                });
137
138            parent
139                .spawn(Node {
140                    flex_direction: FlexDirection::Row,
141                    align_items: AlignItems::Start,
142                    justify_content: JustifyContent::Start,
143                    column_gap: Val::Px(10.),
144                    ..default()
145                })
146                .with_children(|builder| {
147                    let text_font = TextFont {
148                        font: asset_server.load("fonts/FiraSans-Bold.ttf"),
149                        ..default()
150                    };
151
152                    builder.spawn((
153                        Text::new("Display::None\nVisibility::Hidden\nVisibility::Inherited"),
154                        text_font.clone(),
155                        TextColor(HIDDEN_COLOR),
156                        TextLayout::new_with_justify(JustifyText::Center),
157                    ));
158                    builder.spawn((
159                        Text::new("-\n-\n-"),
160                        text_font.clone(),
161                        TextColor(DARK_GRAY.into()),
162                        TextLayout::new_with_justify(JustifyText::Center),
163                    ));
164                    builder.spawn((Text::new("The UI Node and its descendants will not be visible and will not be allotted any space in the UI layout.\nThe UI Node will not be visible but will still occupy space in the UI layout.\nThe UI node will inherit the visibility property of its parent. If it has no parent it will be visible."), text_font));
165                });
166        });
167}
Source

pub const fn with_left(self, left: Val) -> UiRect

Returns the UiRect with its left field set to the given value.

§Example
let ui_rect = UiRect::all(Val::Px(20.0)).with_left(Val::Px(10.0));
assert_eq!(ui_rect.left, Val::Px(10.0));
assert_eq!(ui_rect.right, Val::Px(20.0));
assert_eq!(ui_rect.top, Val::Px(20.0));
assert_eq!(ui_rect.bottom, Val::Px(20.0));
Examples found in repository?
examples/3d/../helpers/widgets.rs (line 78)
57pub fn spawn_option_button<T>(
58    parent: &mut ChildSpawnerCommands,
59    option_value: T,
60    option_name: &str,
61    is_selected: bool,
62    is_first: bool,
63    is_last: bool,
64) where
65    T: Clone + Send + Sync + 'static,
66{
67    let (bg_color, fg_color) = if is_selected {
68        (Color::WHITE, Color::BLACK)
69    } else {
70        (Color::BLACK, Color::WHITE)
71    };
72
73    // Add the button node.
74    parent
75        .spawn((
76            Button,
77            Node {
78                border: BUTTON_BORDER.with_left(if is_first { Val::Px(1.0) } else { Val::Px(0.0) }),
79                justify_content: JustifyContent::Center,
80                align_items: AlignItems::Center,
81                padding: BUTTON_PADDING,
82                ..default()
83            },
84            BUTTON_BORDER_COLOR,
85            BorderRadius::ZERO
86                .with_left(if is_first {
87                    BUTTON_BORDER_RADIUS_SIZE
88                } else {
89                    Val::Px(0.0)
90                })
91                .with_right(if is_last {
92                    BUTTON_BORDER_RADIUS_SIZE
93                } else {
94                    Val::Px(0.0)
95                }),
96            BackgroundColor(bg_color),
97        ))
98        .insert(RadioButton)
99        .insert(WidgetClickSender(option_value.clone()))
100        .with_children(|parent| {
101            spawn_ui_text(parent, option_name, fg_color)
102                .insert(RadioButtonText)
103                .insert(WidgetClickSender(option_value));
104        });
105}
Source

pub const fn with_right(self, right: Val) -> UiRect

Returns the UiRect with its right field set to the given value.

§Example
let ui_rect = UiRect::all(Val::Px(20.0)).with_right(Val::Px(10.0));
assert_eq!(ui_rect.left, Val::Px(20.0));
assert_eq!(ui_rect.right, Val::Px(10.0));
assert_eq!(ui_rect.top, Val::Px(20.0));
assert_eq!(ui_rect.bottom, Val::Px(20.0));
Source

pub const fn with_top(self, top: Val) -> UiRect

Returns the UiRect with its top field set to the given value.

§Example
let ui_rect = UiRect::all(Val::Px(20.0)).with_top(Val::Px(10.0));
assert_eq!(ui_rect.left, Val::Px(20.0));
assert_eq!(ui_rect.right, Val::Px(20.0));
assert_eq!(ui_rect.top, Val::Px(10.0));
assert_eq!(ui_rect.bottom, Val::Px(20.0));
Source

pub const fn with_bottom(self, bottom: Val) -> UiRect

Returns the UiRect with its bottom field set to the given value.

§Example
let ui_rect = UiRect::all(Val::Px(20.0)).with_bottom(Val::Px(10.0));
assert_eq!(ui_rect.left, Val::Px(20.0));
assert_eq!(ui_rect.right, Val::Px(20.0));
assert_eq!(ui_rect.top, Val::Px(20.0));
assert_eq!(ui_rect.bottom, Val::Px(10.0));

Trait Implementations§

Source§

impl Clone for UiRect

Source§

fn clone(&self) -> UiRect

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UiRect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for UiRect

Source§

fn default() -> UiRect

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for UiRect

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<UiRect, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromArg for &'static UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

type This<'from_arg> = &'from_arg UiRect

The type to convert into. Read more
Source§

fn from_arg( arg: Arg<'_>, ) -> Result<<&'static UiRect as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromArg for &'static mut UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

type This<'from_arg> = &'from_arg mut UiRect

The type to convert into. Read more
Source§

fn from_arg( arg: Arg<'_>, ) -> Result<<&'static mut UiRect as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromArg for UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

type This<'from_arg> = UiRect

The type to convert into. Read more
Source§

fn from_arg(arg: Arg<'_>) -> Result<<UiRect as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromReflect for UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<UiRect>

Constructs a concrete instance of Self from a reflected value.
Source§

fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails. Read more
Source§

impl GetOwnership for &UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetOwnership for &mut UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetOwnership for UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetTypeRegistration for UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn get_type_registration() -> TypeRegistration

Returns the default TypeRegistration for this type.
Source§

fn register_type_dependencies(registry: &mut TypeRegistry)

Registers other types needed by this type. Read more
Source§

impl IntoReturn for &UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where &UiRect: 'into_return,

Converts Self into a Return value.
Source§

impl IntoReturn for &mut UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where &mut UiRect: 'into_return,

Converts Self into a Return value.
Source§

impl IntoReturn for UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where UiRect: 'into_return,

Converts Self into a Return value.
Source§

impl PartialEq for UiRect

Source§

fn eq(&self, other: &UiRect) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialReflect for UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
Source§

fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>

Tries to apply a reflected value to this value. Read more
Source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<UiRect>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn try_into_reflect( self: Box<UiRect>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>

Attempts to cast this type to a boxed, fully-reflected value.
Source§

fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>

Attempts to cast this type to a fully-reflected value.
Source§

fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>

Attempts to cast this type to a mutable, fully-reflected value.
Source§

fn into_partial_reflect(self: Box<UiRect>) -> Box<dyn PartialReflect>

Casts this type to a boxed, reflected value. Read more
Source§

fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)

Casts this type to a reflected value. Read more
Source§

fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)

Casts this type to a mutable, reflected value. Read more
Source§

fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>

Returns a “partial equality” comparison result. Read more
Source§

fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Debug formatter for the value. Read more
Source§

fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>

Attempts to clone Self using reflection. Read more
Source§

fn apply(&mut self, value: &(dyn PartialReflect + 'static))

Applies a reflected value to this value. Read more
Source§

fn clone_value(&self) -> Box<dyn PartialReflect>

👎Deprecated since 0.16.0: to clone reflected values, prefer using reflect_clone. To convert reflected values to dynamic ones, use to_dynamic.
Clones Self into its dynamic representation. Read more
Source§

fn to_dynamic(&self) -> Box<dyn PartialReflect>

Converts this reflected value into its dynamic representation based on its kind. Read more
Source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
Source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
Source§

impl Reflect for UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn into_any(self: Box<UiRect>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>. Read more
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns the value as a &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns the value as a &mut dyn Any. Read more
Source§

fn into_reflect(self: Box<UiRect>) -> Box<dyn Reflect>

Casts this type to a boxed, fully-reflected value.
Source§

fn as_reflect(&self) -> &(dyn Reflect + 'static)

Casts this type to a fully-reflected value.
Source§

fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)

Casts this type to a mutable, fully-reflected value.
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

impl Serialize for UiRect

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Struct for UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field named name as a &dyn PartialReflect.
Source§

fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field named name as a &mut dyn PartialReflect.
Source§

fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Returns a reference to the value of the field with index index as a &dyn PartialReflect.
Source§

fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Returns a mutable reference to the value of the field with index index as a &mut dyn PartialReflect.
Source§

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.
Source§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
Source§

fn iter_fields(&self) -> FieldIter<'_>

Returns an iterator over the values of the reflectable fields for this struct.
Source§

fn to_dynamic_struct(&self) -> DynamicStruct

Source§

fn clone_dynamic(&self) -> DynamicStruct

👎Deprecated since 0.16.0: use to_dynamic_struct instead
Clones the struct into a DynamicStruct.
Source§

fn get_represented_struct_info(&self) -> Option<&'static StructInfo>

Will return None if TypeInfo is not available.
Source§

impl TypePath for UiRect
where UiRect: Any + Send + Sync,

Source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
Source§

fn short_type_path() -> &'static str

Returns a short, pretty-print enabled path to the type. Read more
Source§

fn type_ident() -> Option<&'static str>

Returns the name of the type, or None if it is anonymous. Read more
Source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
Source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
Source§

impl Typed for UiRect
where UiRect: Any + Send + Sync, Val: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.
Source§

impl Copy for UiRect

Source§

impl StructuralPartialEq for UiRect

Auto Trait Implementations§

§

impl Freeze for UiRect

§

impl RefUnwindSafe for UiRect

§

impl Send for UiRect

§

impl Sync for UiRect

§

impl Unpin for UiRect

§

impl UnwindSafe for UiRect

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynamicTypePath for T
where T: TypePath,

Source§

impl<T> DynamicTyped for T
where T: Typed,

Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<S> GetField for S
where S: Struct,

Source§

fn get_field<T>(&self, name: &str) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
Source§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.
Source§

impl<T> GetPath for T
where T: Reflect + ?Sized,

Source§

fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a reference to the value specified by path. Read more
Source§

fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>

Returns a mutable reference to the value specified by path. Read more
Source§

fn path<'p, T>( &self, path: impl ReflectPath<'p>, ) -> Result<&T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed reference to the value specified by path. Read more
Source§

fn path_mut<'p, T>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed mutable reference to the value specified by path. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Reflectable for T

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,