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

Console window infinitely expands downwards #21

Open
cebarks opened this issue Jun 21, 2022 · 8 comments
Open

Console window infinitely expands downwards #21

cebarks opened this issue Jun 21, 2022 · 8 comments

Comments

@cebarks
Copy link

cebarks commented Jun 21, 2022

When the console key is pressed, and the console window is shown, it constantly expands downwards until it hits the bottom of the window. When it does, it starts expanding from the top until it fills the screen. Once it fills the screen, it starts expanding from the bottom again off screen and never stops. I have about as bare bones of a project as you can have so unsure but doubtful its something unique to my usecase.

@brandon-reinhart
Copy link
Collaborator

I couldn't repro this, but am curious if you are still having the problem.

@cebarks
Copy link
Author

cebarks commented Aug 11, 2022

Just checked and I am. It seems to only be occurring when the window is on my 4k monitor with 125% scaling, but not the 4k at 200% scaling, so maybe something to do with dpi?

@makspll
Copy link
Collaborator

makspll commented Aug 11, 2022

Hi @cebarks, could you please provide a small code example + steps for reproducing this issue?

@cebarks
Copy link
Author

cebarks commented Aug 11, 2022

Here's the code. The only thing required to reproduce this is to open this app on a 4k screen with scaling that ends in 25% (mine is set to 125%, but 175% also causes this to happen.) Switching scaling to a multiple of 50% stops it from happening.

use bevy::render::camera::ScalingMode;
use bevy::window::{PresentMode, WindowMode};
use bevy_console::{ConsoleConfiguration, ConsolePlugin};

pub const A_RATIO: f32 = 16.0 / 9.0;

fn main() {
    App::new()
        .insert_resource(get_window_desc())
        .insert_resource(ClearColor(Color::PURPLE))
        .add_plugins(DefaultPlugins)
        .add_plugin(ConsolePlugin)
        .insert_resource(ConsoleConfiguration {
            height: 200.0,
            ..Default::default()
        })
        .add_startup_system(spawn_camera)
        .run();
    println!("Exiting.");
}

fn get_window_desc() -> WindowDescriptor {
    return WindowDescriptor{
        title: "ConsoleTest".to_string(),
        width: 1600.0,
        height: 900.0,
        present_mode: PresentMode::Fifo,
        mode: WindowMode::Windowed,
        resizable: true,
        ..Default::default()
    }; 
}

fn spawn_camera(mut commands: Commands) {
    let mut camera = OrthographicCameraBundle::new_2d();

    camera.orthographic_projection.top = 1.0;
    camera.orthographic_projection.bottom = -1.0;

    camera.orthographic_projection.right = 1.0 * A_RATIO;
    camera.orthographic_projection.left = -1.0 * A_RATIO;

    camera.orthographic_projection.scaling_mode = ScalingMode::None;

    commands.spawn_bundle(camera);
    println!("Camera spawned.")
}

@Flapperkewiet
Copy link

I had the same issue on a 2k (1440p) monitor with 125% scaling in windows settings.

I was able to fix it by editing :

let scroll_height = ui.available_height() - 30.0;

from

let scroll_height = ui.available_height() - 30.0;

to

let scroll_height = ui.available_height() - 32.0;

@cebarks
Copy link
Author

cebarks commented Jan 24, 2023

@makspll is the above enough to get this fixed? I can prepare a pull request too if with the change highlighted by @Flapperkewiet if that would help.

@makspll
Copy link
Collaborator

makspll commented Jan 28, 2023

I am not sure what the cause of this issue is, but if this change fixes it it might be to do with the way floating point is handled. If you can reproduce the issue and this fix works then I am happy to accept PR's for it although I would love to know why exactly this happens ideally!

@dimvoly
Copy link

dimvoly commented Oct 23, 2023

I'm getting this issue too. I believe the problem is that console.rs uses ui.vertical() which puts the widgets in from top to bottom. Since the one that grows in size is the scroll area, you can put the widgets in bottom to top instead:

{
                // ui.vertical(|ui| {
                    // let scroll_height = ui.available_height() - 30.0;
                ui.with_layout(egui::Layout::bottom_up(egui::Align::Min), |ui| {
                    // Input
                    let text_edit = TextEdit::singleline(&mut state.buf)
                        .desired_width(f32::INFINITY)
                        .font(egui::TextStyle::Monospace);
                    let text_edit_response = ui.add(text_edit);

                    // Separator
                    ui.separator();

                    // Scroll area
                    ScrollArea::vertical()
                        .auto_shrink([false, false])
                        .stick_to_bottom(true)
                        // .max_height(scroll_height)
                        .show(ui, |ui| {

This way you don't need to pre-calculate the pixels for the available height. This also stops the large jump that happens to window size when you go to resize it using the grip on the bottom-right corner. Related talk here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants