Skip to content

Style.overflow not hidding overflowed nodes #8016

@doup

Description

@doup

Bevy version

What you did

Given

  • Columns: grey node containers
  • Children: orange nodes, which are children of the columns

I set it up like:

  • Rework example in UI text wrapping and LineBreakOn example #7761 to use gap/padding to control spacing between columns.
  • This removes explicit width for columns, and leverages width: Val::Auto, flex_grow: 1.0 & flex_basis: Val::Px(0.), which is a way of splitting columns in equal widths with flex.
  • The columns have Overflow::hidden set.
  • The children have a fixed width.

Example code

Reproduction code
use bevy::prelude::*;
use bevy::winit::WinitSettings;

fn main() {
  App::new()
      .add_plugins(DefaultPlugins)
      .insert_resource(WinitSettings::desktop_app())
      .add_startup_system(spawn)
      .run();
}

fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
  commands.spawn(Camera2dBundle::default());

  let gap = Val::Px(8.0);

  commands
      .spawn(NodeBundle {
          style: Style {
              flex_direction: FlexDirection::Column,
              size: Size::new(Val::Percent(100.), Val::Percent(100.)),
              gap: Size::all(gap),
              padding: UiRect::all(gap),
              ..Default::default()
          },
          background_color: Color::BLACK.into(),
          ..Default::default()
      })
      .with_children(|parent| {
          for _ in 0..2 {
              parent
                  .spawn(NodeBundle {
                      style: Style {
                          size: Size::new(Val::Percent(100.0), Val::Percent(50.)),
                          gap: Size::all(gap),
                          ..default()
                      },
                      ..default()
                  })
                  .with_children(|parent| {
                      for _ in 0..5 {
                          parent
                              .spawn(NodeBundle {
                                  style: Style {
                                      size: Size::new(Val::Auto, Val::Percent(100.)),
                                      overflow: Overflow::Hidden, // <====
                                      flex_grow: 1.0,
                                      flex_basis: Val::Px(0.),
                                      ..default()
                                  },
                                  background_color: Color::GRAY.into(),
                                  ..default()
                              })
                              .with_children(|parent| {
                                  parent.spawn(NodeBundle {
                                      style: Style {
                                          size: Size::new(Val::Px(150.0), Val::Px(30.0)),
                                          ..default()
                                      },
                                      background_color: Color::ORANGE.into(),
                                      ..default()
                                  });
                              });
                      }
                  });
          }
      });
}

What went wrong

When the columns width is bigger than the children width, then everything is OK:

image

If the window width is changed, columns shrink. When column width is smaller than the children width, it should overflow. Instead the column width equals the children width. Columns get pushed off-screen.

NOTE: Here we should see 5 narrow columns.

image

Additional information

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions