Skip to main content

BorderRadius

Struct BorderRadius 

Source
pub struct BorderRadius {
    pub top_left: CornerRadius,
    pub top_right: CornerRadius,
    pub bottom_right: CornerRadius,
    pub bottom_left: CornerRadius,
}
Available on crate feature bevy_ui only.
Expand description

Used to add rounded corners to a UI node. You can set a UI node to have uniformly rounded corners, elliptical corners, or specify a different radius for each corner. If a given radius exceeds half the length of the node’s height or width, the radius will be calculated as half the height or width.

Percentage horizontal and vertical values are based on the node’s width and height, respectively.

§Example

fn setup_ui(mut commands: Commands) {
    commands.spawn((
        Node {
            width: Val::Px(100.),
            height: Val::Px(100.),
            border: UiRect::all(Val::Px(2.)),
            border_radius: BorderRadius {
                // rounded corners, x and y radii equal
                top_left: CornerRadius::circular(px(10.)),
                top_right: percent(20.).into(),
                // elliptical corner
                bottom_right: CornerRadius::new(px(30.), px(20.)),
                bottom_left: CornerRadius { x: px(10.), y: px(40.) },
            },
            ..Default::default()
        },
        BackgroundColor(BLUE.into()),
    ));
}

https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius

Fields§

§top_left: CornerRadius

Border radius of the top left corner

§top_right: CornerRadius

Border radius of the top right corner

§bottom_right: CornerRadius

Border radius of the bottom right corner

§bottom_left: CornerRadius

Border radius of the bottom left corner

Implementations§

Source§

impl BorderRadius

Source

pub const DEFAULT: BorderRadius = Self::ZERO

Source

pub const ZERO: BorderRadius

Zero curvature. All the corners will be right-angled.

Source

pub const MAX: BorderRadius

Maximum curvature. The UI Node will take a capsule shape or circular if width and height are equal.

Source

pub const MAX_ELLIPTICAL: BorderRadius

Source

pub fn all(radius: impl Into<CornerRadius>) -> BorderRadius

Set all four corners to the same curvature.

Examples found in repository?
examples/ui/styling/box_shadow.rs (line 53)
43    fn change_node(&self, node: &mut Node) {
44        match *self {
45            Self::Square => {
46                node.width = px(164);
47                node.height = px(164);
48                node.border_radius = BorderRadius::ZERO;
49            }
50            Self::RoundedSquare => {
51                node.width = px(164);
52                node.height = px(164);
53                node.border_radius = BorderRadius::all(px(41));
54            }
55            Self::Circle => {
56                node.width = px(164);
57                node.height = px(164);
58                node.border_radius = BorderRadius::MAX;
59            }
60            Self::LongRectangle => {
61                node.width = px(240);
62                node.height = px(80);
63                node.border_radius = BorderRadius::all(px(32));
64            }
65            Self::TallRectangle => {
66                node.width = px(80);
67                node.height = px(240);
68                node.border_radius = BorderRadius::all(px(32));
69            }
70        }
71    }
More examples
Hide additional examples
examples/ui/ui_material.rs (line 44)
20fn setup(
21    mut commands: Commands,
22    mut ui_materials: ResMut<Assets<CustomUiMaterial>>,
23    asset_server: Res<AssetServer>,
24) {
25    // Camera so we can see UI
26    commands.spawn(Camera2d);
27
28    commands
29        .spawn(Node {
30            width: percent(100),
31            height: percent(100),
32            align_items: AlignItems::Center,
33            justify_content: JustifyContent::Center,
34            ..default()
35        })
36        .with_children(|parent| {
37            let banner_scale_factor = 0.5;
38            parent.spawn((
39                Node {
40                    position_type: PositionType::Absolute,
41                    width: px(905.0 * banner_scale_factor),
42                    height: px(363.0 * banner_scale_factor),
43                    border: UiRect::all(px(20)),
44                    border_radius: BorderRadius::all(px(20)),
45                    ..default()
46                },
47                MaterialNode(ui_materials.add(CustomUiMaterial {
48                    color: LinearRgba::WHITE.to_f32_array().into(),
49                    slider: Vec4::splat(0.5),
50                    color_texture: asset_server.load("branding/banner.png"),
51                    border_color: LinearRgba::WHITE.to_f32_array().into(),
52                })),
53                // UI material nodes can have outlines and shadows like any other UI node
54                Outline {
55                    width: px(2),
56                    offset: px(100),
57                    color: DARK_BLUE.into(),
58                },
59            ));
60        });
61}
examples/ui/widgets/standard_widgets.rs (line 236)
222fn menu_button(asset_server: &AssetServer) -> impl Bundle {
223    (
224        Node { ..default() },
225        DemoMenuAnchor,
226        observe(on_menu_event),
227        children![(
228            Node {
229                width: px(200),
230                height: px(65),
231                border: UiRect::all(px(5)),
232                box_sizing: BoxSizing::BorderBox,
233                justify_content: JustifyContent::SpaceBetween,
234                align_items: AlignItems::Center,
235                padding: UiRect::axes(px(16), px(0)),
236                border_radius: BorderRadius::all(px(5)),
237                ..default()
238            },
239            DemoMenuButton,
240            Button,
241            MenuButton,
242            Hovered::default(),
243            TabIndex(0),
244            BorderColor::all(Color::BLACK),
245            BackgroundColor(NORMAL_BUTTON),
246            children![
247                (
248                    Text::new("Menu"),
249                    TextFont {
250                        font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
251                        font_size: FontSize::Px(33.0),
252                        ..default()
253                    },
254                    TextColor(Color::srgb(0.9, 0.9, 0.9)),
255                    TextShadow::default(),
256                ),
257                (
258                    Node {
259                        width: px(12),
260                        height: px(12),
261                        ..default()
262                    },
263                    BackgroundColor(GRAY.into()),
264                )
265            ],
266        )],
267    )
268}
269
270fn update_button_style(
271    mut buttons: Query<
272        (
273            Has<Pressed>,
274            &Hovered,
275            Has<InteractionDisabled>,
276            &mut BackgroundColor,
277            &mut BorderColor,
278            &Children,
279        ),
280        (
281            Or<(
282                Changed<Pressed>,
283                Changed<Hovered>,
284                Added<InteractionDisabled>,
285            )>,
286            With<DemoButton>,
287        ),
288    >,
289    mut text_query: Query<&mut Text>,
290) {
291    for (pressed, hovered, disabled, mut color, mut border_color, children) in &mut buttons {
292        let mut text = text_query.get_mut(children[0]).unwrap();
293        set_button_style(
294            disabled,
295            hovered.get(),
296            pressed,
297            &mut color,
298            &mut border_color,
299            &mut text,
300        );
301    }
302}
303
304/// Supplementary system to detect removed marker components
305fn update_button_style2(
306    mut buttons: Query<
307        (
308            Has<Pressed>,
309            &Hovered,
310            Has<InteractionDisabled>,
311            &mut BackgroundColor,
312            &mut BorderColor,
313            &Children,
314        ),
315        With<DemoButton>,
316    >,
317    mut removed_depressed: RemovedComponents<Pressed>,
318    mut removed_disabled: RemovedComponents<InteractionDisabled>,
319    mut text_query: Query<&mut Text>,
320) {
321    removed_depressed
322        .read()
323        .chain(removed_disabled.read())
324        .for_each(|entity| {
325            if let Ok((pressed, hovered, disabled, mut color, mut border_color, children)) =
326                buttons.get_mut(entity)
327            {
328                let mut text = text_query.get_mut(children[0]).unwrap();
329                set_button_style(
330                    disabled,
331                    hovered.get(),
332                    pressed,
333                    &mut color,
334                    &mut border_color,
335                    &mut text,
336                );
337            }
338        });
339}
340
341fn set_button_style(
342    disabled: bool,
343    hovered: bool,
344    pressed: bool,
345    color: &mut BackgroundColor,
346    border_color: &mut BorderColor,
347    text: &mut Text,
348) {
349    match (disabled, hovered, pressed) {
350        // Disabled button
351        (true, _, _) => {
352            **text = "Disabled".to_string();
353            *color = NORMAL_BUTTON.into();
354            border_color.set_all(GRAY);
355        }
356
357        // Pressed and hovered button
358        (false, true, true) => {
359            **text = "Press".to_string();
360            *color = PRESSED_BUTTON.into();
361            border_color.set_all(RED);
362        }
363
364        // Hovered, unpressed button
365        (false, true, false) => {
366            **text = "Hover".to_string();
367            *color = HOVERED_BUTTON.into();
368            border_color.set_all(WHITE);
369        }
370
371        // Unhovered button (either pressed or not).
372        (false, false, _) => {
373            **text = "Button".to_string();
374            *color = NORMAL_BUTTON.into();
375            border_color.set_all(BLACK);
376        }
377    }
378}
379
380/// Create a demo slider
381fn slider(min: f32, max: f32, value: f32) -> impl Bundle {
382    (
383        Node {
384            display: Display::Flex,
385            flex_direction: FlexDirection::Column,
386            justify_content: JustifyContent::Center,
387            align_items: AlignItems::Stretch,
388            justify_items: JustifyItems::Center,
389            column_gap: px(4),
390            height: px(12),
391            width: percent(30),
392            ..default()
393        },
394        Name::new("Slider"),
395        Hovered::default(),
396        DemoSlider,
397        Slider {
398            track_click: TrackClick::Snap,
399            ..Default::default()
400        },
401        SliderValue(value),
402        SliderRange::new(min, max),
403        TabIndex(0),
404        Children::spawn((
405            // Slider background rail
406            Spawn((
407                Node {
408                    height: px(6),
409                    border_radius: BorderRadius::all(px(3)),
410                    ..default()
411                },
412                BackgroundColor(SLIDER_TRACK), // Border color for the slider
413            )),
414            // Invisible track to allow absolute placement of thumb entity. This is narrower than
415            // the actual slider, which allows us to position the thumb entity using simple
416            // percentages, without having to measure the actual width of the slider thumb.
417            Spawn((
418                Node {
419                    display: Display::Flex,
420                    position_type: PositionType::Absolute,
421                    left: px(0),
422                    // Track is short by 12px to accommodate the thumb.
423                    right: px(12),
424                    top: px(0),
425                    bottom: px(0),
426                    ..default()
427                },
428                children![(
429                    // Thumb
430                    DemoSliderThumb,
431                    SliderThumb,
432                    Node {
433                        display: Display::Flex,
434                        width: px(12),
435                        height: px(12),
436                        position_type: PositionType::Absolute,
437                        left: percent(0), // This will be updated by the slider's value
438                        border_radius: BorderRadius::MAX,
439                        ..default()
440                    },
441                    BackgroundColor(SLIDER_THUMB),
442                )],
443            )),
444        )),
445    )
446}
447
448/// Update the visuals of the slider based on the slider state.
449fn update_slider_style(
450    sliders: Query<
451        (
452            Entity,
453            &SliderValue,
454            &SliderRange,
455            &Hovered,
456            &SliderDragState,
457            Has<InteractionDisabled>,
458        ),
459        (
460            Or<(
461                Changed<SliderValue>,
462                Changed<SliderRange>,
463                Changed<Hovered>,
464                Changed<SliderDragState>,
465                Added<InteractionDisabled>,
466            )>,
467            With<DemoSlider>,
468        ),
469    >,
470    children: Query<&Children>,
471    mut thumbs: Query<(&mut Node, &mut BackgroundColor, Has<DemoSliderThumb>), Without<DemoSlider>>,
472) {
473    for (slider_ent, value, range, hovered, drag_state, disabled) in sliders.iter() {
474        for child in children.iter_descendants(slider_ent) {
475            if let Ok((mut thumb_node, mut thumb_bg, is_thumb)) = thumbs.get_mut(child)
476                && is_thumb
477            {
478                thumb_node.left = percent(range.thumb_position(value.0) * 100.0);
479                thumb_bg.0 = thumb_color(disabled, hovered.0 | drag_state.dragging);
480            }
481        }
482    }
483}
484
485fn update_slider_style2(
486    sliders: Query<
487        (Entity, &Hovered, &SliderDragState, Has<InteractionDisabled>),
488        With<DemoSlider>,
489    >,
490    children: Query<&Children>,
491    mut thumbs: Query<(&mut BackgroundColor, Has<DemoSliderThumb>), Without<DemoSlider>>,
492    mut removed_disabled: RemovedComponents<InteractionDisabled>,
493) {
494    removed_disabled.read().for_each(|entity| {
495        if let Ok((slider_ent, hovered, drag_state, disabled)) = sliders.get(entity) {
496            for child in children.iter_descendants(slider_ent) {
497                if let Ok((mut thumb_bg, is_thumb)) = thumbs.get_mut(child)
498                    && is_thumb
499                {
500                    thumb_bg.0 = thumb_color(disabled, hovered.0 | drag_state.dragging);
501                }
502            }
503        }
504    });
505}
506
507fn thumb_color(disabled: bool, hovered: bool) -> Color {
508    match (disabled, hovered) {
509        (true, _) => ELEMENT_FILL_DISABLED,
510
511        (false, true) => SLIDER_THUMB.lighter(0.3),
512
513        _ => SLIDER_THUMB,
514    }
515}
516
517/// Create a demo checkbox
518fn checkbox(asset_server: &AssetServer, caption: &str) -> impl Bundle {
519    (
520        Node {
521            display: Display::Flex,
522            flex_direction: FlexDirection::Row,
523            justify_content: JustifyContent::FlexStart,
524            align_items: AlignItems::Center,
525            align_content: AlignContent::Center,
526            column_gap: px(4),
527            ..default()
528        },
529        Name::new("Checkbox"),
530        Hovered::default(),
531        DemoCheckbox,
532        Checkbox,
533        TabIndex(0),
534        Children::spawn((
535            Spawn((
536                // Checkbox outer
537                Node {
538                    display: Display::Flex,
539                    width: px(16),
540                    height: px(16),
541                    border: UiRect::all(px(2)),
542                    border_radius: BorderRadius::all(px(3)),
543                    ..default()
544                },
545                BorderColor::all(ELEMENT_OUTLINE), // Border color for the checkbox
546                children![
547                    // Checkbox inner
548                    (
549                        Node {
550                            display: Display::Flex,
551                            width: px(8),
552                            height: px(8),
553                            position_type: PositionType::Absolute,
554                            left: px(2),
555                            top: px(2),
556                            ..default()
557                        },
558                        BackgroundColor(ELEMENT_FILL),
559                    ),
560                ],
561            )),
562            Spawn((
563                Text::new(caption),
564                TextFont {
565                    font: asset_server.load("fonts/FiraSans-Bold.ttf").into(),
566                    font_size: FontSize::Px(20.0),
567                    ..default()
568                },
569            )),
570        )),
571    )
572}
examples/ui/widgets/vertical_slider.rs (line 160)
134fn vertical_slider() -> impl Bundle {
135    (
136        Node {
137            display: Display::Flex,
138            flex_direction: FlexDirection::Row,
139            justify_content: JustifyContent::Center,
140            align_items: AlignItems::Stretch,
141            column_gap: px(4),
142            width: px(12),
143            height: px(200),
144            ..default()
145        },
146        DemoSlider,
147        VerticalSlider,
148        Hovered::default(),
149        Slider {
150            track_click: TrackClick::Snap,
151            ..Default::default()
152        },
153        SliderValue(50.0),
154        SliderRange::new(0.0, 100.0),
155        TabIndex(0),
156        Children::spawn((
157            Spawn((
158                Node {
159                    width: px(6),
160                    border_radius: BorderRadius::all(px(3)),
161                    ..default()
162                },
163                BackgroundColor(SLIDER_TRACK),
164            )),
165            Spawn((
166                Node {
167                    display: Display::Flex,
168                    position_type: PositionType::Absolute,
169                    top: px(12),
170                    bottom: px(0),
171                    left: px(0),
172                    right: px(0),
173                    ..default()
174                },
175                children![(
176                    DemoSliderThumb,
177                    SliderThumb,
178                    Node {
179                        display: Display::Flex,
180                        width: px(12),
181                        height: px(12),
182                        position_type: PositionType::Absolute,
183                        bottom: percent(0),
184                        border_radius: BorderRadius::MAX,
185                        ..default()
186                    },
187                    BackgroundColor(SLIDER_THUMB),
188                )],
189            )),
190        )),
191    )
192}
193
194fn horizontal_slider() -> impl Bundle {
195    (
196        Node {
197            display: Display::Flex,
198            flex_direction: FlexDirection::Column,
199            justify_content: JustifyContent::Center,
200            align_items: AlignItems::Stretch,
201            column_gap: px(4),
202            height: px(12),
203            width: px(200),
204            ..default()
205        },
206        DemoSlider,
207        Hovered::default(),
208        Slider {
209            track_click: TrackClick::Snap,
210            ..Default::default()
211        },
212        SliderValue(50.0),
213        SliderRange::new(0.0, 100.0),
214        TabIndex(0),
215        Children::spawn((
216            Spawn((
217                Node {
218                    height: px(6),
219                    border_radius: BorderRadius::all(px(3)),
220                    ..default()
221                },
222                BackgroundColor(SLIDER_TRACK),
223            )),
224            Spawn((
225                Node {
226                    display: Display::Flex,
227                    position_type: PositionType::Absolute,
228                    left: px(0),
229                    right: px(12),
230                    top: px(0),
231                    bottom: px(0),
232                    ..default()
233                },
234                children![(
235                    DemoSliderThumb,
236                    SliderThumb,
237                    Node {
238                        display: Display::Flex,
239                        width: px(12),
240                        height: px(12),
241                        position_type: PositionType::Absolute,
242                        left: percent(0),
243                        border_radius: BorderRadius::MAX,
244                        ..default()
245                    },
246                    BackgroundColor(SLIDER_THUMB),
247                )],
248            )),
249        )),
250    )
251}
examples/camera/2d_on_ui.rs (line 48)
13fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
14    // The default camera. `IsDefaultUiCamera` makes this the default camera to render UI elements to. Alternatively, you can add the `UiTargetCamera` component to root UI nodes to define which camera they should be rendered to.
15    commands.spawn((Camera2d, IsDefaultUiCamera));
16
17    // The second camera. The higher order means that this camera will be rendered after the first camera. We will render to this camera to draw on top of the UI.
18    commands.spawn((
19        Camera2d,
20        Camera {
21            order: 1,
22            // Don't draw anything in the background, to see the previous camera.
23            clear_color: ClearColorConfig::None,
24            ..default()
25        },
26        // This camera will only render entities which are on the same render layer.
27        RenderLayers::layer(1),
28    ));
29
30    commands.spawn((
31        // We could also use a `UiTargetCamera` component here instead of the general `IsDefaultUiCamera`.
32        Node {
33            width: percent(100),
34            height: percent(100),
35            display: Display::Flex,
36            justify_content: JustifyContent::Center,
37            align_items: AlignItems::Center,
38            ..default()
39        },
40        BackgroundColor(tailwind::ROSE_400.into()),
41        children![(
42            Node {
43                height: percent(30),
44                width: percent(20),
45                min_height: px(150),
46                min_width: px(150),
47                border: UiRect::all(px(2)),
48                border_radius: BorderRadius::all(percent(25)),
49                ..default()
50            },
51            BorderColor::all(Color::WHITE),
52        )],
53    ));
54
55    // This 2D object will be rendered on the second camera, on top of the default camera where the UI is rendered.
56    commands.spawn((
57        Sprite {
58            image: asset_server.load("textures/rpg/chars/sensei/sensei.png"),
59            custom_size: Some(Vec2::new(100., 100.)),
60            ..default()
61        },
62        RenderLayers::layer(1),
63    ));
64}
examples/3d/solari_reflections.rs (line 414)
405fn spawn_ui(commands: &mut Commands) {
406    commands.spawn((
407        Node {
408            position_type: PositionType::Absolute,
409            bottom: px(12.0),
410            left: px(12.0),
411            flex_direction: FlexDirection::Column,
412            align_items: AlignItems::FlexStart,
413            padding: px(10.0).all(),
414            border_radius: BorderRadius::all(px(4.0)),
415            ..default()
416        },
417        BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.92)),
418        children![
419            heading("PLAYBACK"),
420            row("Space", ControlRow::Pause),
421            static_row("< >", "Scrub objects"),
422            heading("TEST MATERIAL"),
423            row("1", ControlRow::Metallic),
424            row("3-7", ControlRow::Presets),
425            (
426                Node {
427                    align_items: AlignItems::Center,
428                    column_gap: px(KEY_GAP),
429                    margin: UiRect::left(px(KEY_WIDTH + KEY_GAP)),
430                    ..default()
431                },
432                children![
433                    (
434                        RoughnessValueText,
435                        Text::default(),
436                        TextFont::from_font_size(LABEL_SIZE),
437                        TextColor(LABEL_COLOR),
438                    ),
439                    roughness_slider(),
440                ],
441            ),
442            heading("RIGHT MIRROR"),
443            row("8", ControlRow::MirrorPan),
444            row("9", ControlRow::MirrorSlide),
445            heading("RENDERER"),
446            row("P", ControlRow::Renderer),
447            row("2", ControlRow::Denoising),
448        ],
449    ));
450
451    commands.spawn((
452        Node {
453            position_type: PositionType::Absolute,
454            right: px(0.0),
455            padding: px(4.0).all(),
456            border_radius: BorderRadius::bottom_left(px(4.0)),
457            ..default()
458        },
459        BackgroundColor(Color::srgba(0.10, 0.10, 0.10, 0.8)),
460        children![(
461            PerformanceText,
462            Text::default(),
463            TextFont {
464                font_size: FontSize::Px(8.0),
465                ..default()
466            },
467        )],
468    ));
469}
470
471fn heading(title: &str) -> impl Bundle {
472    (
473        Node {
474            margin: UiRect::top(px(7.0)).with_bottom(px(3.0)),
475            ..default()
476        },
477        Text::new(title),
478        TextFont::from_font_size(HEADING_SIZE),
479        TextColor(HEADING_COLOR),
480    )
481}
482
483fn row(key: &str, label: ControlRow) -> impl Bundle {
484    (
485        row_node(),
486        children![
487            key_label(key),
488            (
489                label,
490                Text::default(),
491                TextFont::from_font_size(LABEL_SIZE),
492                TextColor(LABEL_COLOR),
493            ),
494        ],
495    )
496}
497
498fn static_row(key: &str, label: &str) -> impl Bundle {
499    (
500        row_node(),
501        children![
502            key_label(key),
503            (
504                Text::new(label),
505                TextFont::from_font_size(LABEL_SIZE),
506                TextColor(LABEL_COLOR),
507            ),
508        ],
509    )
510}
511
512fn row_node() -> Node {
513    Node {
514        align_items: AlignItems::Center,
515        column_gap: px(KEY_GAP),
516        ..default()
517    }
518}
519
520fn key_label(key: &str) -> impl Bundle {
521    (
522        Node {
523            width: px(KEY_WIDTH),
524            justify_content: JustifyContent::FlexEnd,
525            ..default()
526        },
527        children![(
528            Text::new(key),
529            TextFont::from_font_size(LABEL_SIZE),
530            TextColor(KEY_COLOR),
531        )],
532    )
533}
534
535fn roughness_slider() -> impl Bundle {
536    (
537        Node {
538            width: px(SLIDER_WIDTH),
539            height: px(SLIDER_THUMB_SIZE),
540            flex_direction: FlexDirection::Column,
541            align_items: AlignItems::Stretch,
542            justify_content: JustifyContent::Center,
543            ..default()
544        },
545        RoughnessSlider,
546        Slider {
547            track_click: TrackClick::Snap,
548            ..default()
549        },
550        SliderValue(INITIAL_ROUGHNESS),
551        SliderRange::new(0.0, 1.0),
552        observe(slider_self_update),
553        Children::spawn((
554            Spawn((
555                Node {
556                    height: px(SLIDER_TRACK_HEIGHT),
557                    border_radius: BorderRadius::all(px(SLIDER_TRACK_HEIGHT / 2.0)),
558                    ..default()
559                },
560                BackgroundColor(SLIDER_TRACK),
561            )),
562            Spawn((
563                Node {
564                    position_type: PositionType::Absolute,
565                    left: px(0.0),
566                    right: px(SLIDER_THUMB_SIZE),
567                    top: px(0.0),
568                    bottom: px(0.0),
569                    ..default()
570                },
571                children![
572                    threshold_tick(DELTA_ROUGHNESS),
573                    threshold_tick(GUIDE_ROUGHNESS),
574                    (
575                        RoughnessSliderThumb,
576                        SliderThumb,
577                        Node {
578                            position_type: PositionType::Absolute,
579                            width: px(SLIDER_THUMB_SIZE),
580                            height: px(SLIDER_THUMB_SIZE),
581                            left: percent(INITIAL_ROUGHNESS * 100.0),
582                            border_radius: BorderRadius::MAX,
583                            ..default()
584                        },
585                        BackgroundColor(SLIDER_THUMB),
586                    )
587                ],
588            )),
589        )),
590    )
591}
Source

pub fn new( top_left: impl Into<CornerRadius>, top_right: impl Into<CornerRadius>, bottom_right: impl Into<CornerRadius>, bottom_left: impl Into<CornerRadius>, ) -> BorderRadius

Examples found in repository?
examples/testbed/ui.rs (lines 1314-1331)
1288    pub fn setup(mut commands: Commands, assets: Res<AssetServer>) {
1289        commands.spawn((
1290            Camera2d,
1291            DespawnOnExit(super::Scene::EllipticalBorderRadius),
1292        ));
1293        commands
1294            .spawn((
1295                Node {
1296                    width: percent(100),
1297                    height: percent(100),
1298                    flex_wrap: FlexWrap::Wrap,
1299                    column_gap: px(40),
1300                    row_gap: px(40),
1301                    margin: auto().all(),
1302                    padding: px(30).all(),
1303                    ..default()
1304                },
1305                BackgroundColor(DARK_GRAY.into()),
1306                DespawnOnExit(super::Scene::EllipticalBorderRadius),
1307            ))
1308            .with_children(|builder| {
1309                builder.spawn((
1310                    Node {
1311                        width: px(200),
1312                        height: px(100),
1313                        border: UiRect::all(px(8)),
1314                        border_radius: BorderRadius::new(
1315                            CornerRadius {
1316                                x: px(90),
1317                                y: px(24),
1318                            },
1319                            CornerRadius {
1320                                x: px(18),
1321                                y: px(70),
1322                            },
1323                            CornerRadius {
1324                                x: px(110),
1325                                y: px(32),
1326                            },
1327                            CornerRadius {
1328                                x: px(28),
1329                                y: px(58),
1330                            },
1331                        ),
1332                        ..default()
1333                    },
1334                    BackgroundColor(ORANGE.into()),
1335                    BackgroundGradient::from(LinearGradient {
1336                        stops: vec![
1337                            RED.into(),
1338                            Color::BLACK.into(),
1339                            BLUE.into(),
1340                            WHEAT.into(),
1341                            GREEN.into(),
1342                        ],
1343                        ..default()
1344                    }),
1345                    BorderColor::all(RED),
1346                    Outline {
1347                        width: px(4),
1348                        offset: px(8),
1349                        color: WHITE.into(),
1350                    },
1351                    BoxShadow::from(ShadowStyle {
1352                        blur_radius: px(5),
1353                        ..default()
1354                    }),
1355                ));
1356
1357                builder.spawn((
1358                    Node {
1359                        width: px(150),
1360                        height: px(150),
1361                        border: UiRect {
1362                            left: px(16),
1363                            right: px(4),
1364                            top: px(24),
1365                            bottom: px(8),
1366                        },
1367                        border_radius: BorderRadius::new(
1368                            CornerRadius {
1369                                x: percent(65),
1370                                y: percent(20),
1371                            },
1372                            CornerRadius {
1373                                x: percent(20),
1374                                y: percent(65),
1375                            },
1376                            CornerRadius {
1377                                x: percent(65),
1378                                y: percent(20),
1379                            },
1380                            CornerRadius {
1381                                x: percent(20),
1382                                y: percent(65),
1383                            },
1384                        ),
1385                        ..default()
1386                    },
1387                    BackgroundColor(MEDIUM_SEA_GREEN.into()),
1388                    BorderColor::all(DARK_GREEN),
1389                    Outline {
1390                        width: px(3),
1391                        offset: px(10),
1392                        color: LIME.into(),
1393                    },
1394                    BoxShadow::from(ShadowStyle {
1395                        blur_radius: px(5),
1396                        ..default()
1397                    }),
1398                ));
1399
1400                builder.spawn((
1401                    Node {
1402                        width: px(210),
1403                        height: px(75),
1404                        border: UiRect::axes(px(12), px(4)),
1405                        border_radius: BorderRadius::new(
1406                            CornerRadius {
1407                                x: px(140),
1408                                y: px(18),
1409                            },
1410                            CornerRadius {
1411                                x: px(140),
1412                                y: px(18),
1413                            },
1414                            CornerRadius {
1415                                x: px(42),
1416                                y: px(54),
1417                            },
1418                            CornerRadius {
1419                                x: px(42),
1420                                y: px(54),
1421                            },
1422                        ),
1423                        ..default()
1424                    },
1425                    BackgroundColor(DODGER_BLUE.into()),
1426                    BorderColor::all(NAVY),
1427                    Outline {
1428                        width: px(5),
1429                        offset: px(6),
1430                        color: SKY_BLUE.into(),
1431                    },
1432                    BoxShadow::from(ShadowStyle {
1433                        blur_radius: px(5),
1434                        ..default()
1435                    }),
1436                ));
1437                builder.spawn((
1438                    Node {
1439                        width: px(160),
1440                        height: px(120),
1441                        border: UiRect::axes(px(20), px(20)),
1442                        border_radius: BorderRadius::new(
1443                            CornerRadius {
1444                                x: px(50),
1445                                y: px(10),
1446                            },
1447                            CornerRadius {
1448                                x: px(50),
1449                                y: px(10),
1450                            },
1451                            CornerRadius {
1452                                x: px(50),
1453                                y: px(10),
1454                            },
1455                            CornerRadius {
1456                                x: px(50),
1457                                y: px(10),
1458                            },
1459                        ),
1460                        ..default()
1461                    },
1462                    BackgroundColor(RED.into()),
1463                    BorderColor::all(WHITE),
1464                    Outline {
1465                        width: px(3),
1466                        offset: px(5),
1467                        color: SKY_BLUE.into(),
1468                    },
1469                    BoxShadow::from(ShadowStyle {
1470                        blur_radius: px(5),
1471                        ..default()
1472                    }),
1473                ));
1474
1475                builder.spawn((
1476                    Node {
1477                        width: px(160),
1478                        height: px(120),
1479                        border: UiRect::axes(px(20), px(20)),
1480                        border_radius: BorderRadius::all(px(1000)),
1481                        ..default()
1482                    },
1483                    BackgroundColor(RED.into()),
1484                    BorderColor::all(WHITE),
1485                    Outline {
1486                        width: px(3),
1487                        offset: px(5),
1488                        color: SKY_BLUE.into(),
1489                    },
1490                    BoxShadow::from(ShadowStyle {
1491                        blur_radius: px(5),
1492                        ..default()
1493                    }),
1494                ));
1495
1496                builder.spawn((
1497                    Node {
1498                        width: px(160),
1499                        height: px(120),
1500                        border: UiRect::axes(px(20), px(20)),
1501                        border_radius: BorderRadius {
1502                            top_left: CornerRadius {
1503                                x: px(1000),
1504                                y: auto(),
1505                            },
1506                            top_right: CornerRadius {
1507                                x: auto(),
1508                                y: px(1000),
1509                            },
1510                            bottom_right: CornerRadius::circular(px(1000)),
1511                            bottom_left: CornerRadius::circular(px(1000)),
1512                        },
1513                        ..default()
1514                    },
1515                    BackgroundColor(RED.into()),
1516                    BorderColor::all(WHITE),
1517                    Outline {
1518                        width: px(3),
1519                        offset: px(5),
1520                        color: SKY_BLUE.into(),
1521                    },
1522                    BoxShadow::from(ShadowStyle {
1523                        blur_radius: px(5),
1524                        ..default()
1525                    }),
1526                ));
1527
1528                builder.spawn((
1529                    Node {
1530                        width: px(160),
1531                        height: px(120),
1532                        border: UiRect::axes(px(20), px(20)),
1533                        border_radius: BorderRadius::new(
1534                            CornerRadius {
1535                                x: px(25),
1536                                y: px(20),
1537                            },
1538                            CornerRadius {
1539                                x: px(20),
1540                                y: px(25),
1541                            },
1542                            CornerRadius {
1543                                x: px(20),
1544                                y: px(25),
1545                            },
1546                            CornerRadius {
1547                                x: px(20),
1548                                y: px(25),
1549                            },
1550                        ),
1551                        ..default()
1552                    },
1553                    BackgroundColor(RED.into()),
1554                    ImageNode::from(assets.load("branding/icon.png")),
1555                    BorderColor::all(WHITE),
1556                    Outline {
1557                        width: px(3),
1558                        offset: px(5),
1559                        color: SKY_BLUE.into(),
1560                    },
1561                    BoxShadow::from(ShadowStyle {
1562                        blur_radius: px(5),
1563                        ..default()
1564                    }),
1565                ));
1566
1567                builder.spawn((
1568                    Node {
1569                        width: px(160),
1570                        height: px(120),
1571                        border: UiRect::axes(px(10), px(10)),
1572                        border_radius: BorderRadius::new(
1573                            CornerRadius {
1574                                x: px(40),
1575                                y: px(30),
1576                            },
1577                            CornerRadius {
1578                                x: px(40),
1579                                y: px(30),
1580                            },
1581                            CornerRadius {
1582                                x: px(40),
1583                                y: px(30),
1584                            },
1585                            CornerRadius {
1586                                x: px(40),
1587                                y: px(30),
1588                            },
1589                        ),
1590                        ..default()
1591                    },
1592                    BackgroundColor(RED.into()),
1593                    BorderColor::all(WHITE),
1594                    Outline {
1595                        width: px(3),
1596                        offset: px(5),
1597                        color: SKY_BLUE.into(),
1598                    },
1599                    BoxShadow::from(ShadowStyle {
1600                        blur_radius: px(5),
1601                        ..default()
1602                    }),
1603                ));
1604
1605                builder.spawn((
1606                    Node {
1607                        width: px(160),
1608                        height: px(80),
1609                        border: UiRect::axes(px(10), px(10)),
1610                        border_radius: BorderRadius::new(
1611                            CornerRadius {
1612                                x: percent(50),
1613                                y: percent(50),
1614                            },
1615                            CornerRadius {
1616                                x: percent(50),
1617                                y: percent(50),
1618                            },
1619                            CornerRadius {
1620                                x: percent(50),
1621                                y: percent(50),
1622                            },
1623                            CornerRadius {
1624                                x: percent(50),
1625                                y: percent(50),
1626                            },
1627                        ),
1628                        ..default()
1629                    },
1630                    BackgroundColor(RED.into()),
1631                    BorderColor::all(WHITE),
1632                    ImageNode::from(assets.load("branding/icon.png")),
1633                    Outline {
1634                        width: px(3),
1635                        offset: px(5),
1636                        color: SKY_BLUE.into(),
1637                    },
1638                    BoxShadow::from(ShadowStyle {
1639                        blur_radius: px(5),
1640                        ..default()
1641                    }),
1642                ));
1643
1644                builder.spawn((
1645                    Node {
1646                        width: px(80),
1647                        height: px(160),
1648                        border: UiRect::axes(px(10), px(10)),
1649                        border_radius: BorderRadius::new(
1650                            CornerRadius {
1651                                x: percent(50),
1652                                y: percent(50),
1653                            },
1654                            CornerRadius {
1655                                x: percent(50),
1656                                y: percent(50),
1657                            },
1658                            CornerRadius {
1659                                x: percent(50),
1660                                y: percent(50),
1661                            },
1662                            CornerRadius {
1663                                x: percent(50),
1664                                y: percent(50),
1665                            },
1666                        ),
1667                        ..default()
1668                    },
1669                    BackgroundColor(RED.into()),
1670                    BorderColor::all(WHITE),
1671                    ImageNode::from(assets.load("branding/icon.png")),
1672                    Outline {
1673                        width: px(3),
1674                        offset: px(5),
1675                        color: SKY_BLUE.into(),
1676                    },
1677                    BoxShadow::from(ShadowStyle {
1678                        blur_radius: px(5),
1679                        ..default()
1680                    }),
1681                ));
1682
1683                builder.spawn((
1684                    Node {
1685                        width: px(160),
1686                        height: px(80),
1687                        border: UiRect::axes(px(20), px(10)),
1688                        border_radius: BorderRadius::new(
1689                            CornerRadius {
1690                                x: percent(50),
1691                                y: percent(50),
1692                            },
1693                            CornerRadius {
1694                                x: percent(50),
1695                                y: percent(50),
1696                            },
1697                            CornerRadius {
1698                                x: percent(50),
1699                                y: percent(50),
1700                            },
1701                            CornerRadius {
1702                                x: percent(50),
1703                                y: percent(50),
1704                            },
1705                        ),
1706                        ..default()
1707                    },
1708                    BackgroundColor(RED.into()),
1709                    BorderColor::all(WHITE),
1710                    ImageNode::from(assets.load("branding/icon.png")),
1711                    Outline {
1712                        width: px(3),
1713                        offset: px(5),
1714                        color: SKY_BLUE.into(),
1715                    },
1716                    BoxShadow::from(ShadowStyle {
1717                        blur_radius: px(5),
1718                        ..default()
1719                    }),
1720                ));
1721
1722                builder.spawn((
1723                    Node {
1724                        width: px(80),
1725                        height: px(160),
1726                        border: UiRect::all(px(10)).with_right(px(25)),
1727                        border_radius: BorderRadius::new(
1728                            CornerRadius {
1729                                x: percent(50),
1730                                y: percent(50),
1731                            },
1732                            CornerRadius {
1733                                x: percent(50),
1734                                y: percent(50),
1735                            },
1736                            CornerRadius {
1737                                x: percent(50),
1738                                y: percent(50),
1739                            },
1740                            CornerRadius {
1741                                x: percent(50),
1742                                y: percent(50),
1743                            },
1744                        ),
1745                        ..default()
1746                    },
1747                    BackgroundColor(RED.into()),
1748                    BorderColor::all(WHITE),
1749                    Outline {
1750                        width: px(3),
1751                        offset: px(5),
1752                        color: SKY_BLUE.into(),
1753                    },
1754                    BoxShadow::from(ShadowStyle {
1755                        blur_radius: px(5),
1756                        ..default()
1757                    }),
1758                ));
1759
1760                builder.spawn((
1761                    Node {
1762                        width: px(160),
1763                        height: px(80),
1764                        border: UiRect::all(px(5)),
1765                        border_radius: BorderRadius::new(
1766                            CornerRadius {
1767                                x: percent(50),
1768                                y: percent(50),
1769                            },
1770                            CornerRadius {
1771                                x: percent(50),
1772                                y: percent(50),
1773                            },
1774                            CornerRadius {
1775                                x: percent(50),
1776                                y: percent(50),
1777                            },
1778                            CornerRadius {
1779                                x: px(20),
1780                                y: px(20),
1781                            },
1782                        ),
1783                        ..default()
1784                    },
1785                    BackgroundColor(RED.into()),
1786                    BorderColor::all(WHITE),
1787                    ImageNode::from(assets.load("branding/icon.png")),
1788                    Outline {
1789                        width: px(3),
1790                        offset: px(5),
1791                        color: SKY_BLUE.into(),
1792                    },
1793                    BoxShadow::from(ShadowStyle {
1794                        blur_radius: px(5),
1795                        ..default()
1796                    }),
1797                ));
1798            });
1799    }
Source

pub const fn px( top_left: f32, top_right: f32, bottom_right: f32, bottom_left: f32, ) -> BorderRadius

Sets each corner to a circular radius in logical pixels.

Examples found in repository?
examples/testbed/ui.rs (lines 1258-1263)
1195    pub fn setup(mut commands: Commands) {
1196        commands.spawn((Camera2d, DespawnOnExit(super::Scene::Borders)));
1197        let root = commands
1198            .spawn((
1199                Node {
1200                    flex_wrap: FlexWrap::Wrap,
1201                    ..default()
1202                },
1203                DespawnOnExit(super::Scene::Borders),
1204            ))
1205            .id();
1206
1207        // all the different combinations of border edges
1208        let borders = [
1209            UiRect::default(),
1210            UiRect::all(px(20)),
1211            UiRect::left(px(20)),
1212            UiRect::vertical(px(20)),
1213            UiRect {
1214                left: px(40),
1215                top: px(20),
1216                ..Default::default()
1217            },
1218            UiRect {
1219                right: px(20),
1220                bottom: px(30),
1221                ..Default::default()
1222            },
1223            UiRect {
1224                right: px(20),
1225                top: px(40),
1226                bottom: px(20),
1227                ..Default::default()
1228            },
1229            UiRect {
1230                left: px(20),
1231                top: px(20),
1232                bottom: px(20),
1233                ..Default::default()
1234            },
1235            UiRect {
1236                left: px(20),
1237                right: px(20),
1238                bottom: px(40),
1239                ..Default::default()
1240            },
1241        ];
1242
1243        let non_zero = |x, y| x != px(0) && y != px(0);
1244        let border_size = |x, y| if non_zero(x, y) { f32::MAX } else { 0. };
1245
1246        for border in borders {
1247            for rounded in [true, false] {
1248                let border_node = commands
1249                    .spawn((
1250                        Node {
1251                            width: px(100),
1252                            height: px(100),
1253                            border,
1254                            margin: UiRect::all(px(30)),
1255                            align_items: AlignItems::Center,
1256                            justify_content: JustifyContent::Center,
1257                            border_radius: if rounded {
1258                                BorderRadius::px(
1259                                    border_size(border.left, border.top),
1260                                    border_size(border.right, border.top),
1261                                    border_size(border.right, border.bottom),
1262                                    border_size(border.left, border.bottom),
1263                                )
1264                            } else {
1265                                BorderRadius::ZERO
1266                            },
1267                            ..default()
1268                        },
1269                        BackgroundColor(MAROON.into()),
1270                        BorderColor::all(RED),
1271                        Outline {
1272                            width: px(10),
1273                            offset: px(10),
1274                            color: Color::WHITE,
1275                        },
1276                    ))
1277                    .id();
1278
1279                commands.entity(root).add_child(border_node);
1280            }
1281        }
1282    }
More examples
Hide additional examples
examples/ui/styling/borders.rs (lines 155-160)
12fn setup(mut commands: Commands) {
13    commands.spawn(Camera2d);
14
15    // labels for the different border edges
16    let border_labels = [
17        "None",
18        "All",
19        "Left",
20        "Right",
21        "Top",
22        "Bottom",
23        "Horizontal",
24        "Vertical",
25        "Top Left",
26        "Bottom Left",
27        "Top Right",
28        "Bottom Right",
29        "Top Bottom Right",
30        "Top Bottom Left",
31        "Top Left Right",
32        "Bottom Left Right",
33    ];
34
35    // all the different combinations of border edges
36    // these correspond to the labels above
37    let borders = [
38        UiRect::default(),
39        UiRect::all(px(10)),
40        UiRect::left(px(10)),
41        UiRect::right(px(10)),
42        UiRect::top(px(10)),
43        UiRect::bottom(px(10)),
44        UiRect::horizontal(px(10)),
45        UiRect::vertical(px(10)),
46        UiRect {
47            left: px(20),
48            top: px(10),
49            ..default()
50        },
51        UiRect {
52            left: px(10),
53            bottom: px(20),
54            ..default()
55        },
56        UiRect {
57            right: px(20),
58            top: px(10),
59            ..default()
60        },
61        UiRect {
62            right: px(10),
63            bottom: px(10),
64            ..default()
65        },
66        UiRect {
67            right: px(10),
68            top: px(20),
69            bottom: px(10),
70            ..default()
71        },
72        UiRect {
73            left: px(10),
74            top: px(10),
75            bottom: px(10),
76            ..default()
77        },
78        UiRect {
79            left: px(20),
80            right: px(10),
81            top: px(10),
82            ..default()
83        },
84        UiRect {
85            left: px(10),
86            right: px(10),
87            bottom: px(20),
88            ..default()
89        },
90    ];
91
92    let borders_examples = (
93        Node {
94            margin: px(25).all(),
95            flex_wrap: FlexWrap::Wrap,
96            ..default()
97        },
98        Children::spawn(SpawnIter(border_labels.into_iter().zip(borders).map(
99            |(label, border)| {
100                (
101                    Node {
102                        flex_direction: FlexDirection::Column,
103                        align_items: AlignItems::Center,
104                        ..default()
105                    },
106                    children![
107                        (
108                            Node {
109                                width: px(50),
110                                height: px(50),
111                                border,
112                                margin: px(20).all(),
113                                align_items: AlignItems::Center,
114                                justify_content: JustifyContent::Center,
115                                ..default()
116                            },
117                            BackgroundColor(MAROON.into()),
118                            BorderColor {
119                                top: RED.into(),
120                                bottom: YELLOW.into(),
121                                left: GREEN.into(),
122                                right: BLUE.into(),
123                            },
124                            Outline {
125                                width: px(6),
126                                offset: px(6),
127                                color: Color::WHITE,
128                            },
129                            children![(
130                                Node {
131                                    width: px(10),
132                                    height: px(10),
133                                    ..default()
134                                },
135                                BackgroundColor(YELLOW.into()),
136                            )]
137                        ),
138                        (Text::new(label), TextFont::from_font_size(9.0))
139                    ],
140                )
141            },
142        ))),
143    );
144
145    let non_zero = |x, y| x != px(0) && y != px(0);
146    let border_size = move |x, y| {
147        if non_zero(x, y) {
148            f32::MAX
149        } else {
150            0.
151        }
152    };
153
154    let rounded_border_radii = borders.map(|border| {
155        BorderRadius::px(
156            border_size(border.left, border.top),
157            border_size(border.right, border.top),
158            border_size(border.right, border.bottom),
159            border_size(border.left, border.bottom),
160        )
161    });
162
163    let elliptical_border_labels = [
164        "Ellipse Wide",
165        "Ellipse Tall",
166        "Ellipse Mixed",
167        "Ellipse Percent",
168    ];
169    let elliptical_borders = [
170        UiRect::all(px(10)),
171        UiRect::all(px(10)),
172        UiRect::all(px(10)),
173        UiRect::all(px(10)),
174    ];
175    let elliptical_border_radii = [
176        BorderRadius {
177            top_left: CornerRadius {
178                x: px(25),
179                y: px(8),
180            },
181            top_right: CornerRadius {
182                x: px(25),
183                y: px(8),
184            },
185            bottom_right: CornerRadius {
186                x: px(25),
187                y: px(8),
188            },
189            bottom_left: CornerRadius {
190                x: px(25),
191                y: px(8),
192            },
193        },
194        BorderRadius {
195            top_left: (px(8), px(25)).into(),
196            top_right: (px(8), px(25)).into(),
197            bottom_right: [px(8), px(25)].into(),
198            bottom_left: [px(8), px(25)].into(),
199        },
200        BorderRadius {
201            top_left: CornerRadius {
202                x: px(25),
203                y: px(12),
204            },
205            top_right: CornerRadius {
206                x: px(12),
207                y: px(25),
208            },
209            bottom_right: CornerRadius {
210                x: px(25),
211                y: px(12),
212            },
213            bottom_left: CornerRadius {
214                x: px(12),
215                y: px(25),
216            },
217        },
218        BorderRadius {
219            top_left: CornerRadius {
220                x: percent(50),
221                y: percent(20),
222            },
223            top_right: CornerRadius {
224                x: percent(20),
225                y: percent(50),
226            },
227            bottom_right: CornerRadius {
228                x: percent(50),
229                y: percent(20),
230            },
231            bottom_left: CornerRadius {
232                x: percent(20),
233                y: percent(50),
234            },
235        },
236    ];
237
238    let borders_examples_rounded = (
239        Node {
240            margin: px(25).all(),
241            flex_wrap: FlexWrap::Wrap,
242            ..default()
243        },
244        Children::spawn(SpawnIter(
245            border_labels
246                .into_iter()
247                .zip(borders)
248                .zip(rounded_border_radii)
249                .map(|((label, border), border_radius)| (label, border, border_radius))
250                .chain(
251                    elliptical_border_labels
252                        .into_iter()
253                        .zip(elliptical_borders)
254                        .zip(elliptical_border_radii)
255                        .map(|((label, border), border_radius)| (label, border, border_radius)),
256                )
257                .map(move |(label, border, border_radius)| {
258                    (
259                        Node {
260                            flex_direction: FlexDirection::Column,
261                            align_items: AlignItems::Center,
262                            ..default()
263                        },
264                        children![
265                            (
266                                Node {
267                                    width: px(50),
268                                    height: px(50),
269                                    border,
270                                    margin: px(20).all(),
271                                    align_items: AlignItems::Center,
272                                    justify_content: JustifyContent::Center,
273                                    border_radius,
274                                    ..default()
275                                },
276                                BackgroundColor(MAROON.into()),
277                                BorderColor {
278                                    top: RED.into(),
279                                    bottom: YELLOW.into(),
280                                    left: GREEN.into(),
281                                    right: BLUE.into(),
282                                },
283                                Outline {
284                                    width: px(6),
285                                    offset: px(6),
286                                    color: Color::WHITE,
287                                },
288                                children![(
289                                    Node {
290                                        width: px(10),
291                                        height: px(10),
292                                        border_radius: BorderRadius::MAX,
293                                        ..default()
294                                    },
295                                    BackgroundColor(YELLOW.into()),
296                                )],
297                            ),
298                            (Text::new(label), TextFont::from_font_size(9.0))
299                        ],
300                    )
301                }),
302        )),
303    );
304
305    commands.spawn((
306        Node {
307            margin: px(25).all(),
308            flex_direction: FlexDirection::Column,
309            align_self: AlignSelf::Stretch,
310            justify_self: JustifySelf::Stretch,
311            ..default()
312        },
313        BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
314        children![
315            label("Borders"),
316            borders_examples,
317            label("Borders Rounded"),
318            borders_examples_rounded
319        ],
320    ));
321}
Source

