Skip to content

UI Node children overflow with BorderRadius #21449

@mirsella

Description

@mirsella

Bevy version and features

0.17.2

What you did

spawn a parent node with a BorderRadius and Overflow::hidden or clip. the child sides are still shown outside the parent node sides.

What you expected

the child red node borders would be clipped since its parent has overflow hidden, so that none of the child goes outside o the parent

use bevy::{color::palettes::css, prelude::*};

fn main() -> AppExit {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup_ui)
        .run()
}

fn setup_ui(mut commands: Commands) {
    commands.spawn(Camera2d);

    commands.spawn((
        Node {
            width: Val::Percent(100.0),
            height: Val::Percent(100.0),
            display: Display::Flex,
            justify_content: JustifyContent::Center,
            align_items: AlignItems::Center,
            ..default()
        },
        children![(
            Node {
                width: Val::Percent(50.),
                height: Val::Percent(50.),
                overflow: Overflow::hidden(),
                ..default()
            },
            BackgroundColor(Color::WHITE),
            BorderRadius::all(Val::Percent(25.0)),
            children![(
                Node {
                    width: Val::Percent(100.0),
                    height: Val::Percent(100.0),
                    ..default()
                },
                BackgroundColor(css::RED.with_alpha(0.5).into()),
            )]
        )],
    ));
}
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenA-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions