UI text jumps up and down at every key

Abierto Apto para principiantes
#26,718 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

Empieza en scroll.rs, en TextViewport::reveal_caret, y sigue las ramas que se usan cuando una línea de texto es más alta que el área del cursor. Reproduce el problema con el ejemplo de Bevy 0.20.1 del issue y observa viewport.offset.y mientras escribes o mueves el cursor. El trabajo estará terminado cuando el offset permanezca centrado para una línea demasiado alta, en lugar de alternar entre 0 y 2.4.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

C-Bug S-Needs-Triage

Bevy version and features

0.20.1. Main is still affected: its scroll.rs last changed in c1b48d6, the #25948 fix.

#25305 ("Text in EditText bounces up and down for every change"), closed by #25948. That fix only adds a 0.001 tolerance, so it helps only when the line is less than 0.002 px taller than the box.

Relevant system information

Windows 10 Pro 19045, RTX 5080, Vulkan.

What you did

Run the app below, then type into the field or move the caret with the arrow keys.

The app (Bevy 0.20.1, default features)

use bevy::input_focus::AutoFocus;
use bevy::prelude::*;
use bevy::text::{EditableText, TextCursorStyle};
use bevy::ui_widgets::TextInput;

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

fn setup(mut commands: Commands) {
    commands.spawn(Camera2d);
    commands.spawn((
        Node {
            width: px(320),
            height: px(40),
            padding: UiRect::axes(px(10), px(6)),
            border: px(2).all(),
            margin: auto().all(),
            ..default()
        },
        BorderColor::from(Color::WHITE),
        TextInput,
        EditableText::new("Bevy"),
        TextFont {
            font_size: FontSize::Px(22.0),
            ..default()
        },
        TextCursorStyle::default(),
        AutoFocus,
    ));
}

fn log_offset(inputs: Query<&EditableText, Changed<EditableText>>) {
    for input in &inputs {
        info!("viewport.offset.y = {}", input.viewport.offset.y);
    }
}

What went wrong

The text jumps up and down at every key. The viewport.offset.y log shows 2.4, 0, 2.4, 0.

Additional information

Why it's happaing

  • The field's box inside the padding and border is 24 px high, and the 22 px font's line is 26.4 px.
  • In TextViewport::reveal_caret, a line taller than the caret area gets centered, at 1.2.
  • The next branch then snaps: back to the line's start (0) when the center is above the current offset, or to the bottom (2.4) when it's below, since there's no next line.
  • Each reveal therefore flips the offset.

A possible fix direction: when the line is taller than the caret area, keep the centered offset instead of snapping to a line.

Lenguaje dominante
Rust
Estrellas
50k
Forks
5.1k
Merge medio
2 d 20 h
PR fusionados (30 d)
129

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bevyengine/bevy

Todos los issues de bevyengine/bevy

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.