pub const fn percent( top_left: f32, top_right: f32, bottom_right: f32, bottom_left: f32, ) -> BorderRadius

Sets each corners to a circular radius in percentage values.

Source

pub fn top_left(radius: impl Into<CornerRadius>) -> BorderRadius

Sets the radius for the top left corner. Remaining corners will be right-angled.

Examples found in repository?
examples/testbed/ui.rs (line 2857)
2831    pub fn setup(mut commands: Commands) {
2832        let radius = CornerRadius::from(percent(33.));
2833        let width = px(10.);
2834
2835        commands.spawn((Camera2d, DespawnOnExit(super::Scene::OuterColor)));
2836        commands
2837            .spawn((
2838                Node {
2839                    display: Display::Grid,
2840                    grid_template_columns: RepeatedGridTrack::px(3, 200.),
2841                    grid_template_rows: RepeatedGridTrack::px(3, 200.),
2842                    margin: UiRect::AUTO,
2843                    ..default()
2844                },
2845                DespawnOnExit(super::Scene::OuterColor),
2846            ))
2847            .with_children(|builder| {
2848                for (border, border_radius, invert) in [
2849                    (UiRect::ZERO, BorderRadius::bottom_right(radius), true),
2850                    (UiRect::top(width), BorderRadius::top(radius), false),
2851                    (UiRect::ZERO, BorderRadius::bottom_left(radius), true),
2852                    (UiRect::left(width), BorderRadius::left(radius), false),
2853                    (UiRect::all(width), BorderRadius::all(radius.x), true),
2854                    (UiRect::right(width), BorderRadius::right(radius), false),
2855                    (UiRect::ZERO, BorderRadius::top_right(radius), true),
2856                    (UiRect::bottom(width), BorderRadius::bottom(radius), false),
2857                    (UiRect::ZERO, BorderRadius::top_left(radius), true),
2858                ] {
2859                    builder
2860                        .spawn((
2861                            Node {
2862                                width: px(200.),
2863                                height: px(200.),
2864                                border_radius,
2865                                border,
2866                                ..default()
2867                            },
2868                            BorderColor::all(bevy::color::palettes::css::RED),
2869                        ))
2870                        .insert_if(BackgroundColor(Color::WHITE), || !invert)
2871                        .insert_if(OuterColor(Color::WHITE), || invert);
2872                }
2873            });
2874    }
Source

pub fn top_right(radius: impl Into<CornerRadius>) -> BorderRadius

Sets the radius for the top right corner. Remaining corners will be right-angled.

Examples found in repository?
examples/testbed/ui.rs (line 2855)
2831    pub fn setup(mut commands: Commands) {
2832        let radius = CornerRadius::from(percent(33.));
2833        let width = px(10.);
2834
2835        commands.spawn((Camera2d, DespawnOnExit(super::Scene::OuterColor)));
2836        commands
2837            .spawn((
2838                Node {
2839                    display: Display::Grid,
2840                    grid_template_columns: RepeatedGridTrack::px(3, 200.),
2841                    grid_template_rows: RepeatedGridTrack::px(3, 200.),
2842                    margin: UiRect::AUTO,
2843                    ..default()
2844                },
2845                DespawnOnExit(super::Scene::OuterColor),
2846            ))
2847            .with_children(|builder| {
2848                for (border, border_radius, invert) in [
2849                    (UiRect::ZERO, BorderRadius::bottom_right(radius), true),
2850                    (UiRect::top(width), BorderRadius::top(radius), false),
2851                    (UiRect::ZERO, BorderRadius::bottom_left(radius), true),
2852                    (UiRect::left(width), BorderRadius::left(radius), false),
2853                    (UiRect::all(width), BorderRadius::all(radius.x), true),
2854                    (UiRect::right(width), BorderRadius::right(radius), false),
2855                    (UiRect::ZERO, BorderRadius::top_right(radius), true),
2856                    (UiRect::bottom(width), BorderRadius::bottom(radius), false),
2857                    (UiRect::ZERO, BorderRadius::top_left(radius), true),
2858                ] {
2859                    builder
2860                        .spawn((
2861                            Node {
2862                                width: px(200.),
2863                                height: px(200.),
2864                                border_radius,
2865                                border,
2866                                ..default()
2867                            },
2868                            BorderColor::all(bevy::color::palettes::css::RED),
2869                        ))
2870                        .insert_if(BackgroundColor(Color::WHITE), || !invert)
2871                        .insert_if(OuterColor(Color::WHITE), || invert);
2872                }
2873            });
2874    }
Source

pub fn bottom_right(radius: impl Into<CornerRadius>) -> BorderRadius

Sets the radius for the bottom right corner. Remaining corners will be right-angled.

