bevy-console
bevy-console copied to clipboard
Console window infinitely expands downwards
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.
I couldn't repro this, but am curious if you are still having the problem.
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?
Hi @cebarks, could you please provide a small code example + steps for reproducing this issue?
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.")
}
I had the same issue on a 2k (1440p) monitor with 125% scaling in windows settings.
I was able to fix it by editing : https://github.com/RichoDemus/bevy-console/blob/fa09da33ee752facc8eb3b2ba93682005d179624/src/console.rs#L545
from
let scroll_height = ui.available_height() - 30.0;
to
let scroll_height = ui.available_height() - 32.0;
@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.
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!
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.