Skip to content

Disappearing space in the layout with intrinsically sized UI nodes #8516

@ickshonpe

Description

@ickshonpe

Bevy version

Main ee697f8

What you did

use bevy::prelude::*;
use bevy::ui::AvailableSpace;
use bevy::ui::CalculatedSize;
use bevy::ui::Measure;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

#[derive(Clone)]
pub struct TestMeasure;

impl Measure for TestMeasure {
    fn measure(
        &self,
        _: Option<f32>,
        _: Option<f32>,
        _: AvailableSpace,
        _: AvailableSpace,
    ) -> Vec2 {
        Vec2::new(500., 0.)
    }

    fn dyn_clone(&self) -> Box<dyn Measure> {
        Box::new(self.clone())
    }
}


fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
        commands.spawn((NodeBundle {
            style: Style {
                max_size: Size::width(Val::Px(0.)),
                ..Default::default()
            },
            background_color: Color::GREEN.into(),
            ..default()
        },
        CalculatedSize { measure: Box::new(TestMeasure) }
    ));
    commands.spawn(NodeBundle {
        style: Style {
            size: Size::width(Val::Percent(100.)),
            ..Default::default()
        },
        background_color: Color::RED.into(),
        ..Default::default()
    });
}

What went wrong

Capture-size

The green NodeBundle with the calculated size has a max-width constraint of 0., so it takes up no space in the layout as expected. But the red NodeBundle doesn't grow to fill 100% of the width of the window and leaves an empty space.

Additional Information

Looked obviously like it must be a bug in Taffy, but couldn't reproduce it. Instead, it was definitely introduced by #7779 but I'm not sure how as #7779 doesn't modify any of the layout calculations except for changing how scale factor is applied, but this doesn't seem like a scale factor related bug.

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