Examples found in repository?
examples/testbed/ui.rs (line 1828)
1805    pub fn setup(mut commands: Commands) {
1806        commands.spawn((Camera2d, DespawnOnExit(super::Scene::BoxShadow)));
1807
1808        commands
1809            .spawn((
1810                Node {
1811                    width: percent(100),
1812                    height: percent(100),
1813                    padding: UiRect::all(px(30)),
1814                    column_gap: px(200),
1815                    flex_wrap: FlexWrap::Wrap,
1816                    ..default()
1817                },
1818                BackgroundColor(GREEN.into()),
1819                DespawnOnExit(super::Scene::BoxShadow),
1820            ))
1821            .with_children(|commands| {
1822                let example_nodes = [
1823                    (
1824                        Vec2::splat(100.),
1825                        Vec2::ZERO,
1826                        10.,
1827                        0.,
1828                        BorderRadius::bottom_right(px(10)),
1829                    ),
1830                    (Vec2::new(200., 50.), Vec2::ZERO, 10., 0., BorderRadius::MAX),
1831                    (
1832                        Vec2::new(100., 50.),
1833                        Vec2::ZERO,
1834                        10.,
1835                        10.,
1836                        BorderRadius::ZERO,
1837                    ),
1838                    (
1839                        Vec2::splat(100.),
1840                        Vec2::splat(20.),
1841                        10.,
1842                        10.,
1843                        BorderRadius::bottom_right(px(10)),
1844                    ),
1845                    (
1846                        Vec2::splat(100.),
1847                        Vec2::splat(50.),
1848                        0.,
1849                        10.,
1850                        BorderRadius::ZERO,
1851                    ),
1852                    (
1853                        Vec2::new(50., 100.),
1854                        Vec2::splat(10.),
1855                        0.,
1856                        10.,
1857                        BorderRadius::MAX,
1858                    ),
1859                ];
1860
1861                for (size, offset, spread, blur, border_radius) in example_nodes {
1862                    commands.spawn((
1863                        Node {
1864                            width: px(size.x),
1865                            height: px(size.y),
1866                            border: UiRect::all(px(2)),
1867                            border_radius,
1868                            ..default()
1869                        },
1870                        BorderColor::all(WHITE),
1871                        BackgroundColor(BLUE.into()),
1872                        BoxShadow::new(
1873                            Color::BLACK.with_alpha(0.9),
1874                            percent(offset.x),
1875                            percent(offset.y),
1876                            percent(spread),
1877                            px(blur),
1878                        ),
1879                    ));
1880                }
1881            });
1882    }
1883}
1884
1885mod text_wrap {
1886    use bevy::prelude::*;
1887
1888    pub fn setup(mut commands: Commands) {
1889        commands.spawn((Camera2d, DespawnOnExit(super::Scene::TextWrap)));
1890
1891        let root = commands
1892            .spawn((
1893                Node {
1894                    flex_direction: FlexDirection::Column,
1895                    width: px(200),
1896                    height: percent(100),
1897                    overflow: Overflow::clip_x(),
1898                    ..default()
1899                },
1900                BackgroundColor(Color::BLACK),
1901                DespawnOnExit(super::Scene::TextWrap),
1902            ))
1903            .id();
1904
1905        for linebreak in [
1906            LineBreak::AnyCharacter,
1907            LineBreak::WordBoundary,
1908            LineBreak::WordOrCharacter,
1909            LineBreak::NoWrap,
1910        ] {
1911            let messages = [
1912                "Lorem ipsum dolor sit amet, consectetur adipiscing elit.".to_string(),
1913                "pneumonoultramicroscopicsilicovolcanoconiosis".to_string(),
1914            ];
1915
1916            for (j, message) in messages.into_iter().enumerate() {
1917                commands.entity(root).with_child((
1918                    Text(message.clone()),
1919                    TextLayout::new(Justify::Left, linebreak),
1920                    BackgroundColor(Color::srgb(0.8 - j as f32 * 0.3, 0., 0.)),
1921                ));
1922            }
1923        }
1924    }
1925}
1926
1927mod overflow {
1928    use bevy::{color::palettes::css::*, prelude::*};
1929
1930    pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
1931        commands.spawn((Camera2d, DespawnOnExit(super::Scene::Overflow)));
1932        let image = asset_server.load("branding/icon.png");
1933
1934        commands
1935            .spawn((
1936                Node {
1937                    width: percent(100),
1938                    height: percent(100),
1939                    align_items: AlignItems::Center,
1940                    justify_content: JustifyContent::SpaceAround,
1941                    ..Default::default()
1942                },
1943                BackgroundColor(BLUE.into()),
1944                DespawnOnExit(super::Scene::Overflow),
1945            ))
1946            .with_children(|parent| {
1947                for overflow in [
1948                    Overflow::visible(),
1949                    Overflow::clip_x(),
1950                    Overflow::clip_y(),
1951                    Overflow::clip(),
1952                ] {
1953                    parent
1954                        .spawn((
1955                            Node {
1956                                width: px(100),
1957                                height: px(100),
1958                                padding: UiRect {
1959                                    left: px(25),
1960                                    top: px(25),
1961                                    ..Default::default()
1962                                },
1963                                border: UiRect::all(px(5)),
1964                                overflow,
1965                                ..default()
1966                            },
1967                            BorderColor::all(RED),
1968                            BackgroundColor(Color::WHITE),
1969                        ))
1970                        .with_children(|parent| {
1971                            parent.spawn((
1972                                ImageNode::new(image.clone()),
1973                                Node {
1974                                    min_width: px(100),
1975                                    min_height: px(100),
1976                                    ..default()
1977                                },
1978                                Outline {
1979                                    width: px(2),
1980                                    offset: px(2),
1981                                    color: Color::NONE,
1982                                },
1983                            ));
1984                        });
1985                }
1986            });
1987    }
1988}
1989
1990mod slice {
1991    use bevy::prelude::*;
1992
1993    pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
1994        commands.spawn((Camera2d, DespawnOnExit(super::Scene::Slice)));
1995        let image = asset_server.load("textures/fantasy_ui_borders/numbered_slices.png");
1996
1997        let slicer = TextureSlicer {
1998            border: BorderRect::all(16.0),
1999            center_scale_mode: SliceScaleMode::Tile { stretch_value: 1.0 },
2000            sides_scale_mode: SliceScaleMode::Tile { stretch_value: 1.0 },
2001            ..default()
2002        };
2003        commands
2004            .spawn((
2005                Node {
2006                    width: percent(100),
2007                    height: percent(100),
2008                    flex_direction: FlexDirection::Column,
2009                    justify_content: JustifyContent::SpaceAround,
2010                    align_content: AlignContent::Center,
2011                    ..default()
2012                },
2013                DespawnOnExit(super::Scene::Slice),
2014            ))
2015            .with_children(|parent| {
2016                for visual_box in [
2017                    VisualBox::BorderBox,
2018                    VisualBox::PaddingBox,
2019                    VisualBox::ContentBox,
2020                ] {
2021                    parent
2022                        .spawn(Node {
2023                            justify_content: JustifyContent::SpaceAround,
2024                            ..default()
2025                        })
2026                        .with_children(|parent| {
2027                            for [w, h] in [[200.0, 200.0], [300.0, 200.0], [150., 200.0]] {
2028                                parent.spawn((
2029                                    ImageNode {
2030                                        image: image.clone(),
2031                                        image_mode: NodeImageMode::Sliced(slicer.clone()),
2032                                        visual_box,
2033                                        ..default()
2034                                    },
2035                                    Node {
2036                                        width: px(w),
2037                                        height: px(h),
2038                                        border: px(20.).all(),
2039                                        padding: px(20.).all(),
2040                                        ..default()
2041                                    },
2042                                    Outline {
2043                                        width: px(2.),
2044                                        ..default()
2045                                    },
2046                                ));
2047                            }
2048
2049                            parent.spawn((
2050                                ImageNode {
2051                                    image: asset_server
2052                                        .load("textures/fantasy_ui_borders/panel-border-010.png"),
2053                                    image_mode: NodeImageMode::Sliced(TextureSlicer {
2054                                        border: BorderRect::all(22.0),
2055                                        center_scale_mode: SliceScaleMode::Stretch,
2056                                        sides_scale_mode: SliceScaleMode::Stretch,
2057                                        max_corner_scale: 1.0,
2058                                    }),
2059                                    visual_box,
2060                                    ..Default::default()
2061                                },
2062                                Node {
2063                                    width: px(200),
2064                                    height: px(200),
2065                                    border: px(20.).all(),
2066                                    padding: px(20.).all(),
2067                                    ..default()
2068                                },
2069                                Outline {
2070                                    color: bevy::color::palettes::css::DARK_CYAN.into(),
2071                                    width: px(2.),
2072                                    ..default()
2073                                },
2074                                BackgroundColor(bevy::color::palettes::css::NAVY.into()),
2075                            ));
2076                        });
2077                }
2078            });
2079    }
2080}
2081
2082mod layout_rounding {
2083    use bevy::{color::palettes::css::*, prelude::*};
2084
2085    pub fn setup(mut commands: Commands) {
2086        commands.spawn((Camera2d, DespawnOnExit(super::Scene::LayoutRounding)));
2087
2088        commands
2089            .spawn((
2090                Node {
2091                    display: Display::Grid,
2092                    width: percent(100),
2093                    height: percent(100),
2094                    grid_template_rows: vec![RepeatedGridTrack::fr(10, 1.)],
2095                    ..Default::default()
2096                },
2097                BackgroundColor(Color::WHITE),
2098                DespawnOnExit(super::Scene::LayoutRounding),
2099            ))
2100            .with_children(|commands| {
2101                for i in 2..12 {
2102                    commands
2103                        .spawn(Node {
2104                            display: Display::Grid,
2105                            grid_template_columns: vec![RepeatedGridTrack::fr(i, 1.)],
2106                            ..Default::default()
2107                        })
2108                        .with_children(|commands| {
2109                            for _ in 0..i {
2110                                commands.spawn((
2111                                    Node {
2112                                        border: UiRect::all(px(5)),
2113                                        ..Default::default()
2114                                    },
2115                                    BackgroundColor(MAROON.into()),
2116                                    BorderColor::all(DARK_BLUE),
2117                                ));
2118                            }
2119                        });
2120                }
2121            });
2122    }
2123}
2124
2125mod linear_gradient {
2126    use bevy::camera::Camera2d;
2127    use bevy::color::palettes::css::BLUE;
2128    use bevy::color::palettes::css::LIME;
2129    use bevy::color::palettes::css::RED;
2130    use bevy::color::palettes::css::YELLOW;
2131    use bevy::color::Color;
2132    use bevy::ecs::prelude::*;
2133    use bevy::state::state_scoped::DespawnOnExit;
2134    use bevy::text::TextFont;
2135    use bevy::ui::widget::Text;
2136    use bevy::ui::AlignItems;
2137    use bevy::ui::BackgroundGradient;
2138    use bevy::ui::ColorStop;
2139    use bevy::ui::GridPlacement;
2140    use bevy::ui::InterpolationColorSpace;
2141    use bevy::ui::JustifyContent;
2142    use bevy::ui::LinearGradient;
2143    use bevy::ui::Node;
2144    use bevy::ui::PositionType;
2145    use bevy::utils::default;
2146
2147    pub fn setup(mut commands: Commands) {
2148        commands.spawn((Camera2d, DespawnOnExit(super::Scene::LinearGradient)));
2149        commands
2150            .spawn((
2151                Node {
2152                    flex_direction: bevy::ui::FlexDirection::Column,
2153                    width: bevy::ui::percent(100),
2154                    height: bevy::ui::percent(100),
2155                    justify_content: JustifyContent::Center,
2156                    align_items: AlignItems::Center,
2157                    row_gap: bevy::ui::px(5),
2158                    ..default()
2159                },
2160                DespawnOnExit(super::Scene::LinearGradient),
2161            ))
2162            .with_children(|commands| {
2163                let mut i = 0;
2164                commands
2165                    .spawn(Node {
2166                        display: bevy::ui::Display::Grid,
2167                        row_gap: bevy::ui::px(4),
2168                        column_gap: bevy::ui::px(4),
2169                        ..Default::default()
2170                    })
2171                    .with_children(|commands| {
2172                        for stops in [
2173                            vec![ColorStop::auto(RED), ColorStop::auto(YELLOW)],
2174                            vec![
2175                                ColorStop::auto(Color::BLACK),
2176                                ColorStop::auto(RED),
2177                                ColorStop::auto(Color::WHITE),
2178                            ],
2179                            vec![
2180                                Color::hsl(180.71191, 0.0, 0.3137255).into(),
2181                                Color::hsl(180.71191, 0.5, 0.3137255).into(),
2182                                Color::hsl(180.71191, 1.0, 0.3137255).into(),
2183                            ],
2184                            vec![
2185                                Color::hsl(180.71191, 0.825, 0.0).into(),
2186                                Color::hsl(180.71191, 0.825, 0.5).into(),
2187                                Color::hsl(180.71191, 0.825, 1.0).into(),
2188                            ],
2189                            vec![
2190                                Color::hsl(0.0 + 0.0001, 1.0, 0.5).into(),
2191                                Color::hsl(180.0, 1.0, 0.5).into(),
2192                                Color::hsl(360.0 - 0.0001, 1.0, 0.5).into(),
2193                            ],
2194                            vec![
2195                                Color::WHITE.into(),
2196                                RED.into(),
2197                                LIME.into(),
2198                                BLUE.into(),
2199                                Color::BLACK.into(),
2200                            ],
2201                        ] {
2202                            for color_space in [
2203                                InterpolationColorSpace::LinearRgba,
2204                                InterpolationColorSpace::Srgba,
2205                                InterpolationColorSpace::Oklaba,
2206                                InterpolationColorSpace::Oklcha,
2207                                InterpolationColorSpace::OklchaLong,
2208                                InterpolationColorSpace::Hsla,
2209                                InterpolationColorSpace::HslaLong,
2210                                InterpolationColorSpace::Hsva,
2211                                InterpolationColorSpace::HsvaLong,
2212                            ] {
2213                                let row = i % 18 + 1;
2214                                let column = i / 18 + 1;
2215                                i += 1;
2216
2217                                commands.spawn((
2218                                    Node {
2219                                        grid_row: GridPlacement::start(row as i16 + 1),
2220                                        grid_column: GridPlacement::start(column as i16 + 1),
2221                                        justify_content: JustifyContent::SpaceEvenly,
2222                                        ..Default::default()
2223                                    },
2224                                    children![(
2225                                        Node {
2226                                            height: bevy::ui::px(30),
2227                                            width: bevy::ui::px(300),
2228                                            justify_content: JustifyContent::Center,
2229                                            ..Default::default()
2230                                        },
2231                                        BackgroundGradient::from(LinearGradient {
2232                                            color_space,
2233                                            angle: LinearGradient::TO_RIGHT,
2234                                            stops: stops.clone(),
2235                                        }),
2236                                        children![
2237                                            Node {
2238                                                position_type: PositionType::Absolute,
2239                                                ..default()
2240                                            },
2241                                            TextFont::from_font_size(10.),
2242                                            Text(format!("{color_space:?}")),
2243                                        ]
2244                                    )],
2245                                ));
2246                            }
2247                        }
2248                    });
2249            });
2250    }
2251}
2252
2253mod radial_gradient {
2254    use bevy::color::palettes::css::RED;
2255    use bevy::color::palettes::tailwind::GRAY_700;
2256    use bevy::prelude::*;
2257    use bevy::ui::ColorStop;
2258
2259    const CELL_SIZE: f32 = 80.;
2260    const GAP: f32 = 10.;
2261
2262    pub fn setup(mut commands: Commands) {
2263        let color_stops = vec![
2264            ColorStop::new(Color::BLACK, px(5)),
2265            ColorStop::new(Color::WHITE, px(5)),
2266            ColorStop::new(Color::WHITE, percent(100)),
2267            ColorStop::auto(RED),
2268        ];
2269
2270        commands.spawn((Camera2d, DespawnOnExit(super::Scene::RadialGradient)));
2271        commands
2272            .spawn((
2273                Node {
2274                    width: percent(100),
2275                    height: percent(100),
2276                    display: Display::Grid,
2277                    align_items: AlignItems::Start,
2278                    grid_template_columns: vec![RepeatedGridTrack::px(
2279                        GridTrackRepetition::AutoFill,
2280                        CELL_SIZE,
2281                    )],
2282                    grid_auto_flow: GridAutoFlow::Row,
2283                    row_gap: px(GAP),
2284                    column_gap: px(GAP),
2285                    padding: UiRect::all(px(GAP)),
2286                    ..default()
2287                },
2288                DespawnOnExit(super::Scene::RadialGradient),
2289            ))
2290            .with_children(|commands| {
2291                for (shape, shape_label) in [
2292                    (RadialGradientShape::ClosestSide, "ClosestSide"),
2293                    (RadialGradientShape::FarthestSide, "FarthestSide"),
2294                    (RadialGradientShape::Circle(percent(55)), "Circle(55%)"),
2295                    (RadialGradientShape::FarthestCorner, "FarthestCorner"),
2296                ] {
2297                    for (position, position_label) in [
2298                        (UiPosition::TOP_LEFT, "TOP_LEFT"),
2299                        (UiPosition::LEFT, "LEFT"),
2300                        (UiPosition::BOTTOM_LEFT, "BOTTOM_LEFT"),
2301                        (UiPosition::TOP, "TOP"),
2302                        (UiPosition::CENTER, "CENTER"),
2303                        (UiPosition::BOTTOM, "BOTTOM"),
2304                        (UiPosition::TOP_RIGHT, "TOP_RIGHT"),
2305                        (UiPosition::RIGHT, "RIGHT"),
2306                        (UiPosition::BOTTOM_RIGHT, "BOTTOM_RIGHT"),
2307                    ] {
2308                        for (w, h) in [(CELL_SIZE, CELL_SIZE), (CELL_SIZE, CELL_SIZE / 2.)] {
2309                            commands
2310                                .spawn((
2311                                    BackgroundColor(GRAY_700.into()),
2312                                    Node {
2313                                        display: Display::Grid,
2314                                        width: px(CELL_SIZE),
2315                                        ..Default::default()
2316                                    },
2317                                ))
2318                                .with_children(|commands| {
2319                                    commands.spawn((
2320                                        Node {
2321                                            margin: UiRect::all(px(2)),
2322                                            ..default()
2323                                        },
2324                                        Text(format!("{shape_label}\n{position_label}")),
2325                                        TextFont::from_font_size(9.),
2326                                    ));
2327                                    commands.spawn((
2328                                        Node {
2329                                            width: px(w),
2330                                            height: px(h),
2331                                            ..default()
2332                                        },
2333                                        BackgroundGradient::from(RadialGradient {
2334                                            stops: color_stops.clone(),
2335                                            position,
2336                                            shape,
2337                                            ..default()
2338                                        }),
2339                                    ));
2340                                });
2341                        }
2342                    }
2343                }
2344            });
2345    }
2346}
2347
2348mod transformations {
2349    use bevy::{color::palettes::css::*, prelude::*};
2350
2351    pub fn setup(mut commands: Commands) {
2352        commands.spawn((Camera2d, DespawnOnExit(super::Scene::Transformations)));
2353        commands
2354            .spawn((
2355                Node {
2356                    width: percent(100),
2357                    height: percent(100),
2358                    display: Display::Block,
2359                    ..default()
2360                },
2361                DespawnOnExit(super::Scene::Transformations),
2362            ))
2363            .with_children(|parent| {
2364                for (transformation, label, background) in [
2365                    (
2366                        UiTransform::from_rotation(Rot2::degrees(45.)),
2367                        "Rotate 45 degrees",
2368                        RED,
2369                    ),
2370                    (
2371                        UiTransform::from_scale(Vec2::new(2., 0.5)),
2372                        "Scale 2.x 0.5y",
2373                        GREEN,
2374                    ),
2375                    (
2376                        UiTransform::from_translation(Val2::px(-50., 50.)),
2377                        "Translate -50px x +50px y",
2378                        BLUE,
2379                    ),
2380                    (
2381                        UiTransform {
2382                            translation: Val2::px(50., 0.),
2383                            scale: Vec2::new(-1., 1.),
2384                            rotation: Rot2::degrees(30.),
2385                        },
2386                        "T 50px x\nS -1.x (refl)\nR 30deg",
2387                        DARK_CYAN,
2388                    ),
2389                ] {
2390                    parent
2391                        .spawn((Node {
2392                            width: percent(100),
2393                            margin: UiRect {
2394                                top: px(50),
2395                                bottom: px(50),
2396                                ..default()
2397                            },
2398                            align_items: AlignItems::Center,
2399                            justify_content: JustifyContent::SpaceAround,
2400                            ..default()
2401                        },))
2402                        .with_children(|row| {
2403                            row.spawn((
2404                                Text::new("Before Tf"),
2405                                Node {
2406                                    width: px(100),
2407                                    height: px(100),
2408                                    border_radius: BorderRadius::bottom_right(px(25.)),
2409                                    ..default()
2410                                },
2411                                BackgroundColor(background.into()),
2412                                TextFont::default(),
2413                            ));
2414                            row.spawn((
2415                                Text::new(label),
2416                                Node {
2417                                    width: px(100),
2418                                    height: px(100),
2419                                    border_radius: BorderRadius::bottom_right(px(25.)),
2420                                    ..default()
2421                                },
2422                                BackgroundColor(background.into()),
2423                                transformation,
2424                                TextFont::default(),
2425                            ));
2426                        });
2427                }
2428            });
2429    }
2430}
2431
2432#[cfg(feature = "bevy_ui_debug")]
2433mod debug_outlines {
2434    use bevy::{
2435        color::palettes::css::{BLUE, GRAY, RED},
2436        prelude::*,
2437        ui_render::UiDebugOptions,
2438    };
2439
2440    pub fn setup(mut commands: Commands, mut debug_options: ResMut<GlobalUiDebugOptions>) {
2441        debug_options.enabled = true;
2442        debug_options.line_width = 5.;
2443        debug_options.line_color_override = Some(LinearRgba::GREEN);
2444        debug_options.show_hidden = true;
2445        debug_options.show_clipped = true;
2446
2447        let debug_options: UiDebugOptions = (*debug_options.as_ref()).into();
2448
2449        commands.spawn((Camera2d, DespawnOnExit(super::Scene::DebugOutlines)));
2450        commands
2451            .spawn((
2452                Node {
2453                    width: percent(100),
2454                    height: percent(50),
2455                    align_items: AlignItems::Center,
2456                    justify_content: JustifyContent::SpaceAround,
2457                    ..default()
2458                },
2459                DespawnOnExit(super::Scene::DebugOutlines),
2460            ))
2461            .with_children(|parent| {
2462                parent.spawn((
2463                    Node {
2464                        width: px(100),
2465                        height: px(100),
2466                        ..default()
2467                    },
2468                    BackgroundColor(GRAY.into()),
2469                    UiTransform::from_rotation(Rot2::degrees(45.)),
2470                ));
2471
2472                parent.spawn((Text::new("Regular Text"), TextFont::default()));
2473
2474                parent.spawn((
2475                    Node {
2476                        width: px(100),
2477                        height: px(100),
2478                        ..default()
2479                    },
2480                    Text::new("Invisible"),
2481                    BackgroundColor(GRAY.into()),
2482                    TextFont::default(),
2483                    Visibility::Hidden,
2484                ));
2485
2486                parent
2487                    .spawn((
2488                        Node {
2489                            width: px(100),
2490                            height: px(100),
2491                            padding: UiRect {
2492                                left: px(25),
2493                                top: px(25),
2494                                ..Default::default()
2495                            },
2496                            overflow: Overflow::clip(),
2497                            ..default()
2498                        },
2499                        BackgroundColor(RED.into()),
2500                    ))
2501                    .with_children(|child| {
2502                        child.spawn((
2503                            Node {
2504                                min_width: px(100),
2505                                min_height: px(100),
2506                                ..default()
2507                            },
2508                            BackgroundColor(BLUE.into()),
2509                        ));
2510                    });
2511            });
2512
2513        commands
2514            .spawn((
2515                Node {
2516                    width: percent(100),
2517                    height: percent(50),
2518                    top: percent(50),
2519                    align_items: AlignItems::Center,
2520                    justify_content: JustifyContent::SpaceAround,
2521                    ..default()
2522                },
2523                DespawnOnExit(super::Scene::DebugOutlines),
2524            ))
2525            .with_children(|parent| {
2526                parent.spawn((
2527                    Node {
2528                        width: px(200),
2529                        height: px(200),
2530                        border: UiRect {
2531                            top: px(10),
2532                            bottom: px(20),
2533                            left: px(30),
2534                            right: px(40),
2535                        },
2536                        border_radius: BorderRadius::bottom_right(px(10)),
2537                        padding: UiRect {
2538                            top: px(40),
2539                            bottom: px(30),
2540                            left: px(20),
2541                            right: px(10),
2542                        },
2543                        ..default()
2544                    },
2545                    children![(
2546                        Text::new("border padding content outlines"),
2547                        TextFont::default(),
2548                        UiDebugOptions {
2549                            enabled: false,
2550                            ..default()
2551                        }
2552                    )],
2553                    UiDebugOptions {
2554                        outline_border_box: true,
2555                        outline_padding_box: true,
2556                        outline_content_box: true,
2557                        ignore_border_radius: false,
2558                        ..debug_options
2559                    },
2560                ));
2561
2562                // Vertical scrollbar (non-functional)
2563                parent.spawn((
2564                    Node {
2565                        flex_direction: FlexDirection::Column,
2566                        width: px(90),
2567                        height: px(230),
2568                        overflow: Overflow::scroll_y(),
2569                        scrollbar_width: 20.,
2570                        ..default()
2571                    },
2572                    ScrollPosition(Vec2::new(180., 180.)),
2573                    UiDebugOptions {
2574                        line_width: 3.,
2575                        outline_scrollbars: true,
2576                        show_hidden: false,
2577                        show_clipped: false,
2578                        ..debug_options
2579                    },
2580                    Children::spawn(SpawnIter((0..20).map(move |i| {
2581                        (
2582                            Node::default(),
2583                            children![(
2584                                Text(format!("Item {i}")),
2585                                UiDebugOptions {
2586                                    enabled: false,
2587                                    ..default()
2588                                }
2589                            )],
2590                            UiDebugOptions {
2591                                enabled: false,
2592                                ..default()
2593                            },
2594                        )
2595                    }))),
2596                ));
2597
2598                // Horizontal scrollbar (non-functional)
2599                parent.spawn((
2600                    Node {
2601                        flex_direction: FlexDirection::Row,
2602                        width: px(156),
2603                        height: px(70),
2604                        overflow: Overflow::scroll_x(),
2605                        scrollbar_width: 10.,
2606                        ..default()
2607                    },
2608                    UiDebugOptions {
2609                        line_width: 3.,
2610                        outline_scrollbars: true,
2611                        show_hidden: false,
2612                        show_clipped: false,
2613                        ..debug_options
2614                    },
2615                    Children::spawn(SpawnIter((0..20).map(move |i| {
2616                        (
2617                            Node::default(),
2618                            children![(
2619                                Text(format!("Item {i}")),
2620                                UiDebugOptions {
2621                                    enabled: false,
2622                                    ..default()
2623                                }
2624                            )],
2625                            UiDebugOptions {
2626                                enabled: false,
2627                                ..default()
2628                            },
2629                        )
2630                    }))),
2631                ));
2632
2633                // bi-directional scrollbar (non-functional)
2634                parent.spawn((
2635                    Node {
2636                        flex_direction: FlexDirection::Column,
2637                        width: px(230),
2638                        height: px(125),
2639                        overflow: Overflow::scroll(),
2640                        scrollbar_width: 20.,
2641                        ..default()
2642                    },
2643                    ScrollPosition(Vec2::new(300., 0.)),
2644                    UiDebugOptions {
2645                        line_width: 3.,
2646                        outline_scrollbars: true,
2647                        show_hidden: false,
2648                        show_clipped: false,
2649                        ..debug_options
2650                    },
2651                    Children::spawn(SpawnIter((0..6).map(move |i| {
2652                        (
2653                            Node {
2654                                flex_direction: FlexDirection::Row,
2655                                ..default()
2656                            },
2657                            Children::spawn(SpawnIter((0..6).map({
2658                                move |j| {
2659                                    (
2660                                        Text(format!("Item {}", (i * 5) + j)),
2661                                        UiDebugOptions {
2662                                            enabled: false,
2663                                            ..default()
2664                                        },
2665                                    )
2666                                }
2667                            }))),
2668                            UiDebugOptions {
2669                                enabled: false,
2670                                ..default()
2671                            },
2672                        )
2673                    }))),
2674                ));
2675            });
2676    }
2677
2678    pub fn teardown(mut debug_options: ResMut<GlobalUiDebugOptions>) {
2679        *debug_options = GlobalUiDebugOptions::default();
2680    }
2681}
2682
2683mod viewport_coords {
2684    use bevy::{color::palettes::css::*, prelude::*};
2685
2686    const PALETTE: [Srgba; 9] = [RED, WHITE, BEIGE, AQUA, CRIMSON, NAVY, AZURE, LIME, BLACK];
2687
2688    pub fn setup(mut commands: Commands) {
2689        commands.spawn((Camera2d, DespawnOnExit(super::Scene::ViewportCoords)));
2690        commands
2691            .spawn((
2692                Node {
2693                    width: vw(100),
2694                    height: vh(100),
2695                    border: UiRect::axes(vw(5), vh(5)),
2696                    flex_wrap: FlexWrap::Wrap,
2697                    ..default()
2698                },
2699                BorderColor::all(PALETTE[0]),
2700                DespawnOnExit(super::Scene::ViewportCoords),
2701            ))
2702            .with_children(|builder| {
2703                builder.spawn((
2704                    Node {
2705                        width: vw(30),
2706                        height: vh(30),
2707                        border: UiRect::all(vmin(5)),
2708                        ..default()
2709                    },
2710                    BackgroundColor(PALETTE[1].into()),
2711                    BorderColor::all(PALETTE[8]),
2712                ));
2713
2714                builder.spawn((
2715                    Node {
2716                        width: vw(60),
2717                        height: vh(30),
2718                        ..default()
2719                    },
2720                    BackgroundColor(PALETTE[2].into()),
2721                ));
2722
2723                builder.spawn((
2724                    Node {
2725                        width: vw(45),
2726                        height: vh(30),
2727                        border: UiRect::left(vmax(45. / 2.)),
2728                        ..default()
2729                    },
2730                    BackgroundColor(PALETTE[3].into()),
2731                    BorderColor::all(PALETTE[7]),
2732                ));
2733
2734                builder.spawn((
2735                    Node {
2736                        width: vw(45),
2737                        height: vh(30),
2738                        border: UiRect::right(vmax(45. / 2.)),
2739                        ..default()
2740                    },
2741                    BackgroundColor(PALETTE[4].into()),
2742                    BorderColor::all(PALETTE[7]),
2743                ));
2744
2745                builder.spawn((
2746                    Node {
2747                        width: vw(60),
2748                        height: vh(30),
2749                        ..default()
2750                    },
2751                    BackgroundColor(PALETTE[5].into()),
2752                ));
2753
2754                builder.spawn((
2755                    Node {
2756                        width: vw(30),
2757                        height: vh(30),
2758                        border: UiRect::all(vmin(5)),
2759                        ..default()
2760                    },
2761                    BackgroundColor(PALETTE[6].into()),
2762                    BorderColor::all(PALETTE[8]),
2763                ));
2764            });
2765    }
2766}
2767
2768mod viewport_node {
2769    use bevy::{
2770        camera::RenderTarget, prelude::*, render::render_resource::TextureFormat,
2771        ui::widget::ViewportNode,
2772    };
2773
2774    pub fn setup(
2775        mut commands: Commands,
2776        mut images: ResMut<Assets<Image>>,
2777        mut meshes: ResMut<Assets<Mesh>>,
2778        mut materials: ResMut<Assets<StandardMaterial>>,
2779    ) {
2780        commands.spawn((
2781            Camera3d::default(),
2782            DespawnOnExit(super::Scene::ViewportNode),
2783        ));
2784
2785        let image = Image::new_target_texture(0, 0, TextureFormat::Bgra8UnormSrgb, None);
2786        let image_handle = images.add(image);
2787
2788        let camera = commands
2789            .spawn((
2790                Camera3d::default(),
2791                Camera {
2792                    order: -1,
2793                    ..default()
2794                },
2795                RenderTarget::Image(image_handle.into()),
2796                DespawnOnExit(super::Scene::ViewportNode),
2797            ))
2798            .id();
2799
2800        commands.spawn((
2801            Mesh3d(meshes.add(Cuboid::new(5.0, 5.0, 5.0))),
2802            MeshMaterial3d(materials.add(Color::WHITE)),
2803            Transform {
2804                translation: Vec3::new(0.0, 0.0, -10.0),
2805                rotation: Quat::from_euler(EulerRot::XYZ, 0.4, 0.7, 0.1),
2806                ..default()
2807            },
2808            DespawnOnExit(super::Scene::ViewportNode),
2809        ));
2810
2811        commands.spawn((
2812            Node {
2813                position_type: PositionType::Absolute,
2814                top: px(50),
2815                left: px(50),
2816                width: px(200),
2817                height: px(200),
2818                border: UiRect::all(px(5)),
2819                ..default()
2820            },
2821            BorderColor::all(Color::WHITE),
2822            ViewportNode::new(camera),
2823            DespawnOnExit(super::Scene::ViewportNode),
2824        ));
2825    }
2826}
2827
2828mod outer_color {
2829    use bevy::prelude::*;
2830
2831    pub fn setup(mut commands: Commands) {
2832        let radius = CornerRadius::from(percent(33.));
2833        let width = px(10.);
2834
2835        commands.spawn((Camera2d, DespawnOnExit(super::Scene::OuterColor)));
2836        commands
2837            .spawn((
2838                Node {
2839                    display: Display::Grid,
2840                    grid_template_columns: RepeatedGridTrack::px(3, 200.),
2841                    grid_template_rows: RepeatedGridTrack::px(3, 200.),
2842                    margin: UiRect::AUTO,
2843                    ..default()
2844                },
2845                DespawnOnExit(super::Scene::OuterColor),
2846            ))
2847            .with_children(|builder| {
2848                for (border, border_radius, invert) in [
2849                    (UiRect::ZERO, BorderRadius::bottom_right(radius), true),
2850                    (UiRect::top(width), BorderRadius::top(radius), false),
2851                    (UiRect::ZERO, BorderRadius::bottom_left(radius), true),
2852                    (UiRect::left(width), BorderRadius::left(radius), false),
2853                    (UiRect::all(width), BorderRadius::all(radius.x), true),
2854                    (UiRect::right(width), BorderRadius::right(radius), false),
2855                    (UiRect::ZERO, BorderRadius::top_right(radius), true),
2856                    (UiRect::bottom(width), BorderRadius::bottom(radius), false),
2857                    (UiRect::ZERO, BorderRadius::top_left(radius), true),
2858                ] {
2859                    builder
2860                        .spawn((
2861                            Node {
2862                                width: px(200.),
2863                                height: px(200.),
2864                                border_radius,
2865                                border,
2866                                ..default()
2867                            },
2868                            BorderColor::all(bevy::color::palettes::css::RED),
2869                        ))
2870                        .insert_if(BackgroundColor(Color::WHITE), || !invert)
2871                        .insert_if(OuterColor(Color::WHITE), || invert);
2872                }
2873            });
2874    }
Source

pub fn bottom_left(radius: impl Into<CornerRadius>) -> BorderRadius

Sets the radii for the bottom left corner. Remaining corners will be right-angled.

Examples found in repository?
examples/testbed/ui.rs (line 2851)
2831    pub fn setup(mut commands: Commands) {
2832        let radius = CornerRadius::from(percent(33.));
2833        let width = px(10.);
2834
2835        commands.spawn((Camera2d, DespawnOnExit(super::Scene::OuterColor)));
2836        commands
2837            .spawn((
2838                Node {
2839                    display: Display::Grid,
2840                    grid_template_columns: RepeatedGridTrack::px(3, 200.),
2841                    grid_template_rows: RepeatedGridTrack::px(3, 200.),
2842                    margin: UiRect::AUTO,
2843                    ..default()
2844                },
2845                DespawnOnExit(super::Scene::OuterColor),
2846            ))
2847            .with_children(|builder| {
2848                for (border, border_radius, invert) in [
2849                    (UiRect::ZERO, BorderRadius::bottom_right(radius), true),
2850                    (UiRect::top(width), BorderRadius::top(radius), false),
2851                    (UiRect::ZERO, BorderRadius::bottom_left(radius), true),
2852                    (UiRect::left(width), BorderRadius::left(radius), false),
2853                    (UiRect::all(width), BorderRadius::all(radius.x), true),
2854                    (UiRect::right(width), BorderRadius::right(radius), false),
2855                    (UiRect::ZERO, BorderRadius::top_right(radius), true),
2856                    (UiRect::bottom(width), BorderRadius::bottom(radius), false),
2857                    (UiRect::ZERO, BorderRadius::top_left(radius), true),
2858                ] {
2859                    builder
2860                        .spawn((
2861                            Node {
2862                                width: px(200.),
2863                                height: px(200.),
2864                                border_radius,
2865                                border,
2866                                ..default()
2867                            },
2868                            BorderColor::all(bevy::color::palettes::css::RED),
2869                        ))
2870                        .insert_if(BackgroundColor(Color::WHITE), || !invert)
2871                        .insert_if(OuterColor(Color::WHITE), || invert);
2872                }
2873            });
2874    }
More examples
Hide additional examples
examples/3d/solari_reflections.rs (line 456)
405fn spawn_ui(commands: &mut Commands) {
406    commands.spawn((
407        Node {
408            position_type: PositionType::Absolute,
409            bottom: px(12.0),
410            left: px(12.0),
411            flex_direction: FlexDirection::Column,
412            align_items: AlignItems::FlexStart,
413            padding: px(10.0).all(),
414            border_radius: BorderRadius::all(px(4.0)),
415            ..default()
416        },
417        BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.92)),
418        children![
419            heading("PLAYBACK"),
420            row("Space", ControlRow::Pause),
421            static_row("< >", "Scrub objects"),
422            heading("TEST MATERIAL"),
423            row("1", ControlRow::Metallic),
424            row("3-7", ControlRow::Presets),
425            (
426                Node {
427                    align_items: AlignItems::Center,
428                    column_gap: px(KEY_GAP),
429                    margin: UiRect::left(px(KEY_WIDTH + KEY_GAP)),
430                    ..default()
431                },
432                children![
433                    (
434                        RoughnessValueText,
435                        Text::default(),
436                        TextFont::from_font_size(LABEL_SIZE),
437                        TextColor(LABEL_COLOR),
438                    ),
439                    roughness_slider(),
440                ],
441            ),
442            heading("RIGHT MIRROR"),
443            row("8", ControlRow::MirrorPan),
444            row("9", ControlRow::MirrorSlide),
445            heading("RENDERER"),
446            row("P", ControlRow::Renderer),
447            row("2", ControlRow::Denoising),
448        ],
449    ));
450
451    commands.spawn((
452        Node {
453            position_type: PositionType::Absolute,
454            right: px(0.0),
455            padding: px(4.0).all(),
456            border_radius: BorderRadius::bottom_left(px(4.0)),
457            ..default()
458        },
459        BackgroundColor(Color::srgba(0.10, 0.10, 0.10, 0.8)),
460        children![(
461            PerformanceText,
462            Text::default(),
463            TextFont {
464                font_size: FontSize::Px(8.0),
465                ..default()
466            },
467        )],
468    ));
469}
examples/3d/solari.rs (line 188)
84fn setup_pica_pica(
85    mut commands: Commands,
86    asset_server: Res<AssetServer>,
87    args: Res<Args>,
88    #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] dlss_rr_supported: Option<
89        Res<DlssRayReconstructionSupported>,
90    >,
91) {
92    commands
93        .spawn((
94            WorldAssetRoot(
95                asset_server.load(
96                    GltfAssetLabel::Scene(0)
97                        .from_asset("https://github.com/bevyengine/bevy_asset_files/raw/2a5950295a8b6d9d051d59c0df69e87abcda58c3/pica_pica/mini_diorama_01.glb")
98                ),
99            ),
100            Transform::from_scale(Vec3::splat(10.0)),
101        ))
102        .observe(add_raytracing_meshes_on_scene_load);
103
104    commands
105        .spawn((
106            WorldAssetRoot(asset_server.load(
107                GltfAssetLabel::Scene(0).from_asset("https://github.com/bevyengine/bevy_asset_files/raw/2a5950295a8b6d9d051d59c0df69e87abcda58c3/pica_pica/robot_01.glb")
108            )),
109            Transform::from_scale(Vec3::splat(2.0))
110                .with_translation(Vec3::new(-2.0, 0.05, -2.1))
111                .with_rotation(Quat::from_rotation_y(PI / 2.0)),
112            PatrolPath {
113                path: vec![
114                    (Vec3::new(-2.0, 0.05, -2.1), Quat::from_rotation_y(PI / 2.0)),
115                    (Vec3::new(2.2, 0.05, -2.1), Quat::from_rotation_y(0.0)),
116                    (
117                        Vec3::new(2.2, 0.05, 2.1),
118                        Quat::from_rotation_y(3.0 * PI / 2.0),
119                    ),
120                    (Vec3::new(-2.0, 0.05, 2.1), Quat::from_rotation_y(PI)),
121                ],
122                i: 0,
123            },
124        ))
125        .observe(add_raytracing_meshes_on_scene_load);
126
127    commands.spawn((
128        DirectionalLight {
129            illuminance: light_consts::lux::FULL_DAYLIGHT,
130            shadow_maps_enabled: false, // Solari replaces shadow mapping
131            ..default()
132        },
133        Transform::from_rotation(Quat::from_xyzw(
134            -0.13334629,
135            -0.86597735,
136            -0.3586996,
137            0.3219264,
138        )),
139    ));
140
141    let mut camera = commands.spawn((
142        Camera3d::default(),
143        Camera {
144            clear_color: ClearColorConfig::Custom(Color::BLACK),
145            ..default()
146        },
147        FreeCamera {
148            walk_speed: 3.0,
149            run_speed: 10.0,
150            ..Default::default()
151        },
152        Transform::from_translation(Vec3::new(0.219417, 2.5764852, 6.9718704)).with_rotation(
153            Quat::from_xyzw(-0.1466768, 0.013738206, 0.002037309, 0.989087),
154        ),
155        // Msaa::Off and CameraMainTextureUsages with STORAGE_BINDING are required for Solari
156        CameraMainTextureUsages::default().with(TextureUsages::STORAGE_BINDING),
157        Msaa::Off,
158    ));
159
160    if args.pathtracer == Some(true) {
161        camera.insert(Pathtracer::default());
162    } else {
163        camera.insert(SolariLighting::default());
164    }
165
166    // Using DLSS Ray Reconstruction for denoising (and cheaper rendering via upscaling) is _highly_ recommended when using Solari
167    #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))]
168    if dlss_rr_supported.is_some() {
169        camera.insert(Dlss::<DlssRayReconstructionFeature>::default());
170    }
171
172    commands.spawn((
173        ControlText,
174        Text::default(),
175        Node {
176            position_type: PositionType::Absolute,
177            bottom: px(12.0),
178            left: px(12.0),
179            ..default()
180        },
181    ));
182
183    commands.spawn((
184        Node {
185            position_type: PositionType::Absolute,
186            right: px(0.0),
187            padding: px(4.0).all(),
188            border_radius: BorderRadius::bottom_left(px(4.0)),
189            ..default()
190        },
191        BackgroundColor(Color::srgba(0.10, 0.10, 0.10, 0.8)),
192        children![(
193            PerformanceText,
194            Text::default(),
195            TextFont {
196                font_size: FontSize::Px(8.0),
197                ..default()
198            },
199        )],
200    ));
201}
202
203fn setup_many_lights(
204    mut commands: Commands,
205    asset_server: Res<AssetServer>,
206    mut meshes: ResMut<Assets<Mesh>>,
207    mut materials: ResMut<Assets<StandardMaterial>>,
208    args: Res<Args>,
209    #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] dlss_rr_supported: Option<
210        Res<DlssRayReconstructionSupported>,
211    >,
212) {
213    let mut rng = ChaCha8Rng::seed_from_u64(42);
214
215    let mut plane_mesh = Plane3d::default()
216        .mesh()
217        .size(400.0, 400.0)
218        .build()
219        .with_generated_tangents()
220        .unwrap();
221    match plane_mesh.attribute_mut(Mesh::ATTRIBUTE_UV_0).unwrap() {
222        VertexAttributeValues::Float32x2(items) => {
223            items.iter_mut().flatten().for_each(|x| *x *= 3.0);
224        }
225        _ => unreachable!(),
226    }
227    let plane_mesh = meshes.add(plane_mesh);
228    let cube_mesh = meshes.add(
229        Cuboid::default()
230            .mesh()
231            .build()
232            .with_generated_tangents()
233            .unwrap(),
234    );
235    let sphere_mesh = meshes.add(
236        Sphere::new(1.0)
237            .mesh()
238            .build()
239            .with_generated_tangents()
240            .unwrap(),
241    );
242
243    commands
244        .spawn((
245            RaytracingMesh3d(plane_mesh.clone()),
246            MeshMaterial3d(
247                materials.add(StandardMaterial {
248                    base_color_texture: Some(
249                        asset_server
250                            .load_builder()
251                            .with_settings::<ImageLoaderSettings>(|settings| {
252                                settings
253                                    .sampler
254                                    .get_or_init_descriptor()
255                                    .set_address_mode(ImageAddressMode::Repeat);
256                            })
257                            .load("textures/uv_checker_bw.png"),
258                    ),
259                    perceptual_roughness: 0.0,
260                    ..default()
261                }),
262            ),
263        ))
264        .insert_if(Mesh3d(plane_mesh), || args.pathtracer != Some(true));
265
266    for _ in 0..8000 {
267        commands
268            .spawn((
269                RaytracingMesh3d(cube_mesh.clone()),
270                MeshMaterial3d(materials.add(StandardMaterial {
271                    base_color: Color::srgb(rng.random(), rng.random(), rng.random()),
272                    perceptual_roughness: rng.random(),
273                    ..default()
274                })),
275                Transform::default()
276                    .with_scale(Vec3 {
277                        x: rng.random_range(0.2..=2.0),
278                        y: rng.random_range(0.2..=2.0),
279                        z: rng.random_range(0.2..=2.0),
280                    })
281                    .with_translation(Vec3::new(
282                        rng.random_range(-180.0..=180.0),
283                        0.2,
284                        rng.random_range(-180.0..=180.0),
285                    )),
286            ))
287            .insert_if(Mesh3d(cube_mesh.clone()), || args.pathtracer != Some(true));
288    }
289
290    for x in -10..=10 {
291        for y in -10..=10 {
292            commands
293                .spawn((
294                    RaytracingMesh3d(sphere_mesh.clone()),
295                    MeshMaterial3d(
296                        materials.add(StandardMaterial {
297                            emissive: Color::linear_rgb(
298                                rng.random::<f32>() * 60000.0,
299                                rng.random::<f32>() * 60000.0,
300                                rng.random::<f32>() * 60000.0,
301                            )
302                            .into(),
303                            ..default()
304                        }),
305                    ),
306                    Transform::default().with_translation(Vec3::new(
307                        (x * 20) as f32,
308                        7.0,
309                        (y * 20) as f32,
310                    )),
311                ))
312                .insert_if(Mesh3d(sphere_mesh.clone()), || {
313                    args.pathtracer != Some(true)
314                });
315        }
316    }
317
318    let mut camera = commands.spawn((
319        Camera3d::default(),
320        Camera {
321            clear_color: ClearColorConfig::Custom(Color::BLACK),
322            ..default()
323        },
324        FreeCamera {
325            walk_speed: 3.0,
326            run_speed: 10.0,
327            ..Default::default()
328        },
329        Transform::from_translation(Vec3::new(6.11329, 166.74896, 451.8226)).with_rotation(
330            Quat::from_xyzw(-0.183938, 0.009093744, 0.0017017953, 0.9828943),
331        ),
332        // Msaa::Off and CameraMainTextureUsages with STORAGE_BINDING are required for Solari
333        CameraMainTextureUsages::default().with(TextureUsages::STORAGE_BINDING),
334        Msaa::Off,
335        Bloom {
336            intensity: 0.1,
337            ..Bloom::NATURAL
338        },
339    ));
340
341    if args.pathtracer == Some(true) {
342        camera.insert(Pathtracer::default());
343    } else {
344        camera.insert(SolariLighting::default());
345    }
346
347    // Using DLSS Ray Reconstruction for denoising (and cheaper rendering via upscaling) is _highly_ recommended when using Solari
348    #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))]
349    if dlss_rr_supported.is_some() {
350        camera.insert(Dlss::<DlssRayReconstructionFeature>::default());
351    }
352
353    commands.spawn((
354        ControlText,
355        Text::default(),
356        Node {
357            position_type: PositionType::Absolute,
358            bottom: px(12.0),
359            left: px(12.0),
360            ..default()
361        },
362    ));
363
364    commands.spawn((
365        Node {
366            position_type: PositionType::Absolute,
367            right: px(0.0),
368            padding: px(4.0).all(),
369            border_radius: BorderRadius::bottom_left(px(4.0)),
370            ..default()
371        },
372        BackgroundColor(Color::srgba(0.10, 0.10, 0.10, 0.8)),
373        children![(
374            PerformanceText,
375            Text::default(),
376            TextFont {
377                font_size: FontSize::Px(8.0),
378                ..default()
379            },
380        )],
381    ));
382}
Source

