mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Change text color of selected text (#7691)
Selected text now gets the color of `visuals.selection.stroke.color`. This means you can have inverted colors for selected text, like in the new test: <img width="154" height="46" alt="image" src="https://github.com/user-attachments/assets/2666361d-d7e2-4d50-8e4d-2fcc128f1a81" /> It also means the color of selected text in labels matches that of the text color of selected buttons.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use egui_kittest::Harness;
|
||||
use egui::{Color32, accesskit::Role};
|
||||
use egui_kittest::{Harness, kittest::Queryable as _};
|
||||
|
||||
#[test]
|
||||
fn test_kerning() {
|
||||
@@ -42,7 +43,7 @@ fn test_italics() {
|
||||
harness.run();
|
||||
harness.fit_contents();
|
||||
harness.snapshot(format!(
|
||||
"image_blending/image_{theme}_x{pixels_per_point:.2}",
|
||||
"italics/image_{theme}_x{pixels_per_point:.2}",
|
||||
theme = match theme {
|
||||
egui::Theme::Dark => "dark",
|
||||
egui::Theme::Light => "light",
|
||||
@@ -51,3 +52,24 @@ fn test_italics() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_text_selection() {
|
||||
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::DARK_BLUE;
|
||||
|
||||
ui.label("Some varied ☺ text :)\nAnd it has a second line!");
|
||||
});
|
||||
harness.run();
|
||||
harness.fit_contents();
|
||||
|
||||
// Drag to select text:
|
||||
let label = harness.get_by_role(Role::Label);
|
||||
harness.drag_at(label.rect().lerp_inside([0.2, 0.25]));
|
||||
harness.drop_at(label.rect().lerp_inside([0.6, 0.75]));
|
||||
harness.run();
|
||||
|
||||
harness.snapshot("text_selection");
|
||||
}
|
||||
|
||||
3
crates/egui_demo_lib/tests/snapshots/text_selection.png
Normal file
3
crates/egui_demo_lib/tests/snapshots/text_selection.png
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:14f253fedc94985ff1431f1016d901d747e1f9948531cc6350f6615649f29056
|
||||
size 4862
|
||||
Reference in New Issue
Block a user