1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-03 15:20:05 -04:00

Fix text selection of centered and right-aligned text (#8076)

* Fixes https://github.com/emilk/egui/issues/8049
* Bug introduced in https://github.com/emilk/egui/pull/7831
This commit is contained in:
Emil Ernerfeldt
2026-04-07 13:29:57 +02:00
committed by GitHub
parent 74b9970a9f
commit 1fdc5c0775
6 changed files with 48 additions and 20 deletions

View File

@@ -62,21 +62,25 @@ fn test_italics() {
fn test_text_selection() {
let mut results = egui_kittest::SnapshotResults::new();
for (test_idx, drag_start_x) in [0.2_f32, 0.9].into_iter().enumerate() {
let mut harness = Harness::builder().build_ui(|ui| {
let visuals = ui.visuals_mut();
visuals.selection.bg_fill = Color32::LIGHT_GREEN;
visuals.selection.stroke.color = Color32::RED;
for (test_idx, drag_start_x) in [0.2_f32, 0.95].into_iter().enumerate() {
let mut harness = Harness::builder()
.with_pixels_per_point(1.0) // TODO(emilk): why does this test fail with 2.0?
.build_ui(|ui| {
let visuals = ui.visuals_mut();
visuals.selection.bg_fill = Color32::LIGHT_GREEN;
visuals.selection.stroke.color = Color32::RED;
ui.label("Some varied ☺ text :)\nAnd it has a second line!");
});
ui.vertical_centered(|ui| {
ui.label("Some varied ☺ text :)\nAnd it has a second line!\nAnd a third!");
});
});
harness.run();
harness.fit_contents();
// Drag to select text:
let label = harness.get_by_role(Role::Label);
harness.drag_at(label.rect().lerp_inside([drag_start_x, 0.25]));
harness.drop_at(label.rect().lerp_inside([0.6, 0.75]));
harness.drop_at(label.rect().lerp_inside([0.5, 0.75]));
harness.run();
harness.snapshot(format!("text_selection_{test_idx}"));

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4c47faa75a002577220a92efceab5c0ccee1ddaa17c2d2f3d6d1429dbf8fe718
size 60887
oid sha256:661570ed4bdf24d52ab049e7d3cf22ef4d50542ee5486d133e0a618a6146da42
size 98582

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ce1e16fa09588ec5351d031408657137f42ff40eb7cf6dd00b8c65a4f51ec680
size 5332
oid sha256:d7d8578b55ed8fdaf2062cb53d7320555e490289ff9efb30f39ebb697d2e252e
size 6529

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:79676693e9f1804c7e0a32ffa9bec3bde281446ffc184b55a1a3fcf34074ac34
size 5304
oid sha256:5e09ec77bd473ad6695557b78d4967ade09b12100f04bc66d0e29779dfb0d551
size 6495