mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
TextEdit Atom prefix/suffix (#7587)
* part of https://github.com/emilk/egui/issues/7264 * part of https://github.com/emilk/egui/issues/7445 This PR changes the layout within the TextEdit to be done with AtomLayout. It also adds a Prefix and Postfix that allows adding permanent icons / icon buttons within the textedit. Breaking changes: - Removed `TextEdit::hint_text_font`. Hint text is an atom now, so the font can be set that way <img width="264" height="130" alt="Screenshot 2025-10-06 at 12 25 21" src="https://github.com/user-attachments/assets/03b6b56b-ca82-4ac3-b5c0-585cca336834" /> --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com> Co-authored-by: lucasmerlin <8009393+lucasmerlin@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use egui::accesskit::Role;
|
||||
use egui::epaint::Shape;
|
||||
use egui::{Align, Color32, Image, Label, Layout, RichText, Sense, TextWrapMode, include_image};
|
||||
use egui::style::ScrollAnimation;
|
||||
use egui::{
|
||||
Align, Color32, Image, Label, Layout, RichText, ScrollArea, Sense, TextWrapMode, include_image,
|
||||
};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable as _;
|
||||
|
||||
@@ -63,6 +66,67 @@ fn text_edit_rtl() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_edit_delay() {
|
||||
let mut text = String::new();
|
||||
let mut harness = Harness::builder().with_size((200.0, 50.0)).build_ui(|ui| {
|
||||
ui.style_mut().scroll_animation = ScrollAnimation::none();
|
||||
ui.add(egui::TextEdit::singleline(&mut text).hint_text("Write something"));
|
||||
});
|
||||
|
||||
harness.get_by_role(Role::TextInput).focus();
|
||||
harness.step();
|
||||
harness.snapshot("text_edit_delay_0_empty");
|
||||
|
||||
harness.get_by_role(Role::TextInput).type_text("h");
|
||||
|
||||
// When the text is empty, and we show the hint text, there is a frame delay.
|
||||
harness.step();
|
||||
harness.snapshot("text_edit_delay_1_h_invisible");
|
||||
|
||||
// Now it should be visible
|
||||
harness.step();
|
||||
harness.snapshot("text_edit_delay_2_h_visible");
|
||||
|
||||
harness.get_by_role(Role::TextInput).type_text("i");
|
||||
|
||||
// The "i" should immediately be visible without a delay
|
||||
harness.step();
|
||||
harness.snapshot("text_edit_delay_3_i_visible");
|
||||
|
||||
// The next frame should exactly match the previous one
|
||||
harness.step();
|
||||
harness.snapshot("text_edit_delay_4_i_visible");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_edit_scroll() {
|
||||
let mut text = "1\n2\n3\n4\n".to_owned();
|
||||
let mut harness = Harness::builder().build_ui(|ui| {
|
||||
ScrollArea::vertical().max_height(40.0).show(ui, |ui| {
|
||||
ui.add(
|
||||
egui::TextEdit::multiline(&mut text)
|
||||
.desired_rows(2)
|
||||
.hint_text("Write something"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
harness.fit_contents();
|
||||
|
||||
harness.get_by_role(Role::MultilineTextInput).focus();
|
||||
harness.step();
|
||||
harness.snapshot("text_edit_scroll_0_focus");
|
||||
|
||||
harness
|
||||
.get_by_role(Role::MultilineTextInput)
|
||||
.type_text("5\n");
|
||||
|
||||
// When the text is empty, and we show the hint text, there is a frame delay.
|
||||
harness.run();
|
||||
harness.snapshot("text_edit_scroll_1_5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn combobox_should_have_value() {
|
||||
let harness = Harness::new_ui(|ui| {
|
||||
|
||||
Reference in New Issue
Block a user