pub fn left(radius: impl Into<CornerRadius>) -> BorderRadius

Sets the radii for the top left and bottom left corners. Remaining corners will be right-angled.

Examples found in repository?
examples/testbed/ui.rs (line 2852)
2831    pub fn setup(mut commands: Commands) {
2832        let radius = CornerRadius::from(percent(33.));
2833        let width = px(10.);
2834
2835        commands.spawn((Camera2d, DespawnOnExit(super::Scene::OuterColor)));
2836        commands
2837            .spawn((
2838                Node {
2839                    display: Display::Grid,
2840                    grid_template_columns: RepeatedGridTrack::px(3, 200.),
2841                    grid_template_rows: RepeatedGridTrack::px(3, 200.),
2842                    margin: UiRect::AUTO,
2843                    ..default()
2844                },
2845                DespawnOnExit(super::Scene::OuterColor),
2846            ))
2847            .with_children(|builder| {
2848                for (border, border_radius, invert) in [
2849                    (UiRect::ZERO, BorderRadius::bottom_right(radius), true),
2850                    (UiRect::top(width), BorderRadius::top(radius), false),
2851                    (UiRect::ZERO, BorderRadius::bottom_left(radius), true),
2852                    (UiRect::left(width), BorderRadius::left(radius), false),
2853                    (UiRect::all(width), BorderRadius::all(radius.x), true),
2854                    (UiRect::right(width), BorderRadius::right(radius), false),
2855                    (UiRect::ZERO, BorderRadius::top_right(radius), true),
2856                    (UiRect::bottom(width), BorderRadius::bottom(radius), false),
2857                    (UiRect::ZERO, BorderRadius::top_left(radius), true),
2858                ] {
2859                    builder
2860                        .spawn((
2861                            Node {
2862                                width: px(200.),
2863                                height: px(200.),
2864                                border_radius,
2865                                border,
2866                                ..default()
2867                            },
2868                            BorderColor::all(bevy::color::palettes::css::RED),
2869                        ))
2870                        .insert_if(BackgroundColor(Color::WHITE), || !invert)
2871                        .insert_if(OuterColor(Color::WHITE), || invert);
2872                }
2873            });
2874    }
Source

