Skip to content

OverflowAxis::Clip allows UI node contents to spill over the border #15335

@Piefayth

Description

@Piefayth

Bevy version

main

Description

Oversized children of UI nodes are getting clipped at the outer edge of the border, not the inner one. Consider the dark grey child in the below image; it should not cross the red border of its parent.

image

This is not consistent with the behavior on web...

image

Seems wrong?

Reproduction

use bevy::{
    color::palettes::{css::{DARK_GREEN, RED}, tailwind::CYAN_400},
    prelude::*,
    winit::WinitSettings,
};

fn main() {
    let mut app = App::new();
    app.add_plugins(DefaultPlugins)
        .insert_resource(WinitSettings::desktop_app())
        .add_systems(Startup, setup);

    app.run();
}

fn setup(mut commands: Commands) {
    commands.spawn((Camera2dBundle::default(), IsDefaultUiCamera));

    commands
        .spawn(NodeBundle {
            style: Style {
                width: Val::Percent(100.0),
                height: Val::Percent(100.0),
                justify_content: JustifyContent::Center,
                flex_direction: FlexDirection::Column,
                ..default()
            },
            ..default()
        }).with_children(|parent| {
            parent
                .spawn(NodeBundle {
                    style: Style {
                        width: Val::Percent(50.),
                        height: Val::Px(100.),
                        border: UiRect::all(Val::Px(5.)),
                        flex_direction: FlexDirection::Column,
                        overflow: Overflow::clip(),
                        ..default()
                    },
                    background_color: DARK_GREEN.into(),
                    border_color: RED.into(),
                    ..default()
                }).with_children(|parent| {
                    parent
                        .spawn(NodeBundle {
                            style: Style {
                                width: Val::Px(8000.),
                                height: Val::Px(50.),
                                ..default()
                            },
                            background_color: Color::srgb(0.15, 0.15, 0.15).into(),
                            border_color: CYAN_400.into(),
                            ..default()
                        });
                });
        });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions