Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ui root node is not sized properly with custom UiCamera's projection #2405

Open
Daniikk1012 opened this issue Jun 27, 2021 · 5 comments
Open
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@Daniikk1012
Copy link
Contributor

Bevy version

0.5

Operating system & version

Tested on Linux, but probably affects all other systems

What you did

I have this system that resizes for all the cameras with OrthographicsProjection and CameraAspectRatio compoents:

pub enum CameraAspectRatio {                                                      
    Auto {                                                                        
        min_width: f32,                                                           
        min_height: f32,                                                          
    },                                                                            
    FixedWidth(f32),                                                              
    FixedHeight(f32),                                                             
}

pub fn camera_aspect_ratio(                                                      
    windows: Res<Windows>,                                                       
    mut query:                                                                    
        Query<(&mut OrthographicProjection, &Camera, &CameraAspectRatio)>,        
) {                                                                               
    for (mut projection, camera, ratio) in query.iter_mut() {                     
        if let (ScalingMode::None, Some(window)) =                                
            (&projection.scaling_mode, windows.get(camera.window))                
        {                                                                         
            let window_size = Vec2::new(window.width(), window.height());         
                                                                                  
            let size = match *ratio {                                             
                CameraAspectRatio::Auto { min_width, min_height } => if           
                    window_size.x / window_size.y > min_width / min_height        
                {                                                                
                    Vec2::new(                                                    
                        min_height * window_size.x / window_size.y,               
                        min_height,                                               
                    )                                                             
                } else {                                                          
                    Vec2::new(                                                    
                        min_width, min_width * window_size.y / window_size.x,    
                    )                                                             
                },                                                                
                CameraAspectRatio::FixedWidth(width) => Vec2::new(                
                    width,                                                        
                    width * window_size.y / window_size.x,                        
                ),                                                                
                CameraAspectRatio::FixedHeight(height) => Vec2::new(              
                    height * window_size.x / window_size.y,                       
                    height,                                                       
                ),                                                                
            };                                                                   
                                                                                 
            match projection.window_origin {                                     
                WindowOrigin::Center => {                                        
                    projection.left = -size.x / 2.0;                             
                    projection.right = size.x / 2.0;                             
                                                                                 
                    projection.bottom = -size.y / 2.0;                           
                    projection.top = size.y / 2.0;                               
                },                                                               
                WindowOrigin::BottomLeft => {                                    
                    projection.left = 0.0;                                       
                    projection.right = size.x;                                   
                                                                                 
                    projection.bottom = 0.0;                                     
                    projection.top = size.y;                                     
                },                                                               
            }                                                                    
        }                                                                        
    }                                                                            
}

The system works fine and the game itself displays correctly. However when I try to create a root node with size set to 100% by 100% it does not fill the whole window, but instead its virtual size gets limited to the value of the real screen size:

    commands                                                                      
        .spawn_bundle(NodeBundle {                                                
            material: materials.add(Color::rgba(1.0, 1.0, 1.0, 0.5).into()),      
            style: Style {                                                        
                size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),        
                flex_direction: FlexDirection::Row,                               
                align_items: AlignItems::FlexEnd,                                 
                justify_content: JustifyContent::SpaceBetween,                    
                ..Default::default()                                              
            },                                                                    
            ..Default::default()                                                  
        })

изображение

What you expected to happen

The root node should fill the whole window.

What actually happened

The root node's size was limited to the window's logical size and was not enough to fill the virtual camera size (1920 by 1080)

@Daniikk1012 Daniikk1012 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jun 27, 2021
@Daniikk1012
Copy link
Contributor Author

As a workaround I can set position_type to Absolute and create a separate system for manually resizing the root node using Px values

@NathanSWard NathanSWard added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Jun 27, 2021
@nicopap
Copy link
Contributor

nicopap commented Jul 7, 2022

This is irrelevant since #4745 Since it made it impossible to set custom projection for UI cameras.

It also did a lot of changes to aspect ratio handling. So maybe even if custom UI projection were added back it would be fixed?

@Daniikk1012
Copy link
Contributor Author

I should probably rephrase the issue. It is not technically a custom projection, but a custom scaling mode for OrthographicProjection. And when it is not set to ScalingMode::Window, it behaves not as expected

@nicopap
Copy link
Contributor

nicopap commented Jul 7, 2022

It is not technically a custom projection, but a custom scaling mode for OrthographicProjection.

I understand, but it is impossible currently to access the OrthographicProjection used by the UI camera. It is hardcoded in the extract_default_ui_camera_view system. You can't access it in the app world, and I'm not sure if it's even possible to modify it in the render world with a system.

@nicopap
Copy link
Contributor

nicopap commented Jul 7, 2022

If you want the ability to directly edit the OrthograpicProjection, please discuss this in #5243 and #5242. I think a review from someone who would actually use the PR change would be very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

3 participants