mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -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| {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:30de3e9f9645206e33fa1edd841b48228e154d0ceae962c64c060a66eecd73ba
|
||||
size 220452
|
||||
oid sha256:29363b37f1260f9f39edf9ba873f4c33c0d8a8b6670f6fc178459019539ae7e3
|
||||
size 220588
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a9f36b8623d2d9c35e337e973f547166f62a5daae757c462b1482babdd42c941
|
||||
size 383051
|
||||
oid sha256:94186c0b9331fd0d13284126f4f5e92e66014105fb6533422516d4fbe765e4c7
|
||||
size 372041
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:1a2734644b2fbb6f42ddab6c65a1f5d073f1f002900bbd814c1edb6184e0a9c0
|
||||
size 362521
|
||||
oid sha256:8ff058ef716689c309ae9806aaf08fb64eca545ef8f92ce89e1f8e9b7b7733bc
|
||||
size 330200
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:cf00e99dbfdf7497688955feb8c417fab0a366588d92182eccee775abade5179
|
||||
size 361876
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:cf62a248bcec1054cbd97251e6fc429972ef2318c24b9a56698d7c80115aa57e
|
||||
size 2262
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ef70c95f7e171984f992e1b9366b4a0fe11a4871746cb8cfaa8ee263e59de702
|
||||
size 2272
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ab120260212d0f41d2956ea2d679cfed648cb188badcca7fa82e0dec9c87ec1a
|
||||
size 714
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c2ea9d6bef26f1dbd7dc272b4331012ad6fd1a43fded150d33ba4762d404dbde
|
||||
size 775
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c2ea9d6bef26f1dbd7dc272b4331012ad6fd1a43fded150d33ba4762d404dbde
|
||||
size 775
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ce357224c2e1cf32f96b3d075dc070c4d14e9aaca1b8165d0ba98603dff19c1b
|
||||
size 2324
|
||||
oid sha256:ed3665dfb232b8f0b1483802bfafb4605e8361d7eb977de5a58862e52ab724fa
|
||||
size 2296
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:d91c715ac66be329cac42ff7c7726348b0ac79d897c414bbde26bb0115781577
|
||||
size 2289
|
||||
oid sha256:5cfdd6255aba92f0253571bde4f22afc8e0fb5fe3cb882946459d623c0a5d89c
|
||||
size 2982
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:81620caad6d420f3bd0f224e5b07a02960a42436208a98d3aa012e5db61a743a
|
||||
size 1510
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f915eafb6490ff456c5b0a7c74c38ef143262bdf74a0c6561b9cf6ee66a679ea
|
||||
size 1501
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:71daf8a33d277075012bf1130d7820574fe0286080154810d8d398c005a65127
|
||||
size 9037
|
||||
oid sha256:60ad2d88535977244ac0fa153700489b454a582af2829dc2f41a531943a21d7a
|
||||
size 9079
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:8d259d113aa23089992b04f19e71c743272dda3fc9baa9612565158f15ace57e
|
||||
size 8159
|
||||
oid sha256:7e1fb3fb0a00a447906aa205c27aa496dcb3d79e98aadf6092811a0514efb5a0
|
||||
size 8127
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a1e56f1b6970c14830d8869f4d8cacfed821ec2b3aab7033b1bfd213a864da79
|
||||
size 10959
|
||||
oid sha256:077e7de9fdaaa222ee75f6ad620967fb1e29da37f60407d584be7141e9d0badd
|
||||
size 10143
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:493649ea09351835147aa6cc800858939dd44beafe37adc488b63b291d58e3b3
|
||||
size 10302
|
||||
oid sha256:b022e27d7275764df45039abd26f80d69af40fb18bec98cca85565850df859ae
|
||||
size 8838
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:337dcbf0b3a344c6cadaf9500376a627739e19e9c47b5da23786c98c612ef4dc
|
||||
size 10028
|
||||
@@ -122,6 +122,18 @@ fn widget_tests() {
|
||||
},
|
||||
&mut results,
|
||||
);
|
||||
test_widget(
|
||||
"text_edit_prefix_suffix",
|
||||
|ui| {
|
||||
ui.spacing_mut().text_edit_width = 45.0;
|
||||
TextEdit::singleline(&mut "Hello World".to_owned())
|
||||
.prefix("🔎")
|
||||
.suffix("!")
|
||||
.clip_text(true)
|
||||
.ui(ui)
|
||||
},
|
||||
&mut results,
|
||||
);
|
||||
|
||||
test_widget(
|
||||
"slider",
|
||||
|
||||
Reference in New Issue
Block a user