egui/crates
Nicolas 77df407f50
`egui_kittest`: add `failed_pixel_count_threshold` (#7092)
I thought about this - so we have two options here:
1. adding it to `SnapshotOptions` 
2. adding it to every function which I do not like as this would be a
huge breaking change

## Summary

This pull request introduces a new feature to the `SnapshotOptions`
struct in the `egui_kittest` crate, allowing users to specify a
permissible percentage of pixel differences (`diff_percentage`) before a
snapshot comparison is considered a failure. This feature provides more
flexibility in handling minor visual discrepancies during snapshot
testing.

### Additions to `SnapshotOptions`:

* Added a new field `diff_percentage` of type `Option<f64>` to the
`SnapshotOptions` struct. This field allows users to define a tolerance
for pixel differences, with a default value of `None` (interpreted as 0%
tolerance).
* Updated the `Default` implementation of `SnapshotOptions` to
initialize `diff_percentage` to `None`.

### Integration into snapshot comparison logic:

* Updated the `try_image_snapshot_options` function to handle the new
`diff_percentage` field. If a `diff_percentage` is specified, the
function calculates the percentage of differing pixels and allows the
snapshot to pass if the difference is within the specified tolerance.
[[1]](diffhunk://#diff-6f481b5866b82a4fe126b7df2e6c9669040c79d1d200d76b87f376de5dec5065R204)
[[2]](diffhunk://#diff-6f481b5866b82a4fe126b7df2e6c9669040c79d1d200d76b87f376de5dec5065R294-R301)

* Closes <https://github.com/emilk/egui/issues/5683>
* [x] I have followed the instructions in the PR template

---------

Co-authored-by: lucasmerlin <hi@lucasmerlin.me>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-07-03 14:23:15 +02:00
..
ecolor Use Rust edition 2024 (#7280) 2025-06-30 14:01:57 +02:00
eframe Respect and detect `prefers-color-scheme: no-preference` (#7293) 2025-07-03 08:58:45 +02:00
egui Fix crash when using infinite widgets (#7296) 2025-07-03 13:40:02 +02:00
egui-wgpu Improve text rendering in light mode (#7290) 2025-07-02 14:58:37 +02:00
egui-winit Use Rust edition 2024 (#7280) 2025-06-30 14:01:57 +02:00
egui_demo_app Add `Visuals::weak_text_alpha` and `weak_text_color` (#7285) 2025-07-01 20:42:54 +02:00
egui_demo_lib `egui_kittest`: add `failed_pixel_count_threshold` (#7092) 2025-07-03 14:23:15 +02:00
egui_extras Extend .typos.toml to enforce american english (#7284) 2025-07-01 15:54:00 +02:00
egui_glow Improve text rendering in light mode (#7290) 2025-07-02 14:58:37 +02:00
egui_kittest `egui_kittest`: add `failed_pixel_count_threshold` (#7092) 2025-07-03 14:23:15 +02:00
egui_plot Move `egui_plot` to its own repo (#4828) 2024-07-15 18:45:19 +02:00
egui_web Rename `master` branch to `main` (#7034) 2025-05-08 09:15:42 +02:00
emath Use Rust edition 2024 (#7280) 2025-06-30 14:01:57 +02:00
epaint Improve text rendering in light mode (#7290) 2025-07-02 14:58:37 +02:00
epaint_default_fonts Update `emoji-icon-font` with fix for fullwidth latin characters (#7067) 2025-05-21 13:22:23 +02:00