pub fn right(radius: impl Into<CornerRadius>) -> BorderRadius

Sets the radii for the top right and bottom right corners. Remaining corners will be right-angled.

Examples found in repository?
examples/testbed/ui.rs (line 2854)
2831    pub fn setup(mut commands: Commands) {
2832        let radius = CornerRadius::from(percent(33.));
2833        let width = px(10.);
2834
2835        commands.spawn((Camera2d, DespawnOnExit(super::Scene::OuterColor)));
2836        commands
2837            .spawn((
2838                Node {
2839                    display: Display::Grid,
2840                    grid_template_columns: RepeatedGridTrack::px(3, 200.),
2841                    grid_template_rows: RepeatedGridTrack::px(3, 200.),
2842                    margin: UiRect::AUTO,
2843                    ..default()
2844                },
2845                DespawnOnExit(super::Scene::OuterColor),
2846            ))
2847            .with_children(|builder| {
2848                for (border, border_radius, invert) in [
2849                    (UiRect::ZERO, BorderRadius::bottom_right(radius), true),
2850                    (UiRect::top(width), BorderRadius::top(radius), false),
2851                    (UiRect::ZERO, BorderRadius::bottom_left(radius), true),
2852                    (UiRect::left(width), BorderRadius::left(radius), false),
2853                    (UiRect::all(width), BorderRadius::all(radius.x), true),
2854                    (UiRect::right(width), BorderRadius::right(radius), false),
2855                    (UiRect::ZERO, BorderRadius::top_right(radius), true),
2856                    (UiRect::bottom(width), BorderRadius::bottom(radius), false),
2857                    (UiRect::ZERO, BorderRadius::top_left(radius), true),
2858                ] {
2859                    builder
2860                        .spawn((
2861                            Node {
2862                                width: px(200.),
2863                                height: px(200.),
2864                                border_radius,
2865                                border,
2866                                ..default()
2867                            },
2868                            BorderColor::all(bevy::color::palettes::css::RED),
2869                        ))
2870                        .insert_if(BackgroundColor(Color::WHITE), || !invert)
2871                        .insert_if(OuterColor(Color::WHITE), || invert);
2872                }
2873            });
2874    }
Source

