1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Allow masking widgets in kittest snapshots (#7467)

* Closes <https://github.com/emilk/egui/issues/THE_RELEVANT_ISSUE>
* [ ] I have followed the instructions in the PR template
This commit is contained in:
Lucas Meurer
2025-08-21 17:46:36 +02:00
committed by GitHub
parent bf981b8d3e
commit 42c2fc58c9
3 changed files with 38 additions and 1 deletions

View File

@@ -28,8 +28,9 @@ pub use builder::*;
pub use node::*;
pub use renderer::*;
use egui::epaint::{ClippedShape, RectShape};
use egui::style::ScrollAnimation;
use egui::{Key, Modifiers, Pos2, Rect, RepaintCause, Vec2, ViewportId};
use egui::{Color32, Key, Modifiers, Pos2, Rect, RepaintCause, Shape, Vec2, ViewportId};
use kittest::Queryable;
#[derive(Debug, Clone)]
@@ -556,6 +557,18 @@ impl<'a, State> Harness<'a, State> {
self.key_combination_modifiers(modifiers, &[key]);
}
/// Mask something. Useful for snapshot tests.
///
/// Call this _after_ [`Self::run`] and before [`Self::snapshot`].
/// This will add a [`RectShape`] to the output shapes, for the current frame.
/// Will be overwritten on the next call to [`Self::run`].
pub fn mask(&mut self, rect: Rect) {
self.output.shapes.push(ClippedShape {
clip_rect: Rect::EVERYTHING,
shape: Shape::Rect(RectShape::filled(rect, 0.0, Color32::MAGENTA)),
});
}
/// Render the last output to an image.
///
/// # Errors