pub fn top(radius: impl Into<CornerRadius>) -> BorderRadius

Sets the radii for the top left and top right corners. Remaining corners will be right-angled.

Examples found in repository?
examples/testbed/ui.rs (line 2850)
2831    pub fn setup(mut commands: Commands) {
2832        let radius = CornerRadius::from(percent(33.));
2833        let width = px(10.);
2834
2835        commands.spawn((Camera2d, DespawnOnExit(super::Scene::OuterColor)));
2836        commands
2837            .spawn((
2838                Node {
2839                    display: Display::Grid,
2840                    grid_template_columns: RepeatedGridTrack::px(3, 200.),
2841                    grid_template_rows: RepeatedGridTrack::px(3, 200.),
2842                    margin: UiRect::AUTO,
2843                    ..default()
2844                },
2845                DespawnOnExit(super::Scene::OuterColor),
2846            ))
2847            .with_children(|builder| {
2848                for (border, border_radius, invert) in [
2849                    (UiRect::ZERO, BorderRadius::bottom_right(radius), true),
2850                    (UiRect::top(width), BorderRadius::top(radius), false),
2851                    (UiRect::ZERO, BorderRadius::bottom_left(radius), true),
2852                    (UiRect::left(width), BorderRadius::left(radius), false),
2853                    (UiRect::all(width), BorderRadius::all(radius.x), true),
2854                    (UiRect::right(width), BorderRadius::right(radius), false),
2855                    (UiRect::ZERO, BorderRadius::top_right(radius), true),
2856                    (UiRect::bottom(width), BorderRadius::bottom(radius), false),
2857                    (UiRect::ZERO, BorderRadius::top_left(radius), true),
2858                ] {
2859                    builder
2860                        .spawn((
2861                            Node {
2862                                width: px(200.),
2863                                height: px(200.),
2864                                border_radius,
2865                                border,
2866                                ..default()
2867                            },
2868                            BorderColor::all(bevy::color::palettes::css::RED),
2869                        ))
2870                        .insert_if(BackgroundColor(Color::WHITE), || !invert)
2871                        .insert_if(OuterColor(Color::WHITE), || invert);
2872                }
2873            });
2874    }
Source

pub fn bottom(radius: impl Into<CornerRadius>) -> BorderRadius

Sets the radii for the bottom left and bottom right corners. Remaining corners will be right-angled.

Examples found in repository?
examples/testbed/ui.rs (line 2856)
2831    pub fn setup(mut commands: Commands) {
2832        let radius = CornerRadius::from(percent(33.));
2833        let width = px(10.);
2834
2835        commands.spawn((Camera2d, DespawnOnExit(super::Scene::OuterColor)));
2836        commands
2837            .spawn((
2838                Node {
2839                    display: Display::Grid,
2840                    grid_template_columns: RepeatedGridTrack::px(3, 200.),
2841                    grid_template_rows: RepeatedGridTrack::px(3, 200.),
2842                    margin: UiRect::AUTO,
2843                    ..default()
2844                },
2845                DespawnOnExit(super::Scene::OuterColor),
2846            ))
2847            .with_children(|builder| {
2848                for (border, border_radius, invert) in [
2849                    (UiRect::ZERO, BorderRadius::bottom_right(radius), true),
2850                    (UiRect::top(width), BorderRadius::top(radius), false),
2851                    (UiRect::ZERO, BorderRadius::bottom_left(radius), true),
2852                    (UiRect::left(width), BorderRadius::left(radius), false),
2853                    (UiRect::all(width), BorderRadius::all(radius.x), true),
2854                    (UiRect::right(width), BorderRadius::right(radius), false),
2855                    (UiRect::ZERO, BorderRadius::top_right(radius), true),
2856                    (UiRect::bottom(width), BorderRadius::bottom(radius), false),
2857                    (UiRect::ZERO, BorderRadius::top_left(radius), true),
2858                ] {
2859                    builder
2860                        .spawn((
2861                            Node {
2862                                width: px(200.),
2863                                height: px(200.),
2864                                border_radius,
2865                                border,
2866                                ..default()
2867                            },
2868                            BorderColor::all(bevy::color::palettes::css::RED),
2869                        ))
2870                        .insert_if(BackgroundColor(Color::WHITE), || !invert)
2871                        .insert_if(OuterColor(Color::WHITE), || invert);
2872                }
2873            });
2874    }
Source

pub fn with_top_left(self, radius: impl Into<CornerRadius>) -> BorderRadius

Returns the BorderRadius with its top_left field set to the given value.

Source

pub fn with_top_right(self, radius: impl Into<CornerRadius>) -> BorderRadius

Returns the BorderRadius with its top_right field set to the given value.

Source

pub fn with_bottom_right(self, radius: impl Into<CornerRadius>) -> BorderRadius

Returns the BorderRadius with its bottom_right field set to the given value.

Source

pub fn with_bottom_left(self, radius: impl Into<CornerRadius>) -> BorderRadius

Returns the BorderRadius with its bottom_left field set to the given value.

Source

pub fn with_left(self, radius: impl Into<CornerRadius>) -> BorderRadius

Returns the BorderRadius with its top_left and bottom_left fields set to the given value.

Source

pub fn with_right(self, radius: impl Into<CornerRadius>) -> BorderRadius

Returns the BorderRadius with its top_right and bottom_right fields set to the given value.

Source

pub fn with_top(self, radius: impl Into<CornerRadius>) -> BorderRadius

Returns the BorderRadius with its top_left and top_right fields set to the given value.

Source

pub fn with_bottom(self, radius: impl Into<CornerRadius>) -> BorderRadius

Returns the BorderRadius with its bottom_left and bottom_right fields set to the given value.

Source

pub fn resolve( &self, scale_factor: f32, node_size: Vec2, viewport_size: Vec2, em_size: EmSize, rem_size: RemSize, ) -> ResolvedBorderRadius

Resolve the border radii for the corners from the given context values. Returns the radii of the each corner in physical pixels.

Trait Implementations§

Source§

impl Clone for BorderRadius

Source§

fn clone(&self) -> BorderRadius

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for BorderRadius

Source§

impl Debug for BorderRadius

Source§

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

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

impl Default for BorderRadius

Source§

fn default() -> BorderRadius

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

impl<'de> Deserialize<'de> for BorderRadius

Source§

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

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

impl<T> From<T> for BorderRadius
where T: Into<CornerRadius>,

Source§

fn from(value: T) -> BorderRadius

Converts to this type from the input type.
Source§

impl FromArg for BorderRadius

Source§

type This<'from_arg> = BorderRadius

The type to convert into. Read more
Source§

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

Creates an item from an argument. Read more
Source§

impl FromReflect for BorderRadius

Source§

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

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 BorderRadius

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetTypeRegistration for BorderRadius

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 BorderRadius

Source§

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

Converts Self into a Return value.
Source§

impl PartialEq for BorderRadius

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialReflect for BorderRadius

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<BorderRadius>) -> ReflectOwned

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

fn try_into_reflect( self: Box<BorderRadius>, ) -> 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<BorderRadius>) -> 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 reflect_partial_cmp( &self, value: &(dyn PartialReflect + 'static), ) -> Option<Ordering>

Returns a “partial 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 to_dynamic(&self) -> Result<Box<dyn PartialReflect>, ReflectCloneError>

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

fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
where T: 'static, Self: Sized + TypePath,

For a type implementing PartialReflect, combines reflect_clone and take in a useful fashion, automatically constructing an appropriate ReflectCloneError if the downcast fails.
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 BorderRadius

Source§

fn into_any(self: Box<BorderRadius>) -> 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<BorderRadius>) -> 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 BorderRadius

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 BorderRadius

Source§

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

Gets 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)>

Gets 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)>

Gets 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)>

Gets 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>

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

fn index_of_name(&self, name: &str) -> Option<usize>

Gets the index of the field with the given name.
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) -> Result<DynamicStruct, ReflectCloneError>

Creates a new DynamicStruct from this struct. Read more
Source§

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

Will return None if TypeInfo is not available.
Source§

impl StructuralPartialEq for BorderRadius

Source§

impl TypePath for BorderRadius

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 BorderRadius

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.

Auto Trait Implementations§

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> Brush for T
where T: Clone + PartialEq + Default + Debug,

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> ConditionalSend for T
where T: Send,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

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

Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> FromTemplate for T
where T: Clone + Default + Unpin,

Source§

type Template = T

The Template for this type.
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,

Gets 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,

Gets 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, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> HitDataExtra for T
where T: Send + Sync + Debug + Any + 'static,

Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
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<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

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

Source§

fn into_sample(self) -> T

Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

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

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<G> PatchFromTemplate for G
where G: FromTemplate,

Source§

type Template = <G as FromTemplate>::Template

The Template that will be patched.
Source§

fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
where F: FnOnce(&mut <G as PatchFromTemplate>::Template, &mut ResolveContext<'_>),

Takes a “patch function” func, and turns it into a TemplatePatch.
Source§

impl<T> PatchTemplate for T
where T: Template,

Source§

fn patch_template<F>(func: F) -> TemplatePatch<F, T>
where F: FnOnce(&mut T, &mut ResolveContext<'_>),

Takes a “patch function” func that patches this Template, and turns it into a TemplatePatch.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> Reflectable for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> Settings for T
where T: 'static + Send + Sync,

Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
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> Template for T
where T: Clone + Unpin,

Source§

type Output = T

The type of value produced by this Template.
Source§

fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>

Uses this template and the given entity context to produce a Template::Output.
Source§

fn clone_template(&self) -> T

Clones this template. See Clone.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of self.
Source§

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

Source§

fn vzip(self) -> V